|
Oracle® Coherence Java API Reference Release 3.7.0.0 E18683-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.tangosol.util.Base
com.tangosol.io.AbstractReadBuffer
com.tangosol.io.AbstractByteArrayReadBuffer
com.tangosol.util.Binary
public final class Binary
A thread-safe immutable binary object.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.tangosol.io.AbstractByteArrayReadBuffer |
---|
AbstractByteArrayReadBuffer.ByteArrayBufferInput |
Nested classes/interfaces inherited from class com.tangosol.io.AbstractReadBuffer |
---|
AbstractReadBuffer.AbstractBufferInput |
Nested classes/interfaces inherited from interface com.tangosol.io.ReadBuffer |
---|
ReadBuffer.BufferInput |
Field Summary |
---|
Fields inherited from class com.tangosol.io.AbstractByteArrayReadBuffer |
---|
m_ab, m_cb, m_of |
Fields inherited from class com.tangosol.io.AbstractReadBuffer |
---|
NO_BINARY, NO_BYTES |
Constructor Summary | |
---|---|
Binary() Default constructor for a binary object. |
|
Binary(Binary that) Construct a Binary object from a Binary object. |
|
Binary(byte[] ab) Construct a binary object from a byte array. |
|
Binary(byte[] ab, int of, int cb) Construct a binary object from a portion of a byte array. |
|
Binary(java.io.ByteArrayOutputStream stream) Construct a Binary object from the contents of a ByteArrayOutputStream. |
|
Binary(java.io.DataInput stream) Construct a binary object from a DataInput interface. |
Method Summary | |
---|---|
int |
calculateNaturalPartition(int cPartitions) Calculate the partition ID to which the specified Binary should be naturally assigned. |
java.lang.Object |
clone() Create a clone of this Binary object. |
static byte[] |
clone(byte[] ab, int of, int cb) Create a clone of the specified binary region. |
int |
compareTo(java.lang.Object o) Compares this object with the specified object for order. |
Binary |
concat(Binary bin) Concatenate the passed Binary onto this Binary. |
boolean |
endsWith(Binary bin) Tests if this Binary object ends with the specified suffix. |
static boolean |
equals(byte[] ab1, int of1, byte[] ab2, int of2, int cb) Compare two binary regions, testing for equality. |
boolean |
equals(java.lang.Object o) Compares this Binary object with another object for equality. |
java.io.InputStream |
getInputStream() Get an InputStream to read the Binary object's contents from. |
int |
hashCode() Returns a hash code value for the object. |
int |
indexOf(Binary bin) Returns the offset within this Binary object of the first occurrence of the specified Binary. |
int |
indexOf(Binary bin, int ofFrom) Returns the offset within this Binary object of the first occurrence of the specified Binary, starting the search at the specified offset. |
int |
indexOf(byte b) Returns the offset within this Binary object of the first occurrence of the specified byte. |
int |
indexOf(byte b, int ofFrom) Returns the offset within this Binary object of the first occurrence of the specified byte, starting the search at the specified offset. |
protected ReadBuffer |
instantiateReadBuffer(int of, int cb) Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer. |
protected boolean |
isByteArrayPrivate() Determine if the underlying byte[] should be treated as private data. |
int |
lastIndexOf(Binary bin) Returns the offset within this Binary object of the last occurrence of the specified Binary. |
int |
lastIndexOf(Binary bin, int ofFrom) Returns the offset within this Binary object of the last occurrence of the specified Binary, starting the search at the specified offset. |
int |
lastIndexOf(byte b) Returns the offset within this Binary object of the last occurrence of the specified byte. |
int |
lastIndexOf(byte b, int ofFrom) Returns the offset within this Binary object of the last occurrence of the specified byte, starting the search at the specified offset and searching backwards. |
static int |
memchr(byte[] abHaystack, int ofHaystack, int cbHaystack, byte bNeedle) Find the specified byte (a "needle") in the specified binary region ("the haystack"). |
static int |
memchr(byte[] abHaystack, int ofHaystack, int cbHaystack, byte bNeedle, boolean fBackwards) Find the specified byte (a "needle") in the specified binary region ("the haystack"). |
static int |
memcmp(byte[] ab1, int of1, int cb1, byte[] ab2, int of2, int cb2) Compare two binary regions. |
static void |
memcpy(byte[] abSrc, int ofSrc, byte[] abDest, int ofDest, int cbCopy) Copy binary data from one binary region to another. |
static int |
memmem(byte[] abHaystack, int ofHaystack, int cbHaystack, byte[] abNeedle, int ofNeedle, int cbNeedle) Find the second binary region (a "needle") in the first binary region ("the haystack"). |
static int |
memmem(byte[] abHaystack, int ofHaystack, int cbHaystack, byte[] abNeedle, int ofNeedle, int cbNeedle, boolean fBackwards) Find the second binary region (a "needle") in the first binary region ("the haystack"). |
static Binary |
readBinary(java.nio.channels.FileChannel channel, long of, int cb, byte[] ab2) Read a Binary of the specified length at the specified offset from the specified FileChannel. |
void |
readExternal(java.io.DataInput in) Restore the contents of this object by loading the object's state from the passed DataInput object. |
void |
readExternal(java.io.ObjectInput in) The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. |
boolean |
regionMatches(int ofThis, Binary that, int ofThat, int cb) Tests if two Binary regions are equal. |
Binary |
replace(Binary binOld, Binary binNew) Replace all occurrences of one specified Binary with another in this Binary object. |
Binary |
replace(byte bOld, byte bNew) Replace all occurrences of one specified byte with another in this Binary object. |
Binary |
replaceRegion(int of, int cb, Binary binNew) Replace a region within this Binary with another Binary. |
Binary |
reverse() Reverse this Binary object's byte sequence such that the byte at offset zero of this sequence occurs at offset length()-1 in the resulting sequence, the byte at offset one of this sequence occurs at offset length()-2 in the resulting sequence, and so on. |
boolean |
startsWith(Binary bin) Tests if this Binary object starts with the specified prefix. |
boolean |
startsWith(Binary bin, int ofFrom) Tests if this Binary object starts with the specified prefix beginning a specified offset. |
Binary |
toBinary() Returns a new Binary object that holds the complete contents of this ReadBuffer. |
Binary |
toBinary(int of, int cb) Returns a Binary object that holds the specified portion of this ReadBuffer. |
java.lang.String |
toString() Provide a human-readable representation of the Binary object. |
static java.lang.String |
toString(byte[] ab) 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. |
void |
writeExternal(java.io.DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object. |
void |
writeExternal(java.io.ObjectOutput out) The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays. |
void |
writeTo(java.nio.ByteBuffer buf) Write the contents of the Binary object to a ByteBuffer. |
void |
writeTo(java.nio.ByteBuffer buf, int of, int cb) Write the contents of the Binary object to a ByteBuffer. |
void |
writeTo(java.io.DataOutput out) Write the contents of the Binary object to a DataOutput. |
void |
writeTo(java.io.DataOutput out, int of, int cb) Write the contents of the Binary object to a DataOutput. |
void |
writeTo(java.io.OutputStream out) Write the contents of the Binary object to an OutputStream. |
void |
writeTo(java.io.OutputStream out, int of, int cb) Write the contents of the Binary object to an OutputStream. |
Methods inherited from class com.tangosol.io.AbstractByteArrayReadBuffer |
---|
byteAt, copyBytes, instantiateBufferInput, length, resetRange, toByteArray |
Methods inherited from class com.tangosol.io.AbstractReadBuffer |
---|
checkBounds, getBufferInput, getReadBuffer, subSequence, toByteArray |
Constructor Detail |
---|
public Binary()
public Binary(byte[] ab)
ab
- an array of bytespublic Binary(byte[] ab, int of, int cb)
ab
- an array of bytesof
- the offset into the byte arraycb
- the number of bytes to extractpublic Binary(Binary that)
that
- another Binary objectString.String(String)
public Binary(java.io.ByteArrayOutputStream stream)
stream
- the ByteArrayOutputStream that holds the value that this Binary object will representpublic Binary(java.io.DataInput stream) throws java.io.IOException
stream
- the object implementing DataInput from which this Binary object will load its datajava.io.IOException
- if an I/O error occurs reading the BinaryMethod Detail |
---|
public boolean regionMatches(int ofThis, Binary that, int ofThat, int cb)
ofThis
- the starting offset of the subregion in this Binary objectthat
- the Binary object containing the subregion to compare toofThat
- the starting offset of the subregion in the passed Binary object that
cb
- the number of bytes to comparetrue
if the specified subregion of this Binary object exactly matches the specified subregion of the that
Binary object; false
otherwisejava.lang.NullPointerException
- if that
is null
String.regionMatches(int, java.lang.String, int, int)
public boolean startsWith(Binary bin, int ofFrom)
bin
- the prefixofFrom
- the offset to begin looking in this Binary objecttrue
if the byte sequence represented by the bin
argument is a prefix of the substring of this Binary object starting at offset ofFrom
; false
otherwisejava.lang.NullPointerException
- if bin
is null
.String.startsWith(java.lang.String, int)
public boolean startsWith(Binary bin)
bin
- the prefixtrue
if the byte sequence represented by the bin
argument is a prefix of this Binary object; false
otherwisejava.lang.NullPointerException
- if bin
is null
.String.startsWith(java.lang.String, int)
public boolean endsWith(Binary bin)
bin
- the suffixtrue
if the byte sequence represented by the bin
argument is a suffix of this Binary object; false
otherwisejava.lang.NullPointerException
- if bin
is null
.String.endsWith(java.lang.String)
public int indexOf(byte b)
This method is identical in its functionality to the corresponding method in String.
b
- the byte to search for-1
if the byte does not occur in the sequenceString.indexOf(int)
public int indexOf(byte b, int ofFrom)
This method is identical in its functionality to the corresponding method in String.
b
- the byte to search forofFrom
- the offset to search fromofFrom
, or -1
if the byte does not occur from that offset to the end of the sequenceString.indexOf(int, int)
public int indexOf(Binary bin)
This method is identical in its functionality to the corresponding method in String.
bin
- the Binary to search for-1
if the byte sequence does not occurString.indexOf(String)
public int indexOf(Binary bin, int ofFrom)
This method is identical in its functionality to the corresponding method in String. Note that one side-effect of maintaining compatibility with the String behavior is that zero-length Strings can be found even when the from-index is out-of-bounds. Given any Binary value "value" and a zero-length binary value "empty", the following will always hold true:
int rnd = new Random().nextInt(Integer.MAX_VALUE - value.length()); assert value.indexOf(empty, value.length() + rnd) == value.length();
bin
- the Binary to search forofFrom
- the offset to search fromofFrom
, or -1
if the byte sequence does not occur from that offset to the end of this BinaryString.indexOf(String, int)
public int lastIndexOf(byte b)
This method is identical in its functionality to the corresponding method in String.
b
- the byte to search for-1
if the byte does not occur in the sequenceString.lastIndexOf(int)
public int lastIndexOf(byte b, int ofFrom)
This method is identical in its functionality to the corresponding method in String.
b
- the byte to search forofFrom
- the offset to search backwards from (inclusive)ofFrom
, or -1
if the byte does not occur from that offset to the start of the sequenceString.lastIndexOf(int, int)
public int lastIndexOf(Binary bin)
This method is identical in its functionality to the corresponding method in String.
bin
- the Binary to search for-1
if the byte sequence does not occurString.lastIndexOf(String)
public int lastIndexOf(Binary bin, int ofFrom)
This method is identical in its functionality to the corresponding method in String.
bin
- the Binary to search forofFrom
- the offset to search fromofFrom
, or -1
if the byte sequence does not occur from that offset to the beginning of this BinaryString.lastIndexOf(String, int)
public Binary replace(byte bOld, byte bNew)
bOld
- the byte value to replacebNew
- the byte value to replace bOld withpublic Binary replace(Binary binOld, Binary binNew)
binOld
- the Binary value to replacebinNew
- the Binary value to replace binOld withpublic Binary replaceRegion(int of, int cb, Binary binNew)
This method does not alter the state of this Binary; it creates a new Binary instance instead.
of
- the offset of the range to replace within this Binarycb
- the length of the range to replace in bytesbinNew
- the Binary value to replace the range withpublic Binary concat(Binary bin)
bin
- the Binary to concatenate to this Binarypublic Binary reverse()
public Binary toBinary()
This is the equivalent of toBinary(0, length())
.
toBinary
in interface ReadBuffer
toBinary
in interface ByteSequence
toBinary
in class AbstractByteArrayReadBuffer
public Binary toBinary(int of, int cb)
This is the equivalent of getReadBuffer(of, cb).toBinary()
.
toBinary
in interface ReadBuffer
toBinary
in class AbstractByteArrayReadBuffer
of
- the beginning index, inclusivecb
- the number of bytes to include in the Binary objectprotected ReadBuffer instantiateReadBuffer(int of, int cb)
instantiateReadBuffer
in class AbstractReadBuffer
of
- the beginning index, inclusivecb
- the number of bytes to include in the resulting ReadBufferprotected boolean isByteArrayPrivate()
isByteArrayPrivate
in class AbstractByteArrayReadBuffer
public java.lang.Object clone()
clone
in interface ReadBuffer
clone
in class AbstractReadBuffer
public java.lang.String toString()
public int hashCode()
The Binary object uses a CRC32 algorithm to determine the hash code.
Base.toCrc(byte[], int, int)
public boolean equals(java.lang.Object o)
equals
in interface ReadBuffer
equals
in class AbstractByteArrayReadBuffer
o
- an object reference or nullpublic int calculateNaturalPartition(int cPartitions)
The resulting partition ID will be in the range [0..cPartitions).
cPartitions
- the partition countpublic int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- the Object to be compared.java.lang.ClassCastException
- if the specified object's type prevents it from being compared to this Objectjava.lang.NullPointerException
- if the specified object is null
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
in
- the stream to read data from in order to restore the objectjava.io.IOException
- if an I/O exception occurspublic void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- the stream to write the object tojava.io.IOException
- if an I/O exception occurspublic void readExternal(java.io.DataInput in) throws java.io.IOException
readExternal
in interface ExternalizableLite
in
- the DataInput stream to read data from in order to restore the state of this objectjava.io.IOException
- if an I/O exception occursjava.io.NotActiveException
- if the object is not in its initial state, and therefore cannot be deserialized intopublic void writeExternal(java.io.DataOutput out) throws java.io.IOException
writeExternal
in interface ExternalizableLite
out
- the DataOutput stream to write the state of this object tojava.io.IOException
- if an I/O exception occurspublic java.io.InputStream getInputStream()
public void writeTo(java.io.OutputStream out) throws java.io.IOException
out
- an OutputStream to write tojava.io.IOException
- if an I/O exception occurspublic void writeTo(java.io.OutputStream out, int of, int cb) throws java.io.IOException
out
- an OutputStream to write toof
- the beginning index, inclusivecb
- the number of bytes to write to an OutputStreamjava.io.IOException
- if an I/O exception occurspublic void writeTo(java.io.DataOutput out) throws java.io.IOException
out
- a DataOutput to write tojava.io.IOException
- if an I/O exception occurspublic void writeTo(java.io.DataOutput out, int of, int cb) throws java.io.IOException
out
- a DataOutput to write toof
- the beginning index, inclusivecb
- the number of bytes to write to a DataOutputjava.io.IOException
- if an I/O exception occurspublic void writeTo(java.nio.ByteBuffer buf)
buf
- a ByteBuffer to write topublic void writeTo(java.nio.ByteBuffer buf, int of, int cb) throws java.io.IOException
buf
- an ByteBuffer to write toof
- the beginning index, inclusivecb
- the number of bytes to write to a ByteBufferjava.io.IOException
- if an I/O exception occurspublic static Binary readBinary(java.nio.channels.FileChannel channel, long of, int cb, byte[] ab2) throws java.io.IOException
channel
- the FileChannel to read fromof
- the offset within the FileChannel to read fromcb
- the number of bytes to read from the FileChannel, which will be the length of the Binaryab2
- reserved; pass in nulljava.io.IOException
- if an I/O exception or unexpected EOF occurspublic static int memchr(byte[] abHaystack, int ofHaystack, int cbHaystack, byte bNeedle)
abHaystack
- the byte array containing the binary region to search within (the "haystack")ofHaystack
- the offset of the binary region within abHaystackcbHaystack
- the size in bytes of the binary region within abHaystackbNeedle
- the byte to search for (a "needle")public static int memchr(byte[] abHaystack, int ofHaystack, int cbHaystack, byte bNeedle, boolean fBackwards)
abHaystack
- the byte array containing the binary region to search within (the "haystack")ofHaystack
- the offset of the binary region within abHaystackcbHaystack
- the size in bytes of the binary region within abHaystackbNeedle
- the byte to search for (a "needle")fBackwards
- pass false to find the first occurrance, or true to find the last occurrencepublic static int memmem(byte[] abHaystack, int ofHaystack, int cbHaystack, byte[] abNeedle, int ofNeedle, int cbNeedle)
abHaystack
- the byte array containing the binary region to search within (the "haystack")ofHaystack
- the offset of the binary region within abHaystackcbHaystack
- the size in bytes of the binary region within abHaystackabNeedle
- the byte array containing the binary region to search for (a "needle")ofNeedle
- the offset of the binary region within abNeedlecbNeedle
- the size in bytes of the binary region within abNeedlepublic static int memmem(byte[] abHaystack, int ofHaystack, int cbHaystack, byte[] abNeedle, int ofNeedle, int cbNeedle, boolean fBackwards)
abHaystack
- the byte array containing the binary region to search within (the "haystack")ofHaystack
- the offset of the binary region within abHaystackcbHaystack
- the size in bytes of the binary region within abHaystackabNeedle
- the byte array containing the binary region to search for (a "needle")ofNeedle
- the offset of the binary region within abNeedlecbNeedle
- the size in bytes of the binary region within abNeedlefBackwards
- pass false to find the first occurrance, or true to find the last occurrencepublic static int memcmp(byte[] ab1, int of1, int cb1, byte[] ab2, int of2, int cb2)
ab1
- the byte array containing the first binary region to compareof1
- the offset of the binary region within ab1cb1
- the size in bytes of the binary region within ab1ab2
- the byte array containing the second binary region to compareof2
- the offset of the binary region within ab2cb2
- the size in bytes of the binary region within ab2public static void memcpy(byte[] abSrc, int ofSrc, byte[] abDest, int ofDest, int cbCopy)
abSrc
- the byte array containing the binary region to copy fromofSrc
- the offset of the binary region within abSrcabDest
- the byte array containing the binary region to copy toofDest
- the offset of the binary region within abDestcbCopy
- the size in bytes of the binary region to copypublic static boolean equals(byte[] ab1, int of1, byte[] ab2, int of2, int cb)
ab1
- the byte array containing the first binary region to compareof1
- the offset of the binary region within ab1ab2
- the byte array containing the second binary region to compareof2
- the offset of the binary region within ab2cb
- the size of the binary regions, which is the number of bytes to comparepublic static byte[] clone(byte[] ab, int of, int cb)
ab
- the byte array containing the binary region to copy fromof
- the offset of the binary region within abcb
- the size in bytes of the binary region to copypublic static java.lang.String toString(byte[] ab)
ab
- a byte array; may be null
|
Oracle® Coherence Java API Reference Release 3.7.0.0 E18683-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |