Class Binary
A thread-safe immutable binary object.
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
[Serializable]
public sealed class Binary
Constructors
Binary()
Default constructor for a Binary object.
Declaration
public Binary()
Binary(byte[])
Construct a Binary object from a byte array.
Declaration
public Binary(byte[] ab)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | An array of bytes. |
Binary(byte[], int, int)
Construct a Binary on a portion of a byte array.
Declaration
public Binary(byte[] ab, int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | A byte array. |
int | of | An offset into the byte array. |
int | cb | The number of bytes to utilize. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If is larger than .
|
ArgumentNullException | If byte array is |
Binary(Stream, int)
Construct a Binary from a Stream.
Declaration
public Binary(Stream stream, int cb)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream from which the Binary will load its data. |
int | cb | The number of bytes to read from the Stream. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If |
Fields
NO_BINARY
An empty Binary object.
Declaration
public static readonly Binary NO_BINARY
Field Value
Type | Description |
---|---|
Binary |
NO_BYTES
An empty byte array (by definition immutable).
Declaration
public static readonly byte[] NO_BYTES
Field Value
Type | Description |
---|---|
byte[] |
Properties
Length
Determine the length of the Binary.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
int | The number of bytes of data represented by this Binary. |
Methods
ByteAt(int)
Returns a byte at the specified position.
Declaration
public byte ByteAt(int of)
Parameters
Type | Name | Description |
---|---|---|
int | of | Offset of the byte to return. |
Returns
Type | Description |
---|---|
byte | Byte at the specified position. |
CalculateNaturalPartition(int)
Calculate the partition ID to which the specified Binary should be naturally assigned. This calculation should not be applied to Binary objects decorated with artificially assigned partitions.
Declaration
public int CalculateNaturalPartition(int cPartitions)
Parameters
Type | Name | Description |
---|---|---|
int | cPartitions | The partition count. |
Returns
Type | Description |
---|---|
int | The partition that the this Binary is naturally assigned to. |
Remarks
The resulting partition ID will be in the range [0..cPartitions).
Clone(byte[], int, int)
Create a clone of the specified binary region.
Declaration
public static byte[] Clone(byte[] ab, int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | The byte array containing the binary region to copy from. |
int | of | The offset of the binary region within ab. |
int | cb | The size in bytes of the binary region to copy. |
Returns
Type | Description |
---|---|
byte[] | The specified binary region cloned. |
Equals(byte[], int, byte[], int, int)
Compare two binary regions, testing for equality.
Declaration
public static bool Equals(byte[] ab1, int of1, byte[] ab2, int of2, int cb)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab1 | The byte array containing the first binary region to compare. |
int | of1 | The offset of the binary region within |
byte[] | ab2 | The byte array containing the second binary region to compare. |
int | of2 | The offset of the binary region within |
int | cb | The size of the binary regions, which is the number of bytes to compare. |
Returns
Type | Description |
---|---|
bool |
|
Equals(object)
Compare this object with another object to determine equality.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | The object to compare with current object. |
Returns
Type | Description |
---|---|
bool | true if this object and the passed object are equivalent Binary objects. |
Overrides
GetBinary(int, int)
Get a Binary representing a subset of this Binary.
Declaration
public Binary GetBinary(int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
int | of | Offset of the first byte. |
int | cb | The number of bytes. |
Returns
Type | Description |
---|---|
Binary | A new Binary view, backed by this Binary object. |
Remarks
This method simply returns a limited "view" into the underlying Binary it is invoked on, without allocating new buffer to hold the data.
GetHashCode()
Determine a hash value for the Binary object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | An integer hash value for this Binary object. |
Overrides
GetReader()
Return a DataReader to read this Binary's contents from.
Declaration
public DataReader GetReader()
Returns
Type | Description |
---|---|
DataReader | A DataReader backed by this Binary. |
GetStream()
Get a Stream to read the Binary object's contents from.
Declaration
public Stream GetStream()
Returns
Type | Description |
---|---|
Stream | A Stream backed by this Binary object. |
GetStream(int, int)
Get a Stream to read the Binary object's contents from.
Declaration
public Stream GetStream(int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
int | of | Offset of the first byte. |
int | cb | The number of bytes. |
Returns
Type | Description |
---|---|
Stream | A Stream backed by this Binary object. |
ToByteArray()
Get the contents of the Binary as a byte array.
Declaration
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
byte[] | A byte array with the contents of this Binary. |
Remarks
This is the equivalent of
ToByteArray(0, Length)
.
ToByteArray(int, int)
Get a portion of the contents of the Binary as a byte array.
Declaration
public byte[] ToByteArray(int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
int | of | The beginning index, inclusive. |
int | cb | The number of bytes to include in the resulting byte array. |
Returns
Type | Description |
---|---|
byte[] | A byte array containing the specified portion of this Binary. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If is larger than the length of this Binary.
|
ToString()
Return a human-readable description for this Binary.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string description of the object. |
Overrides
ToString(byte[])
For debugging purposes, convert the passed byte array into a string that contains the information regarding whether the reference is null, and if it is not null, what the length of the byte array is.
Declaration
public static string ToString(byte[] ab)
Parameters
Type | Name | Description |
---|---|---|
byte[] | ab | a byte array; may be null |
Returns
Type | Description |
---|---|
string | a String; never null |
WriteTo(BinaryWriter)
Write the contents of the Binary object to a Stream.
Declaration
public void WriteTo(BinaryWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BinaryWriter | writer | A Stream to write to. |
WriteTo(BinaryWriter, int, int)
Write the contents of the Binary object to a BinaryWriter.
Declaration
public void WriteTo(BinaryWriter writer, int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
BinaryWriter | writer | A BinaryWriter to write to. |
int | of | Offset of the first byte to write. |
int | cb | The number of bytes to write. |
WriteTo(Stream)
Write the contents of the Binary object to a Stream.
Declaration
public void WriteTo(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | A Stream to write to. |
WriteTo(Stream, int, int)
Write the contents of the Binary object to a Stream.
Declaration
public void WriteTo(Stream stream, int of, int cb)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | A Stream to write to. |
int | of | Offset of the first byte to write. |
int | cb | The number of bytes to write. |