com.orientechnologies.jdo.types
Class oBinary

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.ByteArrayOutputStream
          extended bycom.orientechnologies.jdo.types.oBinary
All Implemented Interfaces:
java.io.Serializable

public class oBinary
extends java.io.ByteArrayOutputStream
implements java.io.Serializable

Handles binary stream. It works like BLOB type in Relational DBMS.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
oBinary()
          Create a new object.
oBinary(byte[] iData)
          Create a new object with value iData.
oBinary(int iStartSize)
          Create a new object preallocating iStartSize bytes to optimize performances avoiding unnecessary reallocations.
 
Method Summary
 void append(byte[] iData, int iLength)
          Append a byte array to the stream
 void append(oBinary iSource)
          Append another oBinary content in current stream
 void append(java.lang.String iData)
          Append a string to the stream
static void copy(byte[] iDest, byte[] iSource, int iDestOffset, int iSourceOffset, int iSize)
          Static method to copy portion of byte arrays using fast-optimized JVM System.arraycopy() method.
 void get(byte[] ioData, int iStart, int iLength)
          Get a portion of binary stream starting from iStart byte with length iLength.
 byte[] getBuffer()
          Return internal stream buffer as byte array object.
static void move(byte[] iDest, byte[] iSource, int iDestOffset, int iSourceOffset, int iSize)
          Static method to move portion of byte arrays.
 void reserve(int iSize)
          Reserve space in stream to optimize further enlargements.
 void reset()
          Reset the binary content
 void set(byte[] iData, int iStart, int iLength)
          Set a portion of binary stream starting from iStart byte with length iLength.
 int size()
          Get length of binary stream
 byte[] toByteArray()
          Copy internal stream content in a new byte array allocated with stream length.
 java.lang.String toString()
          Convert the binary stream to a string.
 java.lang.String toStringByte()
          Convert the binary stream to a string.
 void write(byte[] iData, int iStart, int iLength)
          Append a binary array to the stream
 void write(int iData)
          Append a byte (as int value) to the stream
 
Methods inherited from class java.io.ByteArrayOutputStream
close, toString, toString, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

oBinary

public oBinary()
Create a new object. Default size of internal buffer is 256 bytes and further allocation steps are of 64 bytes each time.


oBinary

public oBinary(byte[] iData)
Create a new object with value iData.


oBinary

public oBinary(int iStartSize)
Create a new object preallocating iStartSize bytes to optimize performances avoiding unnecessary reallocations.

Method Detail

reset

public void reset()
Reset the binary content


get

public void get(byte[] ioData,
                int iStart,
                int iLength)
Get a portion of binary stream starting from iStart byte with length iLength.

Parameters:
ioData - Byte array to copy portion of stream. Byte array must be allocated with enought space (at least iLength) before the call.
iStart - Start address in the stream to copy
iLength - Number of bytes to copy

set

public void set(byte[] iData,
                int iStart,
                int iLength)
Set a portion of binary stream starting from iStart byte with length iLength.

Parameters:
iStart - Start address in the stream to copy
iLength - Number of bytes to copy

write

public void write(int iData)
Append a byte (as int value) to the stream

Parameters:
iData - int value to copy. Will be casted to byte internally

write

public void write(byte[] iData,
                  int iStart,
                  int iLength)
Append a binary array to the stream

Parameters:
iData - Byte Array to copy
iStart - Start address in the byte array iData
iLength - Number of bytes to copy

append

public void append(java.lang.String iData)
Append a string to the stream

Parameters:
iData - String to copy

append

public void append(byte[] iData,
                   int iLength)
Append a byte array to the stream

Parameters:
iData - Byte Array to copy
iLength - Number of bytes to copy

append

public void append(oBinary iSource)
Append another oBinary content in current stream

Parameters:
iSource - Source oBinary object to copy

reserve

public void reserve(int iSize)
Reserve space in stream to optimize further enlargements.

Parameters:
iSize - Number of bytes to allocates. If iSize is minor or equals to the current stream size, then reservation is ignored

getBuffer

public byte[] getBuffer()
Return internal stream buffer as byte array object.

Returns:
Internal byte array

toStringByte

public java.lang.String toStringByte()
Convert the binary stream to a string. Values from '0' to 'z' are not converted. Instead other values are exported as sequence of {} whereas is the byte number in current ASCII/UNICODE representation.

Returns:
String with byte array content in readable mode

toString

public java.lang.String toString()
Convert the binary stream to a string. All values are exported as sequence of separated by comma. Each is a number in current ASCII/UNICODE representation.

Returns:
String with byte array content in readable mode, separated by comma

toByteArray

public byte[] toByteArray()
Copy internal stream content in a new byte array allocated with stream length.

Use getBuffer() method if you want to access to the internal buffer avoiding byte copying.

Returns:
Byte Array with the copy of stream content
See Also:
getBuffer()

size

public int size()
Get length of binary stream

Returns:
Number of bytes of binary stream content

copy

public static void copy(byte[] iDest,
                        byte[] iSource,
                        int iDestOffset,
                        int iSourceOffset,
                        int iSize)
Static method to copy portion of byte arrays using fast-optimized JVM System.arraycopy() method.

Parameters:
iDest - Destination byte array where to copy in
iSource - Source byte array to copy
iDestOffset - Destination offset where start to copy in
iSourceOffset - Source offset where start to copy
iSize - Number of bytes to copy
See Also:
move(byte[], byte[], int, int, int)

move

public static void move(byte[] iDest,
                        byte[] iSource,
                        int iDestOffset,
                        int iSourceOffset,
                        int iSize)
Static method to move portion of byte arrays. As difference from copy() method, it allows moving bytes in the same array without conflict. If iDest destination array and iSource source array are the same, then a temporary buffer is used to avoid overide, otherwise the behaviour is the same of copy() method.

Parameters:
iDest - Destination byte array where to move in
iSource - Source byte array to move
iDestOffset - Destination offset where start to move in
iSourceOffset - Source offset where start to move
iSize - Number of bytes to move
See Also:
copy(byte[], byte[], int, int, int)