Top Description Inners Fields Constructors Methods
org.lwjgl

public final Class MemoryUtil

extends Object
Class Inheritance
Imports
java.lang.reflect.Field, java.nio.*, java.nio.charset.*

[INTERNAL USE ONLY]

This class provides utility methods for passing buffers to JNI API calls.

Author
Spasi

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
private static class
MemoryUtil.AccessorJNI

Default implementation.

private static class
MemoryUtil.AccessorReflect

Implementation using reflection on ByteBuffer.

private static class
MemoryUtil.CharSequenceNT

A null-terminated CharSequence.

Field Summary

Modifier and TypeField and Description
private static final Charset
private static final MemoryUtil.Accessor
private static final Charset
private static final Charset

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
decode(final ByteBuffer buffer, final Charset charset)

public static String
decodeASCII(final ByteBuffer buffer)

private static String
decodeImpl(final ByteBuffer in, final Charset charset)

public static String
decodeUTF16(final ByteBuffer buffer)

public static String
decodeUTF8(final ByteBuffer buffer)

private static ByteBuffer

Returns:

the encoded text
encode
(final CharSequence
the text to encode
text
,
final Charset
the charset to use for encoding
charset
)

Wraps the specified text in a null-terminated CharBuffer and encodes it using the specified Charset.

private static ByteBuffer
public static ByteBuffer

Returns:

the encoded text or null
encodeASCII
(final CharSequence
the text to encode
text
)

Returns a ByteBuffer containing the specified text ASCII encoded and null-terminated.

public static ByteBuffer

Returns:

the encoded text
encodeUTF16
(final CharSequence
the text to encode
text
)

Returns a ByteBuffer containing the specified text UTF-16LE encoded and null-terminated.

public static ByteBuffer

Returns:

the encoded text or null
encodeUTF8
(final CharSequence
the text to encode
text
)

Returns a ByteBuffer containing the specified text UTF-8 encoded and null-terminated.

public static long
public static long
getAddress(ByteBuffer buffer, int position)

public static long
public static long
getAddress(ShortBuffer buffer, int position)

public static long
public static long
getAddress(CharBuffer buffer, int position)

public static long
public static long
getAddress(IntBuffer buffer, int position)

public static long
public static long
getAddress(FloatBuffer buffer, int position)

public static long
public static long
getAddress(LongBuffer buffer, int position)

public static long
public static long
getAddress(DoubleBuffer buffer, int position)

public static long
public static long
getAddress(PointerBuffer buffer, int position)

public static long

Returns:

the memory address
getAddress0
(Buffer
the buffer
buffer
)

Returns the memory address of the specified buffer.

public static long
public static long
public static long
pack-priv static Field
public static long
public static long
getAddressSafe(ByteBuffer buffer, int position)

public static long
public static long
getAddressSafe(ShortBuffer buffer, int position)

public static long
public static long
getAddressSafe(CharBuffer buffer, int position)

public static long
public static long
getAddressSafe(IntBuffer buffer, int position)

public static long
public static long
getAddressSafe(FloatBuffer buffer, int position)

public static long
public static long
getAddressSafe(LongBuffer buffer, int position)

public static long
public static long
getAddressSafe(DoubleBuffer buffer, int position)

public static long
public static long
getAddressSafe(PointerBuffer buffer, int position)

private static Field
getDeclaredFieldRecursive(final Class<?> root, final String fieldName)

private static MemoryUtil.Accessor
loadAccessor(final String className)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

asciiback to summary
private static final Charset ascii
memUtilback to summary
private static final MemoryUtil.Accessor memUtil
utf16back to summary
private static final Charset utf16
utf8back to summary
private static final Charset utf8

Constructor Detail

MemoryUtilback to summary
private MemoryUtil()

Method Detail

decodeback to summary
private static String decode(final ByteBuffer buffer, final Charset charset)
decodeASCIIback to summary
public static String decodeASCII(final ByteBuffer buffer)
decodeImplback to summary
private static String decodeImpl(final ByteBuffer in, final Charset charset)
decodeUTF16back to summary
public static String decodeUTF16(final ByteBuffer buffer)
decodeUTF8back to summary
public static String decodeUTF8(final ByteBuffer buffer)
encodeback to summary
private static ByteBuffer encode(final CharSequence text, final Charset charset)

Wraps the specified text in a null-terminated CharBuffer and encodes it using the specified Charset.

Parameters
text:CharSequence

the text to encode

charset:Charset

the charset to use for encoding

Returns:ByteBuffer

the encoded text

encodeback to summary
private static ByteBuffer encode(final CharBuffer in, final Charset charset)

A CharsetEncoder#encode(java.nio.CharBuffer) implementation that uses BufferUtils#createByteBuffer(int) instead of ByteBuffer#allocate(int).

See Also
CharsetEncoder#encode(java.nio.CharBuffer)
encodeASCIIback to summary
public static ByteBuffer encodeASCII(final CharSequence text)

Returns a ByteBuffer containing the specified text ASCII encoded and null-terminated. If text is null, null is returned.

Parameters
text:CharSequence

the text to encode

Returns:ByteBuffer

the encoded text or null

See Also
String#getBytes()
encodeUTF16back to summary
public static ByteBuffer encodeUTF16(final CharSequence text)

Returns a ByteBuffer containing the specified text UTF-16LE encoded and null-terminated. If text is null, null is returned.

Parameters
text:CharSequence

the text to encode

Returns:ByteBuffer

the encoded text

encodeUTF8back to summary
public static ByteBuffer encodeUTF8(final CharSequence text)

Returns a ByteBuffer containing the specified text UTF-8 encoded and null-terminated. If text is null, null is returned.

Parameters
text:CharSequence

the text to encode

Returns:ByteBuffer

the encoded text or null

See Also
String#getBytes()
getAddressback to summary
public static long getAddress(ByteBuffer buffer)
getAddressback to summary
public static long getAddress(ByteBuffer buffer, int position)
getAddressback to summary
public static long getAddress(ShortBuffer buffer)
getAddressback to summary
public static long getAddress(ShortBuffer buffer, int position)
getAddressback to summary
public static long getAddress(CharBuffer buffer)
getAddressback to summary
public static long getAddress(CharBuffer buffer, int position)
getAddressback to summary
public static long getAddress(IntBuffer buffer)
getAddressback to summary
public static long getAddress(IntBuffer buffer, int position)
getAddressback to summary
public static long getAddress(FloatBuffer buffer)
getAddressback to summary
public static long getAddress(FloatBuffer buffer, int position)
getAddressback to summary
public static long getAddress(LongBuffer buffer)
getAddressback to summary
public static long getAddress(LongBuffer buffer, int position)
getAddressback to summary
public static long getAddress(DoubleBuffer buffer)
getAddressback to summary
public static long getAddress(DoubleBuffer buffer, int position)
getAddressback to summary
public static long getAddress(PointerBuffer buffer)
getAddressback to summary
public static long getAddress(PointerBuffer buffer, int position)
getAddress0back to summary
public static long getAddress0(Buffer buffer)

Returns the memory address of the specified buffer. [INTERNAL USE ONLY]

Parameters
buffer:Buffer

the buffer

Returns:long

the memory address

getAddress0back to summary
public static long getAddress0(PointerBuffer buffer)
getAddress0Safeback to summary
public static long getAddress0Safe(Buffer buffer)
getAddress0Safeback to summary
public static long getAddress0Safe(PointerBuffer buffer)
getAddressFieldback to summary
pack-priv static Field getAddressField() throws NoSuchFieldException
getAddressSafeback to summary
public static long getAddressSafe(ByteBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(ByteBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(ShortBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(ShortBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(CharBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(CharBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(IntBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(IntBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(FloatBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(FloatBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(LongBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(LongBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(DoubleBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(DoubleBuffer buffer, int position)
getAddressSafeback to summary
public static long getAddressSafe(PointerBuffer buffer)
getAddressSafeback to summary
public static long getAddressSafe(PointerBuffer buffer, int position)
getDeclaredFieldRecursiveback to summary
private static Field getDeclaredFieldRecursive(final Class<?> root, final String fieldName) throws NoSuchFieldException
loadAccessorback to summary
private static MemoryUtil.Accessor loadAccessor(final String className) throws Exception
org.lwjgl back to summary

pack-priv Interface MemoryUtil.Accessor

Known Direct Implementers
org.lwjgl.MemoryUtil.AccessorJNI, org.lwjgl.MemoryUtil.AccessorReflect, org.lwjgl.MemoryUtilSun.AccessorUnsafe, org.lwjgl.MemoryUtilSun.AccessorReflectFast

Method Summary

Modifier and TypeMethod and Description
public long

Method Detail

getAddressback to summary
public long getAddress(Buffer buffer)
org.lwjgl back to summary

private Class MemoryUtil.AccessorJNI

extends Object
implements Accessor
Class Inheritance
All Implemented Interfaces
org.lwjgl.MemoryUtil.Accessor

Default implementation.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AccessorJNIback to summary
private AccessorJNI()

Method Detail

getAddressback to summary
public long getAddress(final Buffer buffer)

Implements org.lwjgl.MemoryUtil.Accessor.getAddress.

org.lwjgl back to summary

private Class MemoryUtil.AccessorReflect

extends Object
implements Accessor
Class Inheritance
All Implemented Interfaces
org.lwjgl.MemoryUtil.Accessor

Implementation using reflection on ByteBuffer.

Field Summary

Modifier and TypeField and Description
private final Field

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressback to summary
private final Field address

Constructor Detail

AccessorReflectback to summary
pack-priv AccessorReflect()

Method Detail

getAddressback to summary
public long getAddress(final Buffer buffer)

Implements org.lwjgl.MemoryUtil.Accessor.getAddress.

org.lwjgl back to summary

private Class MemoryUtil.CharSequenceNT

extends Object
implements CharSequence
Class Inheritance
All Implemented Interfaces
java.lang.CharSequence

A null-terminated CharSequence.

Field Summary

Modifier and TypeField and Description
pack-priv final CharSequence

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public char
charAt(final int
the index of the char value to be returned
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value at the specified index.
public int
length()

Implements java.lang.CharSequence.length.

Returns the length of this character sequence.
public CharSequence
subSequence(final int
the start index, inclusive
start
,
final int
the end index, exclusive
end
)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sourceback to summary
pack-priv final CharSequence source

Constructor Detail

CharSequenceNTback to summary
pack-priv CharSequenceNT(CharSequence source)

Method Detail

charAtback to summary
public char charAt(final int index)

Implements java.lang.CharSequence.charAt.

Doc from java.lang.CharSequence.charAt.

Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Parameters
index:int

the index of the char value to be returned

Returns:char

the specified char value

lengthback to summary
public int length()

Implements java.lang.CharSequence.length.

Doc from java.lang.CharSequence.length.

Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Returns:int

the number of chars in this sequence

subSequenceback to summary
public CharSequence subSequence(final int start, final int end)

Implements java.lang.CharSequence.subSequence.

Doc from java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
start:int

the start index, inclusive

end:int

the end index, exclusive

Returns:CharSequence

the specified subsequence