com.amazon.carbonado.lob
Class ByteArrayBlob

java.lang.Object
  extended by com.amazon.carbonado.lob.AbstractBlob
      extended by com.amazon.carbonado.lob.ByteArrayBlob
All Implemented Interfaces:
Blob, Lob

public class ByteArrayBlob
extends AbstractBlob

Implementation of a Blob which is backed by a growable in-memory byte array.

Author:
Brian S O'Neill

Constructor Summary
ByteArrayBlob(byte[] data)
          Construct a ByteArrayBlob initially backed by the given byte array.
ByteArrayBlob(byte[] data, int length)
          Construct a ByteArrayBlob initially backed by the given byte array.
ByteArrayBlob(int capacity)
          Construct a ByteArrayBlob with the given initial capacity.
 
Method Summary
 long getLength()
          Returns the length of this Blob, in bytes.
 Object getLocator()
          Always returns null.
 InputStream openInputStream()
          Returns an InputStream for reading Blob data positioned at the start.
 InputStream openInputStream(long pos)
          Returns an InputStream for reading Blob data.
 InputStream openInputStream(long pos, int bufferSize)
          Returns an InputStream for reading Blob data.
 OutputStream openOutputStream()
          Returns an OutputStream for writing Blob data, positioned at the start.
 OutputStream openOutputStream(long pos)
          Returns an OutputStream for writing Blob data.
 OutputStream openOutputStream(long pos, int bufferSize)
          Returns an OutputStream for writing Blob data.
 void setLength(long length)
          Set the length of this Blob, in bytes.
 
Methods inherited from class com.amazon.carbonado.lob.AbstractBlob
asString, asString, asString, equals, hashCode, setValue, setValue, setValue, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteArrayBlob

public ByteArrayBlob(int capacity)
Construct a ByteArrayBlob with the given initial capacity.

Parameters:
capacity - initial capacity of internal byte array

ByteArrayBlob

public ByteArrayBlob(byte[] data)
Construct a ByteArrayBlob initially backed by the given byte array. The byte array is not cloned until this ByteArrayBlob grows or shrinks.

Parameters:
data - initial data backing the Blob

ByteArrayBlob

public ByteArrayBlob(byte[] data,
                     int length)
Construct a ByteArrayBlob initially backed by the given byte array. The byte array is not cloned until this ByteArrayBlob grows or shrinks.

Parameters:
data - initial data backing the Blob
length - initial length of data
Method Detail

openInputStream

public InputStream openInputStream()
Description copied from interface: Blob
Returns an InputStream for reading Blob data positioned at the start. The Blob implementation selects an appropriate buffer size for the stream.

Returns:
InputStream for this Blob, which is not guaranteed to be thread-safe

openInputStream

public InputStream openInputStream(long pos)
Description copied from interface: Blob
Returns an InputStream for reading Blob data. The Blob implementation selects an appropriate buffer size for the stream.

Parameters:
pos - desired zero-based position to read from
Returns:
InputStream for this Blob, which is not guaranteed to be thread-safe

openInputStream

public InputStream openInputStream(long pos,
                                   int bufferSize)
Description copied from interface: Blob
Returns an InputStream for reading Blob data. A suggested buffer size must be provided, but it might be ignored by the Blob implementation.

Parameters:
pos - desired zero-based position to read from
bufferSize - suggest that the input stream buffer be at least this large (in bytes)
Returns:
InputStream for this Blob, which is not guaranteed to be thread-safe

getLength

public long getLength()
Description copied from interface: Blob
Returns the length of this Blob, in bytes.


openOutputStream

public OutputStream openOutputStream()
Description copied from interface: Blob
Returns an OutputStream for writing Blob data, positioned at the start. The Blob implementation selects an appropriate buffer size for the stream.

Returns:
OutputStream for this Blob, which is not guaranteed to be thread-safe

openOutputStream

public OutputStream openOutputStream(long pos)
Description copied from interface: Blob
Returns an OutputStream for writing Blob data. The Blob implementation selects an appropriate buffer size for the stream.

Parameters:
pos - desired zero-based position to write to
Returns:
OutputStream for this Blob, which is not guaranteed to be thread-safe

openOutputStream

public OutputStream openOutputStream(long pos,
                                     int bufferSize)
Description copied from interface: Blob
Returns an OutputStream for writing Blob data. A suggested buffer size must be provided, but it might be ignored by the Blob implementation.

Parameters:
pos - desired zero-based position to write to
bufferSize - suggest that the output stream buffer be at least this large (in bytes)
Returns:
OutputStream for this Blob, which is not guaranteed to be thread-safe

setLength

public void setLength(long length)
               throws PersistException
Description copied from interface: Blob
Set the length of this Blob, in bytes. If the new length is shorter, the Blob is truncated. If the new length is longer, the Blob is padded with zeros.

Parameters:
length - new length to set to
Throws:
PersistDeniedException - if Blob is read-only
PersistException

getLocator

public Object getLocator()
Always returns null.



Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.