C# Class BitSharper.IO.ByteBuffer

This type supports the Fluorine infrastructure and is not intended to be used directly from your code. http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html The following invariant holds for the mark, position, limit, and capacity values: 0 <= mark <= position <= limit <= capacity
Inheritance: Stream
Mostra file Open project: TangibleCryptography/BitSharper Class Usage Examples

Public Methods

Method Description
Allocate ( int capacity ) : ByteBuffer

Allocates a new byte buffer. The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero.

Append ( byte src ) : void

Appends a byte buffer to this ByteArray.

Append ( byte src, int offset, int length ) : void

Appends a byte buffer to this ByteArray.

ByteBuffer ( MemoryStream stream ) : System

Initializes a new instance of the ByteBuffer class.

Clear ( ) : void

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

ClearBookmark ( ) : void

Clears the current bookmark.

Close ( ) : void

Closes the current stream and releases any resources associated with the current stream.

Compact ( ) : void

Compacts this buffer The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded. The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.

Dump ( string file ) : void

Write the buffer content to a file.

Equals ( object obj ) : bool

Tells whether or not this buffer is equal to another object.

Fill ( byte value, int count ) : void

Fills this buffer with the specified value.

Flip ( ) : void

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

Flush ( ) : void

Clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Get ( ) : byte

Relative get method. Reads the byte at this buffer's current position, and then increments the position.

Get ( int index ) : byte

Absolute get method. Reads the byte at the given index.

Get ( byte dst ) : void

Relative bulk get method.

GetBuffer ( ) : byte[]

Returns the array of unsigned bytes from which this stream was created.

GetHashCode ( ) : int

Returns the current hash code of this buffer.

GetInt ( ) : int

Reads a 4-byte signed integer using network byte order encoding.

GetShort ( ) : short

Reads a 2-byte signed integer using network byte order encoding.

Mark ( ) : long

Sets this buffer's bookmark at its position.

Put ( ByteBuffer output, ByteBuffer input, int numBytesMax ) : int

Puts an in buffer stream onto an out buffer stream and returns the bytes written.

Put ( ByteBuffer src ) : void

This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no bytes are transferred and a BufferOverflowException is thrown. Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

Put ( ByteBuffer src, int count ) : void

Transfers the specified number of bytes from the given source buffer into this buffer.

Put ( byte value ) : void

Writes the given byte into this buffer at the current position, and then increments the position.

Put ( byte src, int offset, int length ) : void

Relative bulk put method. This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length > remaining(), then no bytes are transferred and a BufferOverflowException is thrown. Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

Put ( int index, UInt16 value ) : void
Put ( int index, UInt32 value ) : void

Absolute put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.

Put ( int index, byte value ) : void

Absolute put method. Writes the given byte into this buffer at the given index.

PutInt ( int value ) : void

Relative put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.

PutInt ( int index, int value ) : void

Absolute put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.

PutShort ( short value ) : void

Writes a 16-bit unsigned integer to the current position.

Read ( byte buffer ) : int

Relative bulk get method. This method transfers bytes from this buffer into the given destination array. An invocation of this method behaves in exactly the same way as the invocation buffer.Get(a, 0, a.Length)

Read ( byte buffer, int offset, int count ) : int

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

ReadByte ( ) : int

Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

ReadBytes ( int count ) : byte[]

Reads count bytes from the current stream into a byte array and advances the current position by count bytes.

ReadReverseInt ( ) : int

Reads a 4-byte signed integer.

ReadUInt24 ( ) : int
Reset ( ) : void

Resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.

Rewind ( ) : void

Rewinds this buffer. The position is set to zero and the mark is discarded.

Seek ( long offset, SeekOrigin origin ) : long

Sets the position within the current stream.

SetLength ( long value ) : void

Sets the length of the current stream.

Skip ( int size ) : void

Forwards the position of this buffer as the specified size bytes.

ToArray ( ) : byte[]

Writes the stream contents to a byte array, regardless of the Position property.

This method omits unused bytes in ByteBuffer from the array. To get the entire buffer, use the GetBuffer method.

ToString ( ) : string

Returns a string summarizing the state of this buffer.

Wrap ( byte array ) : ByteBuffer

Wraps a byte array into a buffer. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be array.length, its position will be zero, and its mark will be undefined.

Wrap ( byte array, int offset, int length ) : ByteBuffer

Wraps a byte array into a buffer. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity will be array.length, its position will be offset, its limit will be offset + length, and its mark will be undefined.

Write ( byte buffer, int offset, int count ) : void

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

WriteByte ( byte value ) : void

Writes a byte to the current position in the stream and advances the position within the stream by one byte.

WriteMediumInt ( int value ) : void

Writes a 32-bit signed integer to the current position using variable length unsigned 29-bit integer encoding.

WriteReverseInt ( int value ) : void
this ( int index ) : byte

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases all resources used by this object.

Private Methods

Method Description
WriteBigEndian ( byte bytes ) : void
WriteBigEndian ( int index, byte bytes ) : void
WriteBytes ( int index, byte bytes ) : void

Method Details

Allocate() public static method

Allocates a new byte buffer. The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero.
public static Allocate ( int capacity ) : ByteBuffer
capacity int
return ByteBuffer

Append() public method

Appends a byte buffer to this ByteArray.
public Append ( byte src ) : void
src byte The byte buffer to append.
return void

Append() public method

Appends a byte buffer to this ByteArray.
public Append ( byte src, int offset, int length ) : void
src byte The byte buffer to append.
offset int Offset in the byte buffer.
length int Number of bytes to append.
return void

ByteBuffer() public method

Initializes a new instance of the ByteBuffer class.
public ByteBuffer ( MemoryStream stream ) : System
stream System.IO.MemoryStream Wraps the MemoryStream into a buffer.
return System

Clear() public method

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
public Clear ( ) : void
return void

ClearBookmark() public method

Clears the current bookmark.
public ClearBookmark ( ) : void
return void

Close() public method

Closes the current stream and releases any resources associated with the current stream.
public Close ( ) : void
return void

Compact() public method

Compacts this buffer The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded. The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
public Compact ( ) : void
return void

Dispose() protected method

Releases all resources used by this object.
protected Dispose ( bool disposing ) : void
disposing bool Indicates if this is a dispose call dispose.
return void

Dump() public method

Write the buffer content to a file.
public Dump ( string file ) : void
file string
return void

Equals() public method

Tells whether or not this buffer is equal to another object.
public Equals ( object obj ) : bool
obj object The object to which this buffer is to be compared
return bool

Fill() public method

Fills this buffer with the specified value.
public Fill ( byte value, int count ) : void
value byte
count int
return void

Flip() public method

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.
public Flip ( ) : void
return void

Flush() public method

Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
public Flush ( ) : void
return void

Get() public method

Relative get method. Reads the byte at this buffer's current position, and then increments the position.
public Get ( ) : byte
return byte

Get() public method

Absolute get method. Reads the byte at the given index.
public Get ( int index ) : byte
index int
return byte

Get() public method

Relative bulk get method.
public Get ( byte dst ) : void
dst byte
return void

GetBuffer() public method

Returns the array of unsigned bytes from which this stream was created.
public GetBuffer ( ) : byte[]
return byte[]

GetHashCode() public method

Returns the current hash code of this buffer.
public GetHashCode ( ) : int
return int

GetInt() public method

Reads a 4-byte signed integer using network byte order encoding.
public GetInt ( ) : int
return int

GetShort() public method

Reads a 2-byte signed integer using network byte order encoding.
public GetShort ( ) : short
return short

Mark() public method

Sets this buffer's bookmark at its position.
public Mark ( ) : long
return long

Put() public static method

Puts an in buffer stream onto an out buffer stream and returns the bytes written.
public static Put ( ByteBuffer output, ByteBuffer input, int numBytesMax ) : int
output ByteBuffer
input ByteBuffer
numBytesMax int
return int

Put() public method

This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no bytes are transferred and a BufferOverflowException is thrown. Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
public Put ( ByteBuffer src ) : void
src ByteBuffer The source buffer from which bytes are to be read; must not be this buffer.
return void

Put() public method

Transfers the specified number of bytes from the given source buffer into this buffer.
public Put ( ByteBuffer src, int count ) : void
src ByteBuffer The source buffer from which bytes are to be read; must not be this buffer.
count int Number of bytes to transfer.
return void

Put() public method

Writes the given byte into this buffer at the current position, and then increments the position.
public Put ( byte value ) : void
value byte
return void

Put() public method

Relative bulk put method. This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length > remaining(), then no bytes are transferred and a BufferOverflowException is thrown. Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.
public Put ( byte src, int offset, int length ) : void
src byte The array from which bytes are to be read.
offset int The offset within the array of the first byte to be read; must be non-negative and no larger than the array length.
length int The number of bytes to be read from the given array; must be non-negative and no larger than length - offset.
return void

Put() public method

public Put ( int index, UInt16 value ) : void
index int
value System.UInt16
return void

Put() public method

Absolute put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.
public Put ( int index, UInt32 value ) : void
index int The index at which the bytes will be written.
value System.UInt32 The int value to be written.
return void

Put() public method

Absolute put method. Writes the given byte into this buffer at the given index.
public Put ( int index, byte value ) : void
index int The index.
value byte The byte to write.
return void

PutInt() public method

Relative put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.
public PutInt ( int value ) : void
value int The int value to be written.
return void

PutInt() public method

Absolute put method for writing an int value. Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.
public PutInt ( int index, int value ) : void
index int The index at which the bytes will be written.
value int The int value to be written.
return void

PutShort() public method

Writes a 16-bit unsigned integer to the current position.
public PutShort ( short value ) : void
value short A 16-bit unsigned integer.
return void

Read() public method

Relative bulk get method. This method transfers bytes from this buffer into the given destination array. An invocation of this method behaves in exactly the same way as the invocation buffer.Get(a, 0, a.Length)
public Read ( byte buffer ) : int
buffer byte An array of bytes.
return int

Read() public method

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
public Read ( byte buffer, int offset, int count ) : int
buffer byte An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offset int The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count int The maximum number of bytes to be read from the current stream.
return int

ReadByte() public method

Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
public ReadByte ( ) : int
return int

ReadBytes() public method

Reads count bytes from the current stream into a byte array and advances the current position by count bytes.
public ReadBytes ( int count ) : byte[]
count int
return byte[]

ReadReverseInt() public method

Reads a 4-byte signed integer.
public ReadReverseInt ( ) : int
return int

ReadUInt24() public method

public ReadUInt24 ( ) : int
return int

Reset() public method

Resets this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.
public Reset ( ) : void
return void

Rewind() public method

Rewinds this buffer. The position is set to zero and the mark is discarded.
public Rewind ( ) : void
return void

Seek() public method

Sets the position within the current stream.
public Seek ( long offset, SeekOrigin origin ) : long
offset long A byte offset relative to the origin parameter.
origin SeekOrigin A value of type SeekOrigin indicating the reference point used to obtain the new position.
return long

SetLength() public method

Sets the length of the current stream.
public SetLength ( long value ) : void
value long The desired length of the current stream in bytes.
return void

Skip() public method

Forwards the position of this buffer as the specified size bytes.
public Skip ( int size ) : void
size int
return void

ToArray() public method

Writes the stream contents to a byte array, regardless of the Position property.
This method omits unused bytes in ByteBuffer from the array. To get the entire buffer, use the GetBuffer method.
public ToArray ( ) : byte[]
return byte[]

ToString() public method

Returns a string summarizing the state of this buffer.
public ToString ( ) : string
return string

Wrap() public static method

Wraps a byte array into a buffer. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be array.length, its position will be zero, and its mark will be undefined.
public static Wrap ( byte array ) : ByteBuffer
array byte
return ByteBuffer

Wrap() public static method

Wraps a byte array into a buffer. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity will be array.length, its position will be offset, its limit will be offset + length, and its mark will be undefined.
public static Wrap ( byte array, int offset, int length ) : ByteBuffer
array byte Byte array to wrap.
offset int Offset in the byte array.
length int
return ByteBuffer

Write() public method

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies count bytes from buffer to the current stream.
offset int The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count int The number of bytes to be written to the current stream.
return void

WriteByte() public method

Writes a byte to the current position in the stream and advances the position within the stream by one byte.
public WriteByte ( byte value ) : void
value byte The byte to write to the stream.
return void

WriteMediumInt() public method

Writes a 32-bit signed integer to the current position using variable length unsigned 29-bit integer encoding.
public WriteMediumInt ( int value ) : void
value int A 32-bit signed integer.
return void

WriteReverseInt() public method

public WriteReverseInt ( int value ) : void
value int
return void

this() public method

public this ( int index ) : byte
index int
return byte