jaulib
v1.3.0
Jau Support Library (C++, Java, ..)
java_jni
org
jau
io
MemUtil.java
Go to the documentation of this file.
1
package
org.jau.io;
2
3
import
java.nio.ByteBuffer;
4
5
public
class
MemUtil
{
6
/**
7
* Zeros all bytes of given direct NIO byte buffer.
8
*/
9
public
static
native
void
zeroByteBuffer
(
final
ByteBuffer buf);
10
11
/**
12
* Zeros all underlying bytes of given Java string.
13
*
14
* Implementation either uses the JNI GetStringCritical() with is_copy == false or the String backing array `value`.
15
*
16
* @return true if successful, i.e. the underlying bytes could have been zeroed, otherwise returns false w/o zero'ed content.
17
public static native boolean zeroString(final String str);
18
*/
19
20
/**
21
* Converts the Java string to a native direct ByteBuffer as UTF-8
22
* allowing better control over its memory region to {@link #zeroByteBuffer(ByteBuffer) zero} it after usage.
23
*
24
* @param str the string to convert
25
* @param zerostr pass true to zero the bytes of the given Java string afterwards (recommended!)
26
* @return direct ByteBuffer instance suitable for Cipherpack.
27
public static ByteBuffer to_ByteBuffer(final String str, final boolean zerostr) {
28
final ByteBuffer res = toByteBufferImpl(str);
29
res.limit(res.capacity());
30
res.position(0);
31
if( zerostr ) {
32
zeroString(str);
33
}
34
return res;
35
}
36
private static native ByteBuffer toByteBufferImpl(final String str);
37
38
public static String to_String(final ByteBuffer bb, final Charset cs) {
39
final int p0 = bb.position();
40
bb.position(0);
41
final byte[] bb_bytes = new byte[bb.limit()];
42
bb.get(bb_bytes);
43
bb.position(p0);
44
return new String(bb_bytes, cs);
45
}
46
*/
47
48
}
org.jau.io.MemUtil
Definition:
MemUtil.java:5
org.jau.io.MemUtil.zeroByteBuffer
static native void zeroByteBuffer(final ByteBuffer buf)
Zeros all bytes of given direct NIO byte buffer.
Generated on Sun May 12 2024 09:05:50 for jaulib by
1.9.4