Package org.apache.derby.client.am
Class BlobLocatorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.derby.client.am.BlobLocatorInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
class BlobLocatorInputStream extends java.io.InputStream
AnInputStream
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 anIOException
.This
InputStream
implementation is pretty basic. No buffering of data is done. Hence, for efficiency #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
Fields Modifier and Type Field Description private ClientBlob
blob
The Blob to be accessed.private ClientConnection
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
Constructors Constructor Description BlobLocatorInputStream(ClientConnection connection, ClientBlob blob)
Create anInputStream
for reading theBlob
value represented by the given locator basedBlob
object.BlobLocatorInputStream(ClientConnection connection, ClientBlob blob, long position, long length)
Create anInputStream
for reading theBlob
value represented by the given locator basedBlob
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
read()
int
read(byte[] b, int off, int len)
private byte[]
readBytes(int len)
Read the nextlen
bytes of theBlob
value from the server.
-
-
-
Field Detail
-
connection
private final ClientConnection connection
Connection used to read Blob from server.
-
blob
private final ClientBlob 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
BlobLocatorInputStream(ClientConnection connection, ClientBlob blob) throws SqlException
Create anInputStream
for reading theBlob
value represented by the given locator basedBlob
object.- Parameters:
connection
- connection to be used to read theBlob
value from the serverblob
-Blob
object that contains locator for theBlob
value on the server.- Throws:
SqlException
- if an error occurs when obtaining the length of theBlob
.
-
BlobLocatorInputStream
BlobLocatorInputStream(ClientConnection connection, ClientBlob blob, long position, long length) throws SqlException
Create anInputStream
for reading theBlob
value represented by the given locator basedBlob
object.- Parameters:
connection
- connection to be used to read theBlob
value from the serverblob
-Blob
object that contains locator for theBlob
value on the server.position
- the position in theBlob
of the first byte to read.length
- the maximum number of bytes to read from theBlob
.- Throws:
SqlException
- if an error occurs when obtaining the length of theBlob
.
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.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 classjava.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 nextlen
bytes of theBlob
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.
-
-