Table of Contents

Class ByteBuffer

Namespace
Java.Nio
Assembly
MASES.JNet.dll
public class ByteBuffer : Buffer, IDynamicMetaObjectProvider, IJVMBridgeCore, IJVMBridgeBaseStatic, IJVMBridgeBase, IJVMBridgeDefinition, IDisposable
Inheritance
JVMBridgeBase
JVMBridgeBase<Buffer>
ByteBuffer
Implements
IJVMBridgeCore
IJVMBridgeBaseStatic
IJVMBridgeBase
IJVMBridgeDefinition
Derived
Inherited Members
JVMBridgeBase<Buffer>.IsAssignableFrom(IJavaType)
JVMBridgeBase<Buffer>.IsAssignableFrom<T>()
JVMBridgeBase<Buffer>.Execute<T>(params T[])
JVMBridgeBase<Buffer>.DynBridgeClazz
JVMBridgeBase<Buffer>.BridgeClazz
JVMBridgeBase.RuntimeClassNameOf<T>()
JVMBridgeBase.ClassNameOf<T>()
JVMBridgeBase.ClassOf<T>()
JVMBridgeBase.WrapsDirect<TNewClass>(IJavaObject)
JVMBridgeBase.Wraps<TNewClass>(IJavaObject)
JVMBridgeBase.Wraps<TNewClass, TReturn>(IJavaObject)
JVMBridgeBase.Wraps<TNewClass, TReturn, TConverter>(IJavaObject)
JVMBridgeBase.MonitorEnter()
JVMBridgeBase.MonitorExit()
JVMBridgeBase.IsInstanceOf(IJavaType)
JVMBridgeBase.IsInstanceOf<T>()
JVMBridgeBase.RuntimeIsInstanceOf<T>()
JVMBridgeBase.CastTo<TNewClass>()
JVMBridgeBase.CastDirect<TNewClass>()
JVMBridgeBase.ToString()
JVMBridgeBase.GetHashCode()
JVMBridgeBase.Notify()
JVMBridgeBase.NotifyAll()
JVMBridgeBase.Wait()
JVMBridgeBase.DynBridgeInstance
JVMBridgeBase.BridgeInstance
JVMBridgeBase.IsBridgeListener
Extension Methods

Constructors

ByteBuffer()

Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge

[Obsolete("ByteBuffer class represents, in .NET, an instance of a JVM interface or abstract class. This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")]
public ByteBuffer()

ByteBuffer(params object[])

Generic constructor: it is useful for JCOBridge when there is a derived class which needs to pass arguments to the highest JVMBridgeBase class

[Obsolete("ByteBuffer class represents, in .NET, an instance of a JVM interface or abstract class. This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")]
public ByteBuffer(params object[] args)

Parameters

args object[]

Properties

BridgeClassName

public override string BridgeClassName { get; }

Property Value

string

Char

public char Char { get; }

Property Value

char

Double

public double Double { get; }

Property Value

double

Float

public float Float { get; }

Property Value

float

Int

public int Int { get; }

Property Value

int

IsBridgeAbstract

public override bool IsBridgeAbstract { get; }

Property Value

bool

IsBridgeCloseable

public override bool IsBridgeCloseable { get; }

Property Value

bool

IsBridgeInterface

public override bool IsBridgeInterface { get; }

Property Value

bool

IsBridgeStatic

public override bool IsBridgeStatic { get; }

Property Value

bool

Long

public long Long { get; }

Property Value

long

Short

public short Short { get; }

Property Value

short

Methods

AlignedSlice(int)

public ByteBuffer AlignedSlice(int arg0)

Parameters

arg0 int

int

Returns

ByteBuffer

ByteBuffer

AlignmentOffset(int, int)

public int AlignmentOffset(int arg0, int arg1)

Parameters

arg0 int

int

arg1 int

int

Returns

int

int

Allocate(int)

public static ByteBuffer Allocate(int arg0)

Parameters

arg0 int

int

Returns

ByteBuffer

ByteBuffer

AllocateDirect(int)

public static ByteBuffer AllocateDirect(int arg0)

Parameters

arg0 int

int

Returns

ByteBuffer

ByteBuffer

AsCharBuffer()

public CharBuffer AsCharBuffer()

Returns

CharBuffer

CharBuffer

AsDoubleBuffer()

public DoubleBuffer AsDoubleBuffer()

Returns

DoubleBuffer

DoubleBuffer

AsFloatBuffer()

public FloatBuffer AsFloatBuffer()

Returns

FloatBuffer

FloatBuffer

AsIntBuffer()

public IntBuffer AsIntBuffer()

Returns

IntBuffer

IntBuffer

AsLongBuffer()

public LongBuffer AsLongBuffer()

Returns

LongBuffer

LongBuffer

AsReadOnlyBuffer()

public ByteBuffer AsReadOnlyBuffer()

Returns

ByteBuffer

ByteBuffer

AsShortBuffer()

public ShortBuffer AsShortBuffer()

Returns

ShortBuffer

ShortBuffer

Compact()

public ByteBuffer Compact()

Returns

ByteBuffer

ByteBuffer

CompareTo(ByteBuffer)

public int CompareTo(ByteBuffer arg0)

Parameters

arg0 ByteBuffer

ByteBuffer

Returns

int

int

CompareTo(object)

public int CompareTo(object arg0)

Parameters

arg0 object

object

Returns

int

int

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public override void Dispose()

From(byte[], bool, bool, int)

Creates a new ByteBuffer in the JVM which belongs to data

public static ByteBuffer From(byte[] data, bool useMemoryControlBlock = true, bool arrangeCapacity = true, int timeToLive = -1)

Parameters

data byte[]

The data to be shared

useMemoryControlBlock bool

Appends to the end of the data a memory block will be used to controls and arbitrates memory between CLR and JVM

arrangeCapacity bool

If true the byte array in data will be resized to the next power of 2, so capacity will be memory aligned and the limit of ByteBuffer will be current size of data

timeToLive int

The time to live, expressed in milliseconds, the underlying memory shall remain available; if the time to live expires the pinned memory is retired leaving potentially the JVM under the possibility of an access violation.

Returns

ByteBuffer

A new instance of ByteBuffer holding the memory of data

Remarks

The memory associated to data will be pinned until the JVM reference of the newly created ByteBuffer is garbage collected to avoid access violation within the JVM. Under heavy pressure the memory footprint can raise up and generate an OutOfMemoryException, use the functionality with caution or take into account the timeToLive option which can help to recover the memory in advance before the Garbage Collector of the JVM retires the ByteBuffer If the user of ByteBuffer is pretty sure that the pinned memory is no more needed from the JVM, e.g. the invoked method does not queue the ByteBuffer and its lifetime ends when the method returns, invoke Dispose() to immediately release unmanaged resources and free the memory

From(MemoryStream, bool, EventHandler<MemoryStream>, int)

Creates a new ByteBuffer in the JVM which shares the stream. The method helps to avoid too many array copies from CLR to JVM

public static ByteBuffer From(MemoryStream stream, bool useMemoryControlBlock = true, EventHandler<MemoryStream> disposeEvent = null, int timeToLive = -1)

Parameters

stream MemoryStream

The non disposed MemoryStream to be used directly within the JVM from a ByteBuffer, see remarks

useMemoryControlBlock bool

Appends to the end of the stream a memory block will be used to controls and arbitrates memory between CLR and JVM

disposeEvent EventHandler<MemoryStream>

An optional EventHandler<TEventArgs> can be used to be informed when the stream can be safely disposed (the dispose action shall be in the user code), if null the underlying system will automatically dispose the MemoryStream.

timeToLive int

The time to live, expressed in milliseconds, the underlying memory shall remain available; if the time to live expires the pinned memory is retired leaving potentially the JVM under the possibility of an access violation.

Returns

ByteBuffer

A new instance of ByteBuffer holding the memory of stream shared with the ByteBuffer

Remarks

The memory associated to stream will be pinned until the JVM reference of the newly created ByteBuffer is garbage collected to avoid access violation within the JVM. Under heavy pressure the memory footprint can raise up and generate an OutOfMemoryException, use the functionality with caution or take into account the timeToLive option which can help to recover the memory in advance before the Garbage Collector of the JVM retires the ByteBufferThe MemoryStream cannot be disposed otherwise the underlying system is not able to access the memory. The MemoryStream can be written, or read, and changes are visible to both CLR and JVM, however, if the MemoryStream grows, the underlying system cannot resize too and capacity still remains the one when From(MemoryStream, bool, EventHandler<MemoryStream>, int) was invoked the first time.

From(IntPtr, long, EventHandler<object>, object, int)

Creates a new ByteBuffer in the JVM which belongs to rawAddr.

public static ByteBuffer From(IntPtr rawAddr, long capacity, EventHandler<object> disposeEvent = null, object disposeEventState = null, int timeToLive = -1)

Parameters

rawAddr IntPtr

The pointer where data is stored

capacity long

Declares the memory available, in byte, associated to rawAddr

disposeEvent EventHandler<object>

An optional EventHandler<TEventArgs> can be used to be informed when the rawAddr can be safely retired becuase the JVM is no moore using the pointer of rawAddr.

disposeEventState object

The data will be associated to disposeEvent, by default the value will be rawAddr

timeToLive int

The time to live, expressed in milliseconds, the underlying memory shall remain available; if the time to live expires the pinned memory is retired leaving potentially the JVM under the possibility of an access violation.

Returns

ByteBuffer

A new instance of ByteBuffer holding the memory of rawAddr

Remarks

The memory associated to rawAddr shall be available until the JVM reference of the newly created ByteBuffer is garbage collected to avoid access violation within the JVM. Under heavy pressure the memory footprint can raise up and generate an OutOfMemoryException, use the functionality with caution or take into account the timeToLive option which can help to recover the memory in advance before the Garbage Collector of the JVM retires the ByteBuffer If the user of ByteBuffer is pretty sure that the memory is no more needed from the JVM, e.g. the invoked method does not queue the ByteBuffer and its lifetime ends when the method returns, invoke Dispose() to immediately release unmanaged resources and free the memory

Get()

public byte Get()

Returns

byte

byte

Get(byte[])

public ByteBuffer Get(byte[] arg0)

Parameters

arg0 byte[]

byte

Returns

ByteBuffer

ByteBuffer

Get(byte[], int, int)

public ByteBuffer Get(byte[] arg0, int arg1, int arg2)

Parameters

arg0 byte[]

byte

arg1 int

int

arg2 int

int

Returns

ByteBuffer

ByteBuffer

Get(int)

public byte Get(int arg0)

Parameters

arg0 int

int

Returns

byte

byte

GetChar(int)

public char GetChar(int arg0)

Parameters

arg0 int

int

Returns

char

char

GetDouble(int)

public double GetDouble(int arg0)

Parameters

arg0 int

int

Returns

double

double

GetFloat(int)

public float GetFloat(int arg0)

Parameters

arg0 int

int

Returns

float

float

GetInt(int)

public int GetInt(int arg0)

Parameters

arg0 int

int

Returns

int

int

GetLong(int)

public long GetLong(int arg0)

Parameters

arg0 int

int

Returns

long

long

GetShort(int)

public short GetShort(int arg0)

Parameters

arg0 int

int

Returns

short

short

Mismatch(ByteBuffer)

public int Mismatch(ByteBuffer arg0)

Parameters

arg0 ByteBuffer

ByteBuffer

Returns

int

int

Order()

public ByteOrder Order()

Returns

ByteOrder

ByteOrder

Order(ByteOrder)

public ByteBuffer Order(ByteOrder arg0)

Parameters

arg0 ByteOrder

ByteOrder

Returns

ByteBuffer

ByteBuffer

Put(ByteBuffer)

public ByteBuffer Put(ByteBuffer arg0)

Parameters

arg0 ByteBuffer

ByteBuffer

Returns

ByteBuffer

ByteBuffer

Put(byte)

public ByteBuffer Put(byte arg0)

Parameters

arg0 byte

byte

Returns

ByteBuffer

ByteBuffer

Put(byte[])

public ByteBuffer Put(byte[] arg0)

Parameters

arg0 byte[]

byte

Returns

ByteBuffer

ByteBuffer

Put(byte[], int, int)

public ByteBuffer Put(byte[] arg0, int arg1, int arg2)

Parameters

arg0 byte[]

byte

arg1 int

int

arg2 int

int

Returns

ByteBuffer

ByteBuffer

Put(int, byte)

public ByteBuffer Put(int arg0, byte arg1)

Parameters

arg0 int

int

arg1 byte

byte

Returns

ByteBuffer

ByteBuffer

PutChar(char)

public ByteBuffer PutChar(char arg0)

Parameters

arg0 char

char

Returns

ByteBuffer

ByteBuffer

PutChar(int, char)

public ByteBuffer PutChar(int arg0, char arg1)

Parameters

arg0 int

int

arg1 char

char

Returns

ByteBuffer

ByteBuffer

PutDouble(double)

public ByteBuffer PutDouble(double arg0)

Parameters

arg0 double

double

Returns

ByteBuffer

ByteBuffer

PutDouble(int, double)

public ByteBuffer PutDouble(int arg0, double arg1)

Parameters

arg0 int

int

arg1 double

double

Returns

ByteBuffer

ByteBuffer

PutFloat(int, float)

public ByteBuffer PutFloat(int arg0, float arg1)

Parameters

arg0 int

int

arg1 float

float

Returns

ByteBuffer

ByteBuffer

PutFloat(float)

public ByteBuffer PutFloat(float arg0)

Parameters

arg0 float

float

Returns

ByteBuffer

ByteBuffer

PutInt(int)

public ByteBuffer PutInt(int arg0)

Parameters

arg0 int

int

Returns

ByteBuffer

ByteBuffer

PutInt(int, int)

public ByteBuffer PutInt(int arg0, int arg1)

Parameters

arg0 int

int

arg1 int

int

Returns

ByteBuffer

ByteBuffer

PutLong(int, long)

public ByteBuffer PutLong(int arg0, long arg1)

Parameters

arg0 int

int

arg1 long

long

Returns

ByteBuffer

ByteBuffer

PutLong(long)

public ByteBuffer PutLong(long arg0)

Parameters

arg0 long

long

Returns

ByteBuffer

ByteBuffer

PutShort(short)

public ByteBuffer PutShort(short arg0)

Parameters

arg0 short

short

Returns

ByteBuffer

ByteBuffer

PutShort(int, short)

public ByteBuffer PutShort(int arg0, short arg1)

Parameters

arg0 int

int

arg1 short

short

Returns

ByteBuffer

ByteBuffer

ToArray(bool)

Returns the byte array managed from this ByteBuffer

public byte[] ToArray(bool bypassDirectConvert = false)

Parameters

bypassDirectConvert bool

true to bypass the conversion using direct buffer

Returns

byte[]

The byte array managed from this ByteBuffer

ToArray(ref byte[], bool)

Fills the array with data managed from this ByteBuffer

public void ToArray(ref byte[] array, bool resizeToFill = true)

Parameters

array byte[]

The array to be filled with the content of the ByteBuffer

resizeToFill bool

Resize array to contain all data available in the ByteBuffer

ToDirectBuffer()

Returns an instance of MASES.JCOBridge.C2JBridge.JCOBridgeDirectBuffer<T>

public JCOBridgeDirectBuffer<byte> ToDirectBuffer()

Returns

JCOBridgeDirectBuffer<byte>

The MASES.JCOBridge.C2JBridge.JCOBridgeDirectBuffer<T> associated to this ByteBuffer instance

Remarks

The returned MASES.JCOBridge.C2JBridge.JCOBridgeDirectBuffer<T> can be used to directly access and manages JVM memory without any memory move

ToStream()

Returns an instance of Stream associated to this ByteBuffer instance

public Stream ToStream()

Returns

Stream

The Stream associated to this ByteBuffer instance

Remarks

The returned Stream can be used to directly access and manages JVM memory without any memory move

Wrap(byte[])

public static ByteBuffer Wrap(byte[] arg0)

Parameters

arg0 byte[]

byte

Returns

ByteBuffer

ByteBuffer

Wrap(byte[], int, int)

public static ByteBuffer Wrap(byte[] arg0, int arg1, int arg2)

Parameters

arg0 byte[]

byte

arg1 int

int

arg2 int

int

Returns

ByteBuffer

ByteBuffer

Operators

implicit operator Comparable(ByteBuffer)

Converter from ByteBuffer to Comparable

public static implicit operator Comparable(ByteBuffer t)

Parameters

t ByteBuffer

Returns

Comparable

implicit operator Comparable<ByteBuffer>(ByteBuffer)

Converter from ByteBuffer to Comparable<T>

public static implicit operator Comparable<ByteBuffer>(ByteBuffer buffer)

Parameters

buffer ByteBuffer

Returns

Comparable<ByteBuffer>

implicit operator JCOBridgeDirectBuffer<byte>(ByteBuffer)

Converts an instance of ByteBuffer into MASES.JCOBridge.C2JBridge.JCOBridgeDirectBuffer<T>

public static implicit operator JCOBridgeDirectBuffer<byte>(ByteBuffer t)

Parameters

t ByteBuffer

Returns

JCOBridgeDirectBuffer<byte>

implicit operator byte[](ByteBuffer)

Converts an instance of ByteBuffer into byte array

public static implicit operator byte[](ByteBuffer t)

Parameters

t ByteBuffer

Returns

byte[]

Remarks

If the ByteBuffer supports direct access the function tries to move data from JVM memory without JNI, otherwise fallback to the standard memory copy.

implicit operator Stream(ByteBuffer)

Converts an instance of ByteBuffer into Stream

public static implicit operator Stream(ByteBuffer t)

Parameters

t ByteBuffer

Returns

Stream

Remarks

The returned Stream can be used to directly access and manages JVM memory without any memory move

implicit operator ByteBuffer(byte[])

Converts an instance of byte array into ByteBuffer using the default parameters of From(byte[], bool, bool, int)

public static implicit operator ByteBuffer(byte[] t)

Parameters

t byte[]

Returns

ByteBuffer

Remarks

If the JVM supports direct access the function will share with the JVM the memory without JNI, otherwise fallback to the standard memory copy.

implicit operator ByteBuffer(MemoryStream)

Converts an instance of MemoryStream into a ByteBuffer using the default parameters of From(MemoryStream, bool, EventHandler<MemoryStream>, int)

public static implicit operator ByteBuffer(MemoryStream stream)

Parameters

stream MemoryStream

Returns

ByteBuffer

Remarks