HSQLDB-Specific Information:
Starting with 2.1, in addition to HSQLDB driver support for both client-side in-memory and remote SQL CLOB data implementations, this class is provided to expose efficient, relatively high-performance BLOB operations over client accessible files.Design Notes
Although it is possible to implement a transactional version of this class, the present implementation directly propagates changes to the underlying file such that changes become visible as soon as they are either implicitly or explicitly flushed to disk.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| protected static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final FrameworkLogger | |
| private boolean | |
| private boolean | |
| private final File | |
| private List | |
| public static final String | |
| public static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JDBCBlobFile(boolean
Assigns whether an attempt to delete the backing file
is to be made in response to invocation of deleteOnFree)free().Constructs a new instance backed by a File object created in response to invoking File.createTempFile(TEMP_FILE_PREFIX,TEMP_FILE_SUFFIX). |
| public | JDBCBlobFile(final File
used to back this BLOB instance. file)Convenience constructor; equivalent to JDBCBlobFile(file, false); |
| public | JDBCBlobFile(final File
used to back this BLOB instance. file, boolean Assigns whether an attempt to delete the backing file
is to be made in response to invocation of deleteOnFree)free().Constructs a new instance backed by the given File object. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| protected final void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private void | |
| private void | |
| public synchronized void | free()
Implements java. This method frees the |
| public InputStream | Returns: a stream containing theBLOB dataImplements java. Retrieves the |
| public InputStream | Returns: InputStream through which the partial Blob value can be read.the offset to the first byte of the partial value to be retrieved.
The first byte in the pos, final long Blob is at position 1the length in bytes of the partial value to be retrieved length)Implements java. Returns an |
| public byte[] | Returns: a byte array containing up tolength
consecutive bytes from the BLOB value designated
by this Blob object, starting with the
byte at position posthe ordinal position of the first byte in the
pos, final int BLOB value to be extracted; the first byte is at
position 1the number of consecutive bytes to be copied; the value
for length must be 0 or greater length)Implements java. Retrieves all or part of the |
| public File | Returns: the file that backs this BLOB.Retrieves the canonical |
| public boolean | Returns: true if backing file deletion is attempted; otherwise false.Retrieves whether an attempt to delete the backing file
is made in response to invocation of |
| public long | Returns: length of theBLOB in bytesImplements java. Returns the number of bytes in the |
| public long | Returns: the position at which the pattern appears, else -1the byte array for which to search pattern, final long the position at which to begin searching; the
first position is 1 start)Implements java. Retrieves the byte position at which the specified byte array
|
| public long | Returns: the position at which the pattern begins, else -1the pattern, final long Blob object designating
the BLOB value for which to searchthe position in the start)BLOB value
at which to begin searching; the first position is 1Implements java. Retrieves the byte position in the |
| private long | |
| public OutputStream | Returns: ajava.io.OutputStream object to which data can
be writtenthe position in the pos)BLOB value at which
to start writing; the first position is 1Implements java. Retrieves a stream that can be used to write to the |
| public int | Returns: the number of bytes writtenthe position in the pos, final byte[] BLOB object at which
to start writing; the first position is 1the array of bytes to be written to the bytes)BLOB
value that this Blob object representsImplements java. Writes the given array of bytes to the |
| public int | Returns: the number of bytes writtenthe position in the pos, final byte[] BLOB object at which
to start writing; the first position is 1the array of bytes to be written to this bytes, final int BLOB
objectthe offset into the array offset, final int bytes at which
to start reading the bytes to be setthe number of bytes to be written to the len)BLOB
value from the array of bytes bytesImplements java. Writes all or part of the given |
| public void | setDeleteOnFree(boolean
the new value to assign deleteOnFree)Assigns whether an attempt to delete the backing file
is made in response to invocation of |
| public void | truncate(long
the length, in bytes, to which the len)BLOB value
that this Blob object represents should be truncatedImplements java. Truncates the |
| LOG | back to summary |
|---|---|
| private static final FrameworkLogger LOG | |
| m_closed | back to summary |
|---|---|
| private boolean m_closed | |
| m_deleteOnFree | back to summary |
|---|---|
| private boolean m_deleteOnFree | |
| m_file | back to summary |
|---|---|
| private final File m_file | |
| m_streams | back to summary |
|---|---|
| private List<Object> m_streams | |
| TEMP_FILE_PREFIX | back to summary |
|---|---|
| public static final String TEMP_FILE_PREFIX | |
| TEMP_FILE_SUFFIX | back to summary |
|---|---|
| public static final String TEMP_FILE_SUFFIX | |
| JDBCBlobFile | back to summary |
|---|---|
| public JDBCBlobFile() throws SQLException Convenience constructor; equivalent to JDBCBlobFile(true);
| |
| JDBCBlobFile | back to summary |
|---|---|
| public JDBCBlobFile(boolean deleteOnFree) throws SQLException Constructs a new instance backed by a File object created in response to invoking File.createTempFile(TEMP_FILE_PREFIX,TEMP_FILE_SUFFIX).
| |
| JDBCBlobFile | back to summary |
|---|---|
| public JDBCBlobFile(final File file) throws SQLException Convenience constructor; equivalent to JDBCBlobFile(file, false);
| |
| JDBCBlobFile | back to summary |
|---|---|
| public JDBCBlobFile(final File file, boolean deleteOnFree) throws SQLException Constructs a new instance backed by the given File object.
| |
| checkClosed | back to summary |
|---|---|
| private void checkClosed() throws SQLException | |
| checkIsFile | back to summary |
|---|---|
| protected final void checkIsFile(boolean checkExists) throws SQLException | |
| closeSafely | back to summary |
|---|---|
| private static void closeSafely(RandomAccessFile target) | |
| closeSafely | back to summary |
|---|---|
| private static void closeSafely(InputStream target) | |
| closeSafely | back to summary |
|---|---|
| private static void closeSafely(OutputStream target) | |
| closeSafely | back to summary |
|---|---|
| private static void closeSafely(Reader target) | |
| closeSafely | back to summary |
|---|---|
| private static void closeSafely(Writer target) | |
| closeSafely | back to summary |
|---|---|
| private void closeSafely(Object target) | |
| createFile | back to summary |
|---|---|
| private void createFile() throws SQLException | |
| free | back to summary |
|---|---|
| public synchronized void free() throws SQLException Implements java. This method frees the
After HSQLDB-Specific Information: This operation closes any input and/or output streams obtained viagetBinaryStream(), getBinaryStream(long, long) or
setBinaryStream(long).
Additionally, if the property
| |
| getBinaryStream | back to summary |
|---|---|
| public InputStream getBinaryStream() throws SQLException Implements java. Retrieves the
| |
| getBinaryStream | back to summary |
|---|---|
| public InputStream getBinaryStream(final long pos, final long length) throws SQLException Implements java. Returns an
| |
| getBytes | back to summary |
|---|---|
| public byte[] getBytes(final long pos, final int length) throws SQLException Implements java. Retrieves all or part of the
| |
| getFile | back to summary |
|---|---|
| public File getFile() Retrieves the canonical
| |
| isDeleteOnFree | back to summary |
|---|---|
| public boolean isDeleteOnFree() Retrieves whether an attempt to delete the backing file
is made in response to invocation of
| |
| length | back to summary |
|---|---|
| public long length() throws SQLException Implements java. Returns the number of bytes in the
| |
| position | back to summary |
|---|---|
| public long position(final byte[] pattern, final long start) throws SQLException Implements java. Retrieves the byte position at which the specified byte array
| |
| position | back to summary |
|---|---|
| public long position(final Blob pattern, final long start) throws SQLException Implements java. Retrieves the byte position in the
| |
| position0 | back to summary |
|---|---|
| private long position0(final byte[] pattern, final long start) throws SQLException | |
| setBinaryStream | back to summary |
|---|---|
| public OutputStream setBinaryStream(final long pos) throws SQLException Implements java. Retrieves a stream that can be used to write to the Note If the value specified for HSQLDB-Specific Information: Data written to the returned stream affects only the content of the underlying file; it has no effect upon a value stored in a database. To propagate the updated Blob value to a database, it is required to supply the Blob instance to an updating or inserting setXXX method of a Prepared or Callable Statement, or to supply the Blob instance to an updateXXX method of an updateable ResultSet.
| |
| setBytes | back to summary |
|---|---|
| public int setBytes(final long pos, final byte[] bytes) throws SQLException Implements java. Writes the given array of bytes to the Note If the value specified for HSQLDB-Specific Information: This operation affects only the content of the underlying file; it has no effect upon a value stored in a database. To propagate the updated Blob value to a database, it is required to supply the Blob instance to an updating or inserting setXXX method of a Prepared or Callable Statement, or to supply the Blob instance to an updateXXX method of an updatable ResultSet.
| |
| setBytes | back to summary |
|---|---|
| public int setBytes(final long pos, final byte[] bytes, final int offset, final int len) throws SQLException Implements java. Writes all or part of the given Note If the value specified for HSQLDB-Specific Information: This operation affects only the content of the underlying file; it has no effect upon a value stored in a database. To propagate the updated Blob value to a database, it is required to supply the Blob instance to an updating or inserting setXXX method of a Prepared or Callable Statement, or to supply the Blob instance to an updateXXX method of an updatable ResultSet.
| |
| setDeleteOnFree | back to summary |
|---|---|
| public void setDeleteOnFree(boolean deleteOnFree) Assigns whether an attempt to delete the backing file
is made in response to invocation of
| |
| truncate | back to summary |
|---|---|
| public void truncate(long len) throws SQLException Implements java. Truncates the Note If the value specified for HSQLDB-Specific Information: This operation affects only the length of the underlying file; it has no effect upon a value stored in a database. To propagate the truncated Blob value to a database, it is required to supply the Blob instance to an updating or inserting setXXX method of a Prepared or Callable Statement, or to supply the Blob instance to an updateXXX method of an updatable ResultSet.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final CountdownInputStream |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. |
| public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public int | read(byte[] b)
Overrides java. Reads some number of bytes from the input stream and stores them into
the buffer array |
| public int | read(byte[] b, int off, int len)
Overrides java. Reads up to |
| public long | skip(long n)
Overrides java. Skips over and discards |
| m_ciStream | back to summary |
|---|---|
| private final CountdownInputStream m_ciStream | |
| InputStreamAdapter | back to summary |
|---|---|
| pack-priv InputStreamAdapter(final File file, final long pos, final long length) throws IOException, SecurityException, NullPointerException, IllegalArgumentException | |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b) throws IOException Overrides java. Doc from java. Reads some number of bytes from the input stream and stores them into
the buffer array If the length of The first byte read is stored into element
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Doc from java. Skips over and discards
| |
| Modifier and Type | Field and Description |
|---|---|
| private final RandomAccessFile |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. Closes this output stream and releases any system resources associated with this stream. |
| public void | flush()
Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out. |
| public void | write(int b)
Implements abstract java. Writes the specified byte to this output stream. |
| public void | write(byte[] b)
Overrides java. Writes |
| public void | write(byte[] b, int off, int len)
Overrides java. Writes |
| m_randomAccessFile | back to summary |
|---|---|
| private final RandomAccessFile m_randomAccessFile | |
| OutputStreamAdapter | back to summary |
|---|---|
| protected OutputStreamAdapter(final File file, final long pos) throws IOException, IllegalArgumentException, NullPointerException, SecurityException | |
| OutputStreamAdapter | back to summary |
|---|---|
| protected OutputStreamAdapter(RandomAccessFile randomAccessFile) | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources
associated with this stream. The general contract of
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| write | back to summary |
|---|---|
| public void write(byte[] b) throws IOException Overrides java. Doc from java. Writes
| |
| write | back to summary |
|---|---|
| public void write(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |