org.apache.derby.client.am
Class BlobLocatorInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.apache.derby.client.am.BlobLocatorInputStream
All Implemented Interfaces:
java.io.Closeable

public class BlobLocatorInputStream
extends java.io.InputStream

An InputStream that will use an locator to fetch the Blob value from the server.

Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

This InputStream implementation is pretty basic. No buffering of data is done. Hence, for efficieny #read(byte[]) should be used instead of #read(). Marks are not supported, but it should be pretty simple to extend the implementation to support this. A more efficient skip implementation should also be straight-forward.


Field Summary
private  Blob blob
          The Blob to be accessed.
private  Connection connection
          Connection used to read Blob from server.
private  long currentPos
          Current position in the underlying Blob.
private  long maxPos
          Position in Blob where to stop reading.
 
Constructor Summary
BlobLocatorInputStream(Connection connection, Blob blob)
          Create an InputStream for reading the Blob value represented by the given locator based Blob object.
BlobLocatorInputStream(Connection connection, Blob blob, long position, long length)
          Create an InputStream for reading the Blob value represented by the given locator based Blob object.
 
Method Summary
 int read()
           
 int read(byte[] b, int off, int len)
           
private  byte[] readBytes(int len)
          Read the next len bytes of the Blob value from the server.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

private final Connection connection
Connection used to read Blob from server.


blob

private final Blob blob
The Blob to be accessed.


currentPos

private long currentPos
Current position in the underlying Blob. Blobs are indexed from 1


maxPos

private final long maxPos
Position in Blob where to stop reading. maxPos starts counting from 1.

Constructor Detail

BlobLocatorInputStream

public BlobLocatorInputStream(Connection connection,
                              Blob blob)
                       throws SqlException
Create an InputStream for reading the Blob value represented by the given locator based Blob object.

Parameters:
connection - connection to be used to read the Blob value from the server
blob - Blob object that contains locator for the Blob value on the server.
Throws:
SqlException - if an error occurs when obtaining the length of the Blob.

BlobLocatorInputStream

public BlobLocatorInputStream(Connection connection,
                              Blob blob,
                              long position,
                              long length)
                       throws SqlException
Create an InputStream for reading the Blob value represented by the given locator based Blob object.

Parameters:
connection - connection to be used to read the Blob value from the server
blob - Blob object that contains locator for the Blob value on the server.
position - the position in the Blob of the first byte to read.
length - the maximum number of bytes to read from the Blob.
Throws:
SqlException - if an error occurs when obtaining the length of the Blob.
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException
See Also:
This method fetches one byte at a time from the server. For more efficient retrieval, use #read(byte[]).

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException
See Also:
InputStream.read(byte[], int, int)

readBytes

private byte[] readBytes(int len)
                  throws java.io.IOException
Read the next len bytes of the Blob value from the server.

Parameters:
len - number of bytes to read
Returns:
byte[] containing the read bytes
Throws:
java.io.IOException - Wrapped SqlException if reading from server fails.

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.