Top Description Inners Fields Constructors Methods
org.graalvm.nativebridge

public abstract Class BinaryOutput

extends Object
Class Inheritance
Known Direct Subclasses
org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput, org.graalvm.nativebridge.BinaryOutput.CCharPointerBinaryOutput
Imports
org.graalvm.nativebridge.JNIConfig.Builder, org.graalvm.nativeimage.UnmanagedMemory, org.graalvm.nativeimage.c.type.CCharPointer, .CTypeConversion, org.graalvm.word.WordFactory, java.io.Closeable, java.nio.ByteBuffer, java.util.Arrays, .Objects

A buffer used by the BinaryMarshaller to marshall parameters and results passed by value.
See Also
BinaryInput, BinaryMarshaller, Builder#registerMarshaller(Class, BinaryMarshaller)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
BinaryOutput.CCharPointerBinaryOutput

A BinaryOutput backed by an off-heap memory.

Field Summary

Modifier and TypeField and Description
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final int
LARGE_STRING_TAG

Tag to distinguish between long and short string.

pack-priv static final byte
private static final int
MAX_LENGTH

Maximum string length for string encoded by 4 bytes length followed be content.

private static final int
MAX_SHORT_LENGTH

Maximum string length for string encoded by 2 bytes length followed be content.

pack-priv static final byte
protected int
pack-priv static final byte
pack-priv static final byte
private byte[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static int
bufferSize(int headerSize, int dataSize)

public static BinaryOutput.ByteArrayBinaryOutput
create()

Creates a new buffer backed by a byte array.

public static BinaryOutput.ByteArrayBinaryOutput
create(byte[] initialBuffer)

Creates a new buffer wrapping the initialBuffer.

public static BinaryOutput.CCharPointerBinaryOutput
create(CCharPointer
the off-heap memory address
address
,
int
the off-heap memory size
length
,
boolean
true if the memory was dynamically allocated and should be freed when the buffer is closed; false for the stack allocated memory.
dynamicallyAllocated
)

Creates a new buffer wrapping an off-heap memory segment starting at address having length bytes.

private void
ensureBufferSize(int headerSize, int dataSize)

public int
getPosition()

Returns this buffer's position.

public static boolean
isTypedValue(Object value)

Returns true if a value is a typed value writable using writeTypedValue(Object), else false.

public abstract void
skip(int
number of bytes to reserve.
numberOfBytes
)

Reserves a buffer space.

public abstract void
write(int b)

Writes the lowest byte of the argument as a single byte value.

public abstract void
write(byte[] array, int off, int len)

Writes len bytes from the byte array starting at offset off.

public final void
write(boolean[] array, int off, int len)

Writes len bytes from the boolean array starting at offset off.

public final void
write(short[] array, int off, int len)

Writes len shorts from the array starting at offset off.

public final void
write(char[] array, int off, int len)

Writes len chars from the array starting at offset off.

public final void
write(int[] array, int off, int len)

Writes len ints from the array starting at offset off.

public final void
write(long[] array, int off, int len)

Writes len longs from the array starting at offset off.

public final void
write(float[] array, int off, int len)

Writes len floats from the array starting at offset off.

public final void
write(double[] array, int off, int len)

Writes len doubles from the array starting at offset off.

public final void
writeBoolean(boolean value)

Writes a boolean as a single byte value.

public final void
writeByte(int value)

Writes a byte as a single byte value.

public final void
writeChar(int value)

Writes a char as two bytes, high byte first.

public final void
writeDouble(double value)

Converts a double value to a long using the Double#doubleToLongBits(double), and then writes that long as eight bytes, high byte first.

public final void
writeFloat(float value)

Converts a float value to an int using the Float#floatToIntBits(float), and then writes that int as four bytes, high byte first.

public final void
writeInt(int value)

Writes an int as four bytes, high byte first.

public final void
writeLong(long value)

Writes a long as eight bytes, high byte first.

public final void
writeShort(int value)

Writes a short as two bytes, high byte first.

public final void
writeTypedValue(Object value)

Writes the value that is represented by the given object, together with information on the value's data type.

public final void
writeUTF(String string)

Writes a string using a modified UTF-8 encoding in a machine-independent manner.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAYback to summary
pack-priv static final byte ARRAY
BOOLEANback to summary
pack-priv static final byte BOOLEAN
BYTEback to summary
pack-priv static final byte BYTE
CHARback to summary
pack-priv static final byte CHAR
DOUBLEback to summary
pack-priv static final byte DOUBLE
FLOATback to summary
pack-priv static final byte FLOAT
INTback to summary
pack-priv static final byte INT
LARGE_STRING_TAGback to summary
pack-priv static final int LARGE_STRING_TAG

Tag to distinguish between long and short string. The tag is set in the first string length byte.

LONGback to summary
pack-priv static final byte LONG
MAX_LENGTHback to summary
private static final int MAX_LENGTH

Maximum string length for string encoded by 4 bytes length followed be content.

MAX_SHORT_LENGTHback to summary
private static final int MAX_SHORT_LENGTH

Maximum string length for string encoded by 2 bytes length followed be content.

NULLback to summary
pack-priv static final byte NULL
posback to summary
protected int pos
SHORTback to summary
pack-priv static final byte SHORT
STRINGback to summary
pack-priv static final byte STRING
tempDecodingBufferback to summary
private byte[] tempDecodingBuffer

Constructor Detail

BinaryOutputback to summary
private BinaryOutput()

Method Detail

bufferSizeback to summary
pack-priv static int bufferSize(int headerSize, int dataSize)
createback to summary
public static BinaryOutput.ByteArrayBinaryOutput create()

Creates a new buffer backed by a byte array.

createback to summary
public static BinaryOutput.ByteArrayBinaryOutput create(byte[] initialBuffer)

Creates a new buffer wrapping the initialBuffer. If the initialBuffer capacity is not sufficient for writing the data, a new array is allocated. Always use ByteArrayBinaryOutput#getArray() to obtain the marshaled data.

createback to summary
public static BinaryOutput.CCharPointerBinaryOutput create(CCharPointer address, int length, boolean dynamicallyAllocated)

Creates a new buffer wrapping an off-heap memory segment starting at address having length bytes. If the capacity of an off-heap memory segment is not sufficient for writing the data, a new off-heap memory is allocated. Always use CCharPointerBinaryOutput#getAddress() to obtain the marshaled data.

Parameters
address:CCharPointer

the off-heap memory address

length:int

the off-heap memory size

dynamicallyAllocated:boolean

true if the memory was dynamically allocated and should be freed when the buffer is closed; false for the stack allocated memory.

ensureBufferSizeback to summary
private void ensureBufferSize(int headerSize, int dataSize)
getPositionback to summary
public int getPosition()

Returns this buffer's position.

isTypedValueback to summary
public static boolean isTypedValue(Object value)

Returns true if a value is a typed value writable using writeTypedValue(Object), else false.

skipback to summary
public abstract void skip(int numberOfBytes)

Reserves a buffer space. The reserved space can be used for out parameters.

Parameters
numberOfBytes:int

number of bytes to reserve.

writeback to summary
public abstract void write(int b)

Writes the lowest byte of the argument as a single byte value. The buffer position is incremented by 1.

writeback to summary
public abstract void write(byte[] array, int off, int len)

Writes len bytes from the byte array starting at offset off. The buffer position is incremented by len.

writeback to summary
public final void write(boolean[] array, int off, int len)

Writes len bytes from the boolean array starting at offset off. The value true is written as the value (byte)1, the value false is written as the value (byte)0. The buffer position is incremented by len.

writeback to summary
public final void write(short[] array, int off, int len)

Writes len shorts from the array starting at offset off. The buffer position is incremented by 2 * len.

writeback to summary
public final void write(char[] array, int off, int len)

Writes len chars from the array starting at offset off. The buffer position is incremented by 2 * len.

writeback to summary
public final void write(int[] array, int off, int len)

Writes len ints from the array starting at offset off. The buffer position is incremented by 4 * len.

writeback to summary
public final void write(long[] array, int off, int len)

Writes len longs from the array starting at offset off. The buffer position is incremented by 8 * len.

writeback to summary
public final void write(float[] array, int off, int len)

Writes len floats from the array starting at offset off. Each float value is converted to an int using the Float#floatToIntBits(float) and written as an int. The buffer position is incremented by 4 * len.

writeback to summary
public final void write(double[] array, int off, int len)

Writes len doubles from the array starting at offset off. Each double value is converted to an lang using the Double#doubleToLongBits(double) and written as a long. The buffer position is incremented by 8 * len.

writeBooleanback to summary
public final void writeBoolean(boolean value)

Writes a boolean as a single byte value. The value true is written as the value (byte)1, the value false is written as the value (byte)0. The buffer position is incremented by 1.

writeByteback to summary
public final void writeByte(int value)

Writes a byte as a single byte value. The buffer position is incremented by 1.

writeCharback to summary
public final void writeChar(int value)

Writes a char as two bytes, high byte first. The buffer position is incremented by 2.

writeDoubleback to summary
public final void writeDouble(double value)

Converts a double value to a long using the Double#doubleToLongBits(double), and then writes that long as eight bytes, high byte first. The buffer position is incremented by 8.

writeFloatback to summary
public final void writeFloat(float value)

Converts a float value to an int using the Float#floatToIntBits(float), and then writes that int as four bytes, high byte first. The buffer position is incremented by 4.

writeIntback to summary
public final void writeInt(int value)

Writes an int as four bytes, high byte first. The buffer position is incremented by 4.

writeLongback to summary
public final void writeLong(long value)

Writes a long as eight bytes, high byte first. The buffer position is incremented by 8.

writeShortback to summary
public final void writeShort(int value)

Writes a short as two bytes, high byte first. The buffer position is incremented by 2.

writeTypedValueback to summary
public final void writeTypedValue(Object value) throws IllegalArgumentException

Writes the value that is represented by the given object, together with information on the value's data type. Supported types are boxed Java primitive types, String, null, and arrays of these types.

Exceptions
IllegalArgumentException:
when the value type is not supported or the value is a string which cannot be encoded using modified UTF-8 encoding.
See Also
to find out whether a value can be serialized.
writeUTFback to summary
public final void writeUTF(String string) throws IllegalArgumentException

Writes a string using a modified UTF-8 encoding in a machine-independent manner.

Exceptions
IllegalArgumentException:
if the string cannot be encoded using modified UTF-8 encoding.
org.graalvm.nativebridge back to summary

public final Class BinaryOutput.ByteArrayBinaryOutput

extends BinaryOutput
Class Inheritance

A BinaryOutput backed by a byte array.

Field Summary

Modifier and TypeField and Description
private byte[]
pack-priv static final int
private static final int
Inherited from org.graalvm.nativebridge.BinaryOutput:
ARRAYBOOLEANBYTECHARDOUBLEFLOATINTLARGE_STRING_TAGLONGNULLposSHORTSTRING

Constructor Summary

AccessConstructor and Description
private
private
ByteArrayBinaryOutput(byte[] initialBuffer)

Method Summary

Modifier and TypeMethod and Description
public static BinaryOutput.ByteArrayBinaryOutput
create(int initialSize)

Creates a new buffer backed by a byte array.

private void
ensureCapacity(int neededCapacity)

public byte[]
getArray()

Returns the byte array containing the marshalled data.

public void
skip(int
number of bytes to reserve.
numberOfBytes
)

Implements abstract org.graalvm.nativebridge.BinaryOutput.skip.

Reserves a buffer space.

public void
write(int b)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Writes the lowest byte of the argument as a single byte value.

public void
write(byte[] b, int off, int len)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Writes len bytes from the byte array starting at offset off.

Inherited from org.graalvm.nativebridge.BinaryOutput:
bufferSizecreatecreatecreategetPositionisTypedValuewritewritewritewritewritewritewritewriteBooleanwriteBytewriteCharwriteDoublewriteFloatwriteIntwriteLongwriteShortwriteTypedValuewriteUTF

Field Detail

bufferback to summary
private byte[] buffer
INITIAL_SIZEback to summary
pack-priv static final int INITIAL_SIZE
MAX_ARRAY_SIZEback to summary
private static final int MAX_ARRAY_SIZE

Constructor Detail

ByteArrayBinaryOutputback to summary
private ByteArrayBinaryOutput(int size)
ByteArrayBinaryOutputback to summary
private ByteArrayBinaryOutput(byte[] initialBuffer)

Method Detail

createback to summary
public static BinaryOutput.ByteArrayBinaryOutput create(int initialSize)

Creates a new buffer backed by a byte array. The buffer initial size is initialSize.

ensureCapacityback to summary
private void ensureCapacity(int neededCapacity)
getArrayback to summary
public byte[] getArray()

Returns the byte array containing the marshalled data.

skipback to summary
public void skip(int numberOfBytes)

Implements abstract org.graalvm.nativebridge.BinaryOutput.skip.

Doc from org.graalvm.nativebridge.BinaryOutput.skip.

Reserves a buffer space. The reserved space can be used for out parameters.

Parameters
numberOfBytes:int

number of bytes to reserve.

Annotations
@Override
writeback to summary
public void write(int b)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Doc from org.graalvm.nativebridge.BinaryOutput.write.

Writes the lowest byte of the argument as a single byte value. The buffer position is incremented by 1.

Annotations
@Override
writeback to summary
public void write(byte[] b, int off, int len)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Doc from org.graalvm.nativebridge.BinaryOutput.write.

Writes len bytes from the byte array starting at offset off. The buffer position is incremented by len.

Annotations
@Override
org.graalvm.nativebridge back to summary

public final Class BinaryOutput.CCharPointerBinaryOutput

extends BinaryOutput
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable

A BinaryOutput backed by an off-heap memory.

Field Summary

Modifier and TypeField and Description
private CCharPointer
private static final int
BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD

Represents the point at which the average cost of a JNI call exceeds the expense of an element by element copy.

private ByteBuffer
byteBufferView

ByteBuffer view of this CCharPointerBinaryOutput direct memory.

private int
private boolean
Inherited from org.graalvm.nativebridge.BinaryOutput:
ARRAYBOOLEANBYTECHARDOUBLEFLOATINTLARGE_STRING_TAGLONGNULLposSHORTSTRING

Constructor Summary

AccessConstructor and Description
private
CCharPointerBinaryOutput(CCharPointer address, int length, boolean unmanaged)

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements java.io.Closeable.close.

Closes the buffer and frees off-heap allocated resources.

public static BinaryOutput.CCharPointerBinaryOutput
create(int initialSize)

Creates a new buffer backed by an off-heap memory segment.

private void
ensureCapacity(int neededCapacity)

public CCharPointer
getAddress()

Returns an address of an off-heap memory segment containing the marshalled data.

public int
getPosition()

Overrides org.graalvm.nativebridge.BinaryOutput.getPosition.

Returns this buffer's position.

private static void
memcpy(CCharPointer dst, CCharPointer src, int len)

public void
skip(int
number of bytes to reserve.
numberOfBytes
)

Implements abstract org.graalvm.nativebridge.BinaryOutput.skip.

Reserves a buffer space.

public void
write(int b)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Writes the lowest byte of the argument as a single byte value.

public void
write(byte[] b, int off, int len)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Writes len bytes from the byte array starting at offset off.

Inherited from org.graalvm.nativebridge.BinaryOutput:
bufferSizecreatecreatecreateisTypedValuewritewritewritewritewritewritewritewriteBooleanwriteBytewriteCharwriteDoublewriteFloatwriteIntwriteLongwriteShortwriteTypedValuewriteUTF

Field Detail

addressback to summary
private CCharPointer address
BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLDback to summary
private static final int BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD

Represents the point at which the average cost of a JNI call exceeds the expense of an element by element copy. See java.nio.Bits#JNI_COPY_FROM_ARRAY_THRESHOLD.

byteBufferViewback to summary
private ByteBuffer byteBufferView

ByteBuffer view of this CCharPointerBinaryOutput direct memory. The ByteBuffer is used for bulk data transfers, where the bulk ByteBuffer operations outperform element by element copying by an order of magnitude.

lengthback to summary
private int length
unmanagedback to summary
private boolean unmanaged

Constructor Detail

CCharPointerBinaryOutputback to summary
private CCharPointerBinaryOutput(CCharPointer address, int length, boolean unmanaged)

Method Detail

checkClosedback to summary
private void checkClosed()
closeback to summary
public void close()

Implements java.io.Closeable.close.

Closes the buffer and frees off-heap allocated resources.

Annotations
@Override
createback to summary
public static BinaryOutput.CCharPointerBinaryOutput create(int initialSize)

Creates a new buffer backed by an off-heap memory segment. The buffer initial size is initialSize.

ensureCapacityback to summary
private void ensureCapacity(int neededCapacity)
getAddressback to summary
public CCharPointer getAddress()

Returns an address of an off-heap memory segment containing the marshalled data.

getPositionback to summary
public int getPosition()

Overrides org.graalvm.nativebridge.BinaryOutput.getPosition.

Doc from org.graalvm.nativebridge.BinaryOutput.getPosition.

Returns this buffer's position.

Annotations
@Override
memcpyback to summary
private static void memcpy(CCharPointer dst, CCharPointer src, int len)
skipback to summary
public void skip(int numberOfBytes)

Implements abstract org.graalvm.nativebridge.BinaryOutput.skip.

Doc from org.graalvm.nativebridge.BinaryOutput.skip.

Reserves a buffer space. The reserved space can be used for out parameters.

Parameters
numberOfBytes:int

number of bytes to reserve.

Annotations
@Override
writeback to summary
public void write(int b)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Doc from org.graalvm.nativebridge.BinaryOutput.write.

Writes the lowest byte of the argument as a single byte value. The buffer position is incremented by 1.

Annotations
@Override
writeback to summary
public void write(byte[] b, int off, int len)

Implements abstract org.graalvm.nativebridge.BinaryOutput.write.

Doc from org.graalvm.nativebridge.BinaryOutput.write.

Writes len bytes from the byte array starting at offset off. The buffer position is incremented by len.

Annotations
@Override