|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.jdbc.LOBStreamControl
class LOBStreamControl
This class acts as a layer of blob/clob repository (in memory or file). The max bytes of data stored in memory depends on the way this class is created. If the class is created with initial data, the buffer size is set to the size of the byte array supplied. If no initial data is supplied or if the initial data size is less than DEFAULT_MAX_BUF_SIZE, The buffer size is set to DEFAULT_MAX_BUF_SIZE. When write increases the data beyond this value a temporary file is created and data is moved into that. If truncate reduces the size of the file below initial buffer size (max of DEFAULT_MAX_BUF_SIZE and initial byte array size) the data moved into memory. This class also creates InputStream and OutputStream which can be used to access blob data irrespective of if its in memory or in file.
Field Summary | |
---|---|
private int |
bufferSize
|
private EmbedConnection |
conn
|
private byte[] |
dataBytes
|
private static int |
DEFAULT_MAX_BUF_SIZE
|
private boolean |
isBytes
|
private LOBFile |
tmpFile
|
private long |
updateCount
|
Constructor Summary | |
---|---|
LOBStreamControl(EmbedConnection conn)
Creates an empty LOBStreamControl. |
|
LOBStreamControl(EmbedConnection conn,
byte[] data)
Creates a LOBStreamControl and initializes with a bytes array. |
Method Summary | |
---|---|
(package private) void |
copyData(java.io.InputStream inStream,
long length)
Copies bytes from stream to local storage. |
(package private) long |
copyUtf8Data(java.io.InputStream utf8Stream,
long charLength)
Copies UTF-8 encoded chars from a stream to local storage. |
private void |
deleteFile(StorageFile file)
|
protected void |
finalize()
|
(package private) void |
free()
Invalidates all the variables and closes file handle if open. |
(package private) java.io.InputStream |
getInputStream(long pos)
returns input stream linked with this object. |
(package private) long |
getLength()
Returns length of data. |
(package private) java.io.OutputStream |
getOutputStream(long pos)
returns output stream linked with this object |
(package private) long |
getUpdateCount()
Returns the running secquence number to check if the lob is updated since last access. |
private void |
init(byte[] b,
long len)
|
private void |
isValidOffset(int off,
int length)
|
private void |
isValidPostion(long pos)
|
(package private) int |
read(byte[] buff,
int off,
int len,
long pos)
Reads bytes starting from 'position' into bytes array. |
(package private) int |
read(long pos)
Reads one byte. |
private int |
readBytes(byte[] b,
int off,
int len,
long pos)
|
private void |
releaseTempFile(LOBFile file)
Close and release all resources held by a temporary file. |
(package private) long |
replaceBytes(byte[] buf,
long stPos,
long endPos)
Replaces a block of bytes in the middle of the LOB with a another block of bytes, which may be of a different size. |
(package private) void |
truncate(long size)
Resets the size. |
private long |
updateData(byte[] bytes,
int offset,
int len,
long pos)
|
(package private) long |
write(byte[] b,
int off,
int len,
long pos)
Writes len bytes from the specified byte array to the LOB. |
(package private) long |
write(int b,
long pos)
Writes one byte. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private LOBFile tmpFile
private byte[] dataBytes
private boolean isBytes
private final int bufferSize
private final EmbedConnection conn
private long updateCount
private static final int DEFAULT_MAX_BUF_SIZE
Constructor Detail |
---|
LOBStreamControl(EmbedConnection conn)
conn
- Connection for this lobLOBStreamControl(EmbedConnection conn, byte[] data) throws java.io.IOException, StandardException
conn
- Connection for this lobdata
- initial value
java.io.IOException
StandardException
Method Detail |
---|
private void init(byte[] b, long len) throws java.io.IOException, StandardException
java.io.IOException
StandardException
private long updateData(byte[] bytes, int offset, int len, long pos) throws StandardException
StandardException
private void isValidPostion(long pos) throws java.io.IOException, StandardException
java.io.IOException
StandardException
private void isValidOffset(int off, int length) throws StandardException
StandardException
long write(int b, long pos) throws java.io.IOException, StandardException
b
- bytepos
-
IOException,
- StandardException
java.io.IOException
StandardException
long write(byte[] b, int off, int len, long pos) throws java.io.IOException, StandardException
len
bytes from the specified byte array to the LOB.
b
- byte arrayoff
- offset from where to read from the byte arraylen
- number of bytes to be writtenpos
- starting position
java.io.IOException
- if writing to the LOB fails
StandardException
- if writing to the LOB fails
java.lang.IndexOutOfBoundsException
- if len
is larger than
b.length - off
int read(long pos) throws java.io.IOException, StandardException
pos
- postion from where to read
IOException,
- StandardException
java.io.IOException
StandardException
private int readBytes(byte[] b, int off, int len, long pos)
int read(byte[] buff, int off, int len, long pos) throws java.io.IOException, StandardException
buff
- array into the bytes will be copiedoff
- offset from where the array has to be populatedlen
- number of bytes to readpos
- initial postion before reading
IOException,
- StandardException
java.io.IOException
StandardException
java.io.InputStream getInputStream(long pos)
pos
- initial postion
java.io.OutputStream getOutputStream(long pos)
pos
- initial postion
long getLength() throws java.io.IOException
java.io.IOException
void truncate(long size) throws java.io.IOException, StandardException
size
- new size should be smaller than exisiting size
java.io.IOException
StandardException
void copyData(java.io.InputStream inStream, long length) throws java.io.IOException, StandardException
Note that specifying the length as Long.MAX_VALUE
results in
reading data from the stream until EOF is reached, but no length checking
will be performed.
inStream
- the stream to copy fromlength
- number of bytes to be copied, or Long.MAX_VALUE
to
copy everything until EOF is reached
IOException,
- StandardException
java.io.IOException
StandardException
long copyUtf8Data(java.io.InputStream utf8Stream, long charLength) throws java.io.IOException, StandardException
Note that specifying the length as Long.MAX_VALUE
results in
reading data from the stream until EOF is reached, but no length checking
will be performed.
utf8Stream
- the stream to copy fromcharLength
- number of chars to be copied, or Long.MAX_VALUE
to copy everything until EOF is reached
java.io.EOFException
- if EOF is reached prematurely
java.io.IOException
- thrown on a number of error conditions
StandardException
- if reading, writing or truncating the
LOBStreamControl
-object fails
java.io.UTFDataFormatException
- if an invalid UTF-8 encoding is detectedprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
private void deleteFile(StorageFile file) throws java.io.IOException
java.io.IOException
void free() throws java.io.IOException
IOexception
java.io.IOException
private void releaseTempFile(LOBFile file) throws java.io.IOException
LOBFile
s in EmbedConnection
.
file
- the temporary file
java.io.IOException
- if the file cannot be closed or deletedlong replaceBytes(byte[] buf, long stPos, long endPos) throws java.io.IOException, StandardException
The new byte array may not be be of same length as the original, thus it may result in resizing the total lob.
buf
- byte array which will be written inplace of old blockstPos
- inclusive starting position of current blockendPos
- exclusive end position of current block
IOExcepton
- if writing to temporary file fails
StandardException
java.io.IOException
long getUpdateCount()
|
Built on Thu 2012-03-29 21:53:33+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |