Class ByteBuffer
public class ByteBuffer : Buffer, IDynamicMetaObjectProvider, IJVMBridgeCore, IJVMBridgeBaseStatic, IJVMBridgeBase, IJVMBridgeDefinition, IDisposable
- Inheritance
-
JVMBridgeBaseJVMBridgeBase<Buffer>ByteBuffer
- Implements
-
IJVMBridgeCoreIJVMBridgeBaseStaticIJVMBridgeBaseIJVMBridgeDefinition
- Derived
- Inherited Members
-
JVMBridgeBase<Buffer>.IsAssignableFrom(IJavaType)JVMBridgeBase<Buffer>.IsAssignableFrom<T>()JVMBridgeBase<Buffer>.Execute<T>(params T[])JVMBridgeBase<Buffer>.DynBridgeClazzJVMBridgeBase<Buffer>.BridgeClazzJVMBridgeBase.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.IExecuteWithSignature<TNewClass, TReturn, TConverter>(string, string, params object[])JVMBridgeBase.DynBridgeInstanceJVMBridgeBase.BridgeInstanceJVMBridgeBase.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
https://www.jcobridge.com/api-clr/html/P_MASES_JCOBridge_C2JBridge_JVMBridgeBase_BridgeClassName.htm
public override string BridgeClassName { get; }
Property Value
Char
public char Char { get; }
Property Value
Double
public double Double { get; }
Property Value
Float
public float Float { get; }
Property Value
Int
public int Int { get; }
Property Value
IsBridgeAbstract
public override bool IsBridgeAbstract { get; }
Property Value
IsBridgeCloseable
public override bool IsBridgeCloseable { get; }
Property Value
IsBridgeInterface
public override bool IsBridgeInterface { get; }
Property Value
IsBridgeStatic
public override bool IsBridgeStatic { get; }
Property Value
Long
public long Long { get; }
Property Value
Short
public short Short { get; }
Property Value
Methods
AlignedSlice(int)
public ByteBuffer AlignedSlice(int arg0)
Parameters
Returns
AlignmentOffset(int, int)
public int AlignmentOffset(int arg0, int arg1)
Parameters
Returns
Allocate(int)
public static ByteBuffer Allocate(int arg0)
Parameters
Returns
AllocateDirect(int)
public static ByteBuffer AllocateDirect(int arg0)
Parameters
Returns
AsCharBuffer()
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/ByteBuffer.html#asCharBuffer()
public CharBuffer AsCharBuffer()
Returns
AsDoubleBuffer()
public DoubleBuffer AsDoubleBuffer()
Returns
AsFloatBuffer()
public FloatBuffer AsFloatBuffer()
Returns
AsIntBuffer()
public IntBuffer AsIntBuffer()
Returns
AsLongBuffer()
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/ByteBuffer.html#asLongBuffer()
public LongBuffer AsLongBuffer()
Returns
AsReadOnlyBuffer()
public ByteBuffer AsReadOnlyBuffer()
Returns
AsShortBuffer()
public ShortBuffer AsShortBuffer()
Returns
Compact()
public ByteBuffer Compact()
Returns
CompareTo(ByteBuffer)
public int CompareTo(ByteBuffer arg0)
Parameters
arg0
ByteBuffer
Returns
CompareTo(object)
public int CompareTo(object arg0)
Parameters
Returns
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
boolAppends to the end of the
data
a memory block will be used to controls and arbitrates memory between CLR and JVMarrangeCapacity
boolIf 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 ofdata
timeToLive
intThe 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
MemoryStreamThe non disposed MemoryStream to be used directly within the JVM from a ByteBuffer, see remarks
useMemoryControlBlock
boolAppends to the end of the
stream
a memory block will be used to controls and arbitrates memory between CLR and JVMdisposeEvent
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
intThe 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
IntPtrThe pointer where data is stored
capacity
longDeclares 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 ofrawAddr
.disposeEventState
objectThe data will be associated to
disposeEvent
, by default the value will berawAddr
timeToLive
intThe 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
Get(byte[])
public ByteBuffer Get(byte[] arg0)
Parameters
Returns
Get(byte[], int, int)
public ByteBuffer Get(byte[] arg0, int arg1, int arg2)
Parameters
Returns
Get(int)
public byte Get(int arg0)
Parameters
Returns
GetChar(int)
public char GetChar(int arg0)
Parameters
Returns
GetDouble(int)
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/ByteBuffer.html#getDouble(int)
public double GetDouble(int arg0)
Parameters
Returns
GetFloat(int)
public float GetFloat(int arg0)
Parameters
Returns
GetInt(int)
public int GetInt(int arg0)
Parameters
Returns
GetLong(int)
public long GetLong(int arg0)
Parameters
Returns
GetShort(int)
public short GetShort(int arg0)
Parameters
Returns
Mismatch(ByteBuffer)
public int Mismatch(ByteBuffer arg0)
Parameters
arg0
ByteBuffer
Returns
Order()
public ByteOrder Order()
Returns
Order(ByteOrder)
public ByteBuffer Order(ByteOrder arg0)
Parameters
Returns
Put(ByteBuffer)
public ByteBuffer Put(ByteBuffer arg0)
Parameters
arg0
ByteBuffer
Returns
Put(byte)
public ByteBuffer Put(byte arg0)
Parameters
Returns
Put(byte[])
public ByteBuffer Put(byte[] arg0)
Parameters
Returns
Put(byte[], int, int)
public ByteBuffer Put(byte[] arg0, int arg1, int arg2)
Parameters
Returns
Put(int, byte)
public ByteBuffer Put(int arg0, byte arg1)
Parameters
Returns
PutChar(char)
public ByteBuffer PutChar(char arg0)
Parameters
Returns
PutChar(int, char)
public ByteBuffer PutChar(int arg0, char arg1)
Parameters
Returns
PutDouble(double)
public ByteBuffer PutDouble(double arg0)
Parameters
Returns
PutDouble(int, double)
public ByteBuffer PutDouble(int arg0, double arg1)
Parameters
Returns
PutFloat(int, float)
public ByteBuffer PutFloat(int arg0, float arg1)
Parameters
Returns
PutFloat(float)
public ByteBuffer PutFloat(float arg0)
Parameters
Returns
PutInt(int)
public ByteBuffer PutInt(int arg0)
Parameters
Returns
PutInt(int, int)
public ByteBuffer PutInt(int arg0, int arg1)
Parameters
Returns
PutLong(int, long)
public ByteBuffer PutLong(int arg0, long arg1)
Parameters
Returns
PutLong(long)
public ByteBuffer PutLong(long arg0)
Parameters
Returns
PutShort(short)
public ByteBuffer PutShort(short arg0)
Parameters
Returns
PutShort(int, short)
public ByteBuffer PutShort(int arg0, short arg1)
Parameters
Returns
ToArray(bool)
Returns the byte array managed from this ByteBuffer
public byte[] ToArray(bool bypassDirectConvert = false)
Parameters
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
boolResize
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
Returns
Wrap(byte[], int, int)
public static ByteBuffer Wrap(byte[] arg0, int arg1, int arg2)
Parameters
Returns
Operators
implicit operator Comparable(ByteBuffer)
Converter from ByteBuffer to Comparable
public static implicit operator Comparable(ByteBuffer t)
Parameters
Returns
implicit operator Comparable<ByteBuffer>(ByteBuffer)
Converter from ByteBuffer to Comparable<T>
public static implicit operator Comparable<ByteBuffer>(ByteBuffer buffer)
Parameters
buffer
ByteBuffer
Returns
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
Returns
- JCOBridgeDirectBuffer<byte>
implicit operator byte[](ByteBuffer)
Converts an instance of ByteBuffer into byte array
public static implicit operator byte[](ByteBuffer t)
Parameters
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
Returns
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
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
Remarks
See remarks of From(MemoryStream, bool, EventHandler<MemoryStream>, int)