Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

pack-priv final Class ClobUpdatableReader

extends Reader
Class Inheritance
Imports
java.io.IOException, .Reader, java.sql.SQLException, org.apache.derby.shared.common.sanity.SanityManager

ClobUpdatableReader is used to create a Reader capable of detecting changes to the underlying source.

This class is aware that the underlying stream can be modified and reinitializes itself if it detects any change in the stream. This invalidates the cache so the changes are reflected immediately.

The task of this class is to detect changes in the underlying Clob. Repositioning is handled by other classes.

Field Summary

Modifier and TypeField and Description
private final EmbedClob
clob

The Clob object we are reading from.

private volatile boolean
closed

Tells if this reader has been closed.

private InternalClob
iClob

The current internal representation of the Clob content.

private long
lastUpdateCount

The last update count seen on the underlying Clob.

private final long
maxPos

Position in Clob where to stop reading unless EOF is reached first.

private long
pos

Character position of this reader (1-based).

private Reader
streamReader

Reader accessing the Clob data and doing the work.

Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
ClobUpdatableReader(EmbedClob
source data
clob
)

Creates an updatable reader configured with initial position set to the first character in the Clob and with no imposed length limit.

public
ClobUpdatableReader(EmbedClob
source data
clob
,
long
the first character that will be read
initialPos
,
long
the maximum number of characters that will read
length
)

Creates an updatable reader configured with the specified initial position and with an imposed length limit.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes this reader.

public int
read()

Overrides java.io.Reader.read.

Reads a single character.

public int
read(char[]
Destination buffer
cbuf
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

public long
skip(long
The number of characters to skip
len
)

Overrides java.io.Reader.skip.

Skips characters.

private void
updateReaderIfRequired()

Updates the reader if the underlying data has been modified.

Inherited from java.io.Reader:
markmarkSupportednullReaderreadreadreadyresettransferTo

Field Detail

clobback to summary
private final EmbedClob clob

The Clob object we are reading from.

Note that even though the Clob itself is final, the internal representation of the content may change. The reference to the Clob is needed to get a hold of the new internal representation if it is changed.

See Also
iClob
closedback to summary
private volatile boolean closed

Tells if this reader has been closed.

iClobback to summary
private InternalClob iClob

The current internal representation of the Clob content.

If the user starts out with a read-only Clob and then modifies it, the internal representation will change.

lastUpdateCountback to summary
private long lastUpdateCount

The last update count seen on the underlying Clob.

maxPosback to summary
private final long maxPos

Position in Clob where to stop reading unless EOF is reached first.

posback to summary
private long pos

Character position of this reader (1-based).

streamReaderback to summary
private Reader streamReader

Reader accessing the Clob data and doing the work.

Constructor Detail

ClobUpdatableReaderback to summary
public ClobUpdatableReader(EmbedClob clob) throws IOException, SQLException

Creates an updatable reader configured with initial position set to the first character in the Clob and with no imposed length limit.

Parameters
clob:EmbedClob

source data

Exceptions
IOException:
if obtaining the underlying reader fails
SQLException:
if obtaining the underlying reader fails
ClobUpdatableReaderback to summary
public ClobUpdatableReader(EmbedClob clob, long initialPos, long length) throws IOException, SQLException

Creates an updatable reader configured with the specified initial position and with an imposed length limit.

Parameters
clob:EmbedClob

source data

initialPos:long

the first character that will be read

length:long

the maximum number of characters that will read

Exceptions
IOException:
if obtaining the underlying reader fails
SQLException:
if obtaining the underlying reader fails

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes this reader.

An IOException will be thrown if any of the read or skip methods are called after the reader has been closed.

Exceptions
IOException:
if an error occurs while closing
readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Returns:int

The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

off:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs
skipback to summary
public long skip(long len) throws IOException

Overrides java.io.Reader.skip.

Doc from java.io.Reader.skip.

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.

Parameters
len:long

The number of characters to skip

Returns:long

The number of characters actually skipped

Exceptions
IOException:
If an I/O error occurs
updateReaderIfRequiredback to summary
private void updateReaderIfRequired() throws IOException

Updates the reader if the underlying data has been modified.

There are two cases to deal with:

  1. The underlying data of the internal Clob representation has been modified.
  2. The internal Clob representation has changed.
The latter case happens when a read-only Clob, represented as a stream into store, is modified by the user and a new temporary internal representation is created.
Exceptions
IOException:
if verifying or updating the reader fails