Package org.apache.derby.client.am
Class ClobLocatorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.derby.client.am.ClobLocatorInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
class ClobLocatorInputStream extends java.io.InputStreamAnInputStreamthat will use an locator to fetch the Clob value from the server.Closing a
ByteArrayInputStreamhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException.This
InputStreamimplementation 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 ClientClobclobThe Clob to be accessed.private ClientConnectionconnectionConnection used to read Clob from server.private longcurrentPosCurrent position in the underlying Clob.
-
Constructor Summary
Constructors Constructor Description ClobLocatorInputStream(ClientConnection connection, ClientClob clob)Create anInputStreamfor reading theClobvalue represented by the given locator basedClobobject.ClobLocatorInputStream(ClientConnection connection, ClientClob clob, long pos)Create anInputStreamfor reading theClobvalue represented by the given locator basedClobobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]getBytesFromString(java.lang.String str)Returns aBytearray from theStringpassed as Input.intread()intread(byte[] b, int off, int len)private byte[]readBytes(int len)Read the nextlenbytes of theClobvalue from the server.
-
-
-
Field Detail
-
connection
private final ClientConnection connection
Connection used to read Clob from server.
-
clob
private final ClientClob clob
The Clob to be accessed.
-
currentPos
private long currentPos
Current position in the underlying Clob. Clobs are indexed from 1
-
-
Constructor Detail
-
ClobLocatorInputStream
ClobLocatorInputStream(ClientConnection connection, ClientClob clob) throws SqlException
Create anInputStreamfor reading theClobvalue represented by the given locator basedClobobject.- Parameters:
connection- connection to be used to read theClobvalue from the serverclob-Clobobject that contains locator for theClobvalue on the server.- Throws:
SqlException
-
ClobLocatorInputStream
ClobLocatorInputStream(ClientConnection connection, ClientClob clob, long pos) throws SqlException
Create anInputStreamfor reading theClobvalue represented by the given locator basedClobobject.- Parameters:
connection- connection to be used to read theClobvalue from the serverclob-Clobobject that contains locator for theClobvalue on the server.pos- the position inside theClobfrom which the reading must begin.- Throws:
SqlException
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin 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:
readin classjava.io.InputStream- Throws:
java.io.IOException- See Also:
InputStream.read(byte[], int, int)
-
readBytes
private byte[] readBytes(int len) throws java.io.IOExceptionRead the nextlenbytes of theClobvalue 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.
-
getBytesFromString
private byte[] getBytesFromString(java.lang.String str)
Returns aBytearray from theStringpassed as Input.- Parameters:
str- the inputString.- Returns:
- The
Bytecorresponding to theStringthat was input.
-
-