Top Description Fields Constructors Methods
javax.sql.rowset.serial

public Class SerialClob

extends Object
implements Clob, Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable, java.sql.Clob
Imports
java.sql.*, java.io.*, java.util.Arrays

A serialized mapping in the Java programming language of an SQL CLOB value.

The SerialClob class provides a constructor for creating an instance from a Clob object. Note that the Clob object should have brought the SQL CLOB value's data over to the client before a SerialClob object is constructed from it. The data of an SQL CLOB value can be materialized on the client as a stream of Unicode characters.

SerialClob methods make it possible to get a substring from a SerialClob object or to locate the start of a pattern of characters.

Thread safety

A SerialClob is not safe for use by multiple concurrent threads. If a SerialClob is to be used by more than one thread then access to the SerialClob should be controlled by appropriate synchronization.

Author
Jonathan Bruce
Since
1.5

Field Summary

Modifier and TypeField and Description
private char[]
buf

A serialized array of characters containing the data of the SQL CLOB value that this SerialClob object represents.

private Clob
clob

Internal Clob representation if SerialClob is initialized with a Clob.

private long
len

The length in characters of this SerialClob object's internal array of characters.

private long
origLen

The original length in characters of this SerialClob object's internal array of characters.

pack-priv static final long
serialVersionUID

The identifier that assists in the serialization of this SerialClob object.

Constructor Summary

AccessConstructor and Description
public
SerialClob(char[]
the char array representing the Clob object to be serialized
ch
)

Constructs a SerialClob object that is a serialized version of the given char array.

public
SerialClob(Clob
the Clob object from which this SerialClob object is to be constructed; cannot be null
clob
)

Constructs a SerialClob object that is a serialized version of the given Clob object.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this SerialClob
clone
()

Overrides java.lang.Object.clone.

Returns a clone of this SerialClob.
public boolean

Returns:

true if the given object represents a SerialClob equivalent to this SerialClob, false otherwise
equals
(Object
The object to compare this SerialClob against
obj
)

Overrides java.lang.Object.equals.

Compares this SerialClob to the specified object.
public void
free()

Implements java.sql.Clob.free.

This method frees the SerialClob object and releases the resources that it holds.
public InputStream

Returns:

a java.io.InputStream object containing this SerialClob object's data
getAsciiStream
()

Implements java.sql.Clob.getAsciiStream.

Retrieves the CLOB value designated by this SerialClob object as an ascii stream.
public Reader

Returns:

a java.io.Reader object containing this SerialClob object's data
getCharacterStream
()

Implements java.sql.Clob.getCharacterStream.

Returns this SerialClob object's data as a stream of Unicode characters.
public Reader

Returns:

Reader through which the partial SerialClob value can be read.
getCharacterStream
(long
the offset to the first character of the partial value to be retrieved. The first character in the SerialClob is at position 1.
pos
,
long
the length in characters of the partial value to be retrieved.
length
)

Implements java.sql.Clob.getCharacterStream.

Returns a Reader object that contains a partial SerialClob value, starting with the character specified by pos, which is length characters in length.
public String

Returns:

a String object containing a substring of this SerialClob object beginning at the given position and containing the specified number of consecutive characters
getSubString
(long
the position of the first character in the substring to be copied; the first character of the SerialClob object is at position 1; must not be less than 1, and the sum of the starting position and the length of the substring must be less than the length of this SerialClob object
pos
,
int
the number of characters in the substring to be returned; must not be greater than the length of this SerialClob object, and the sum of the starting position and the length of the substring must be less than the length of this SerialClob object
length
)

Implements java.sql.Clob.getSubString.

Returns a copy of the substring contained in this SerialClob object, starting at the given position and continuing for the specified number or characters.
public int

Returns:

a hash code value for this object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this SerialClob.
private void
isValid()

Check to see if this object had previously had its free method called

public long

Returns:

a long indicating the length in characters of this SerialClob object's array of character
length
()

Implements java.sql.Clob.length.

Retrieves the number of characters in this SerialClob object's array of characters.
public long

Returns:

the position at which the given String object begins, starting the search at the specified position; -1 if the given String object is not found or the starting position is out of bounds; position numbering for the return value starts at 1
position
(String
the String object for which to search
searchStr
,
long
the position in this SerialClob object at which to start the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialClob object
start
)

Implements java.sql.Clob.position.

Returns the position in this SerialClob object where the given String object begins, starting the search at the specified position.
public long

Returns:

the position at which the given Clob object begins in this SerialClob object, at or after the specified starting position
position
(Clob
the Clob object for which to search
searchStr
,
long
the position in this SerialClob object at which to begin the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialClob object
start
)

Implements java.sql.Clob.position.

Returns the position in this SerialClob object where the given Clob signature begins, starting the search at the specified position.
private void
readObject(ObjectInputStream
the ObjectInputStream to read from.
s
)

readObject is called to restore the state of the SerialClob from a stream.

public OutputStream

Returns:

the stream to which ASCII encoded characters can be written
setAsciiStream
(long
the position at which to start writing to the CLOB object
pos
)

Implements java.sql.Clob.setAsciiStream.

Retrieves a stream to be used to write Ascii characters to the CLOB value that this SerialClob object represents, starting at position pos.
public Writer

Returns:

a stream to which Unicode encoded characters can be written
setCharacterStream
(long
the position at which to start writing to the CLOB value
pos
)

Implements java.sql.Clob.setCharacterStream.

Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this SerialClob object represents, at position pos.
public int

Returns:

the number of characters written
setString
(long
the position at which to start writing to the CLOB value that this SerialClob object represents; the first position is 1; must not be less than 1 nor greater than the length+1 of this SerialClob object
pos
,
String
the string to be written to the CLOB value that this SerialClob object represents
str
)

Implements java.sql.Clob.setString.

Writes the given Java String to the CLOB value that this SerialClob object represents, at the position pos.
public int

Returns:

the number of characters written
setString
(long
the position at which to start writing to the CLOB value that this SerialClob object represents; the first position is 1; must not be less than 1 nor greater than the length+1 of this SerialClob object
pos
,
String
the string to be written to the CLOB value that this Clob object represents
str
,
int
the offset into str to start reading the characters to be written
offset
,
int
the number of characters to be written
length
)

Implements java.sql.Clob.setString.

Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.
public void
truncate(long
the length, in bytes, to which the CLOB value should be truncated
length
)

Implements java.sql.Clob.truncate.

Truncates the CLOB value that this SerialClob object represents so that it has a length of len characters.
private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write to.
s
)

writeObject is called to save the state of the SerialClob to a stream.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private char[] buf

A serialized array of characters containing the data of the SQL CLOB value that this SerialClob object represents.

clobback to summary
private Clob clob

Internal Clob representation if SerialClob is initialized with a Clob. Null if SerialClob is initialized with a char[].

Annotations
@SuppressWarnings:serial
lenback to summary
private long len

The length in characters of this SerialClob object's internal array of characters.

origLenback to summary
private long origLen

The original length in characters of this SerialClob object's internal array of characters.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

The identifier that assists in the serialization of this SerialClob object.

Constructor Detail

SerialClobback to summary
public SerialClob(char[] ch) throws SerialException, SQLException

Constructs a SerialClob object that is a serialized version of the given char array.

The new SerialClob object is initialized with the data from the char array, thus allowing disconnected RowSet objects to establish a serialized Clob object without touching the data source.

Parameters
ch:char[]

the char array representing the Clob object to be serialized

Exceptions
SerialException:
if an error occurs during serialization
SQLException:
if a SQL error occurs
SerialClobback to summary
public SerialClob(Clob clob) throws SerialException, SQLException

Constructs a SerialClob object that is a serialized version of the given Clob object.

The new SerialClob object is initialized with the data from the Clob object; therefore, the Clob object should have previously brought the SQL CLOB value's data over to the client from the database. Otherwise, the new SerialClob object object will contain no data.

Note

The Clob object supplied to this constructor must return non-null for both the Clob.getCharacterStream() and Clob.getAsciiStream methods. This SerialClob constructor cannot serialize a Clob object in this instance and will throw an SQLException object.

Parameters
clob:Clob

the Clob object from which this SerialClob object is to be constructed; cannot be null

Exceptions
SerialException:
if an error occurs during serialization
SQLException:
if a SQL error occurs in capturing the CLOB; if the Clob object is a null; or if either of the Clob.getCharacterStream() and Clob.getAsciiStream() methods on the Clob returns a null
See Also
java.sql.Clob

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Returns a clone of this SerialClob. The copy will contain a reference to a clone of the internal character array, not a reference to the original internal character array of this SerialClob object. The underlying Clob object will be set to null.

Returns:Object

a clone of this SerialClob

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares this SerialClob to the specified object. The result is true if and only if the argument is not null and is a SerialClob object that represents the same sequence of characters as this object.

Parameters
obj:Object

The object to compare this SerialClob against

Returns:boolean

true if the given object represents a SerialClob equivalent to this SerialClob, false otherwise

freeback to summary
public void free() throws SQLException

Implements java.sql.Clob.free.

This method frees the SerialClob object and releases the resources that it holds. The object is invalid once the free method is called.

If free is called multiple times, the subsequent calls to free are treated as a no-op.

Exceptions
SQLException:
if an error occurs releasing the Clob's resources
Since
1.6
getAsciiStreamback to summary
public InputStream getAsciiStream() throws SerialException, SQLException

Implements java.sql.Clob.getAsciiStream.

Retrieves the CLOB value designated by this SerialClob object as an ascii stream. This method forwards the getAsciiStream call to the underlying Clob object in the event that this SerialClob object is instantiated with a Clob object. If this SerialClob object is instantiated with a char array, a SerialException object is thrown.

Returns:InputStream

a java.io.InputStream object containing this SerialClob object's data

Exceptions
SerialException:
if this SerialClob object was not instantiated with a Clob object; if free had previously been called on this object
SQLException:
if there is an error accessing the CLOB value represented by the Clob object that was used to create this SerialClob object
getCharacterStreamback to summary
public Reader getCharacterStream() throws SerialException

Implements java.sql.Clob.getCharacterStream.

Returns this SerialClob object's data as a stream of Unicode characters. Unlike the related method, getAsciiStream, a stream is produced regardless of whether the SerialClob object was created with a Clob object or a char array.

Returns:Reader

a java.io.Reader object containing this SerialClob object's data

Exceptions
SerialException:
if an error occurs; if free had previously been called on this object
getCharacterStreamback to summary
public Reader getCharacterStream(long pos, long length) throws SQLException

Implements java.sql.Clob.getCharacterStream.

Returns a Reader object that contains a partial SerialClob value, starting with the character specified by pos, which is length characters in length.

Parameters
pos:long

the offset to the first character of the partial value to be retrieved. The first character in the SerialClob is at position 1.

length:long

the length in characters of the partial value to be retrieved.

Returns:Reader

Reader through which the partial SerialClob value can be read.

Exceptions
SQLException:
if pos is less than 1 or if pos is greater than the number of characters in the SerialClob or if pos + length is greater than the number of characters in the SerialClob;
SerialException:
if the free method had been previously called on this object
Since
1.6
getSubStringback to summary
public String getSubString(long pos, int length) throws SerialException

Implements java.sql.Clob.getSubString.

Returns a copy of the substring contained in this SerialClob object, starting at the given position and continuing for the specified number or characters.

Parameters
pos:long

the position of the first character in the substring to be copied; the first character of the SerialClob object is at position 1; must not be less than 1, and the sum of the starting position and the length of the substring must be less than the length of this SerialClob object

length:int

the number of characters in the substring to be returned; must not be greater than the length of this SerialClob object, and the sum of the starting position and the length of the substring must be less than the length of this SerialClob object

Returns:String

a String object containing a substring of this SerialClob object beginning at the given position and containing the specified number of consecutive characters

Exceptions
SerialException:
if either of the arguments is out of bounds; if free had previously been called on this object
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this SerialClob.

Returns:int

a hash code value for this object.

isValidback to summary
private void isValid() throws SerialException

Check to see if this object had previously had its free method called

lengthback to summary
public long length() throws SerialException

Implements java.sql.Clob.length.

Retrieves the number of characters in this SerialClob object's array of characters.

Returns:long

a long indicating the length in characters of this SerialClob object's array of character

Exceptions
SerialException:
if an error occurs; if free had previously been called on this object
positionback to summary
public long position(String searchStr, long start) throws SerialException, SQLException

Implements java.sql.Clob.position.

Returns the position in this SerialClob object where the given String object begins, starting the search at the specified position. This method returns -1 if the pattern is not found.

Parameters
searchStr:String

the String object for which to search

start:long

the position in this SerialClob object at which to start the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialClob object

Returns:long

the position at which the given String object begins, starting the search at the specified position; -1 if the given String object is not found or the starting position is out of bounds; position numbering for the return value starts at 1

Exceptions
SerialException:
if the free method had been previously called on this object
SQLException:
if there is an error accessing the Clob value from the database.
positionback to summary
public long position(Clob searchStr, long start) throws SerialException, SQLException

Implements java.sql.Clob.position.

Returns the position in this SerialClob object where the given Clob signature begins, starting the search at the specified position. This method returns -1 if the pattern is not found.

Parameters
searchStr:Clob

the Clob object for which to search

start:long

the position in this SerialClob object at which to begin the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialClob object

Returns:long

the position at which the given Clob object begins in this SerialClob object, at or after the specified starting position

Exceptions
SerialException:
if an error occurs locating the Clob signature; if the free method had been previously called on this object
SQLException:
if there is an error accessing the Clob value from the database
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

readObject is called to restore the state of the SerialClob from a stream.

Parameters
s:ObjectInputStream

the ObjectInputStream to read from.

Exceptions
IOException:
if an I/O error occurs.
ClassNotFoundException:
if the class of a serialized object could not be found.
setAsciiStreamback to summary
public OutputStream setAsciiStream(long pos) throws SerialException, SQLException

Implements java.sql.Clob.setAsciiStream.

Retrieves a stream to be used to write Ascii characters to the CLOB value that this SerialClob object represents, starting at position pos. This method forwards the setAsciiStream() call to the underlying Clob object in the event that this SerialClob object is instantiated with a Clob object. If this SerialClob object is instantiated with a char array, a SerialException object is thrown.

Parameters
pos:long

the position at which to start writing to the CLOB object

Returns:OutputStream

the stream to which ASCII encoded characters can be written

Exceptions
SerialException:
if SerialClob is not instantiated with a Clob object; if the free method had been previously called on this object
SQLException:
if there is an error accessing the CLOB value
See Also
getAsciiStream
setCharacterStreamback to summary
public Writer setCharacterStream(long pos) throws SerialException, SQLException

Implements java.sql.Clob.setCharacterStream.

Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this SerialClob object represents, at position pos. This method forwards the setCharacterStream() call to the underlying Clob object in the event that this SerialClob object is instantiated with a Clob object. If this SerialClob object is instantiated with a char array, a SerialException is thrown.

Parameters
pos:long

the position at which to start writing to the CLOB value

Returns:Writer

a stream to which Unicode encoded characters can be written

Exceptions
SerialException:
if the SerialClob is not instantiated with a Clob object; if the free method had been previously called on this object
SQLException:
if there is an error accessing the CLOB value
See Also
getCharacterStream
setStringback to summary
public int setString(long pos, String str) throws SerialException

Implements java.sql.Clob.setString.

Writes the given Java String to the CLOB value that this SerialClob object represents, at the position pos.

Parameters
pos:long

the position at which to start writing to the CLOB value that this SerialClob object represents; the first position is 1; must not be less than 1 nor greater than the length+1 of this SerialClob object

str:String

the string to be written to the CLOB value that this SerialClob object represents

Returns:int

the number of characters written

Exceptions
SerialException:
if there is an error accessing the CLOB value; if an invalid position is set; if the free method had been previously called on this object
setStringback to summary
public int setString(long pos, String str, int offset, int length) throws SerialException

Implements java.sql.Clob.setString.

Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.

Parameters
pos:long

the position at which to start writing to the CLOB value that this SerialClob object represents; the first position is 1; must not be less than 1 nor greater than the length+1 of this SerialClob object

str:String

the string to be written to the CLOB value that this Clob object represents

offset:int

the offset into str to start reading the characters to be written

length:int

the number of characters to be written

Returns:int

the number of characters written

Exceptions
SerialException:
if there is an error accessing the CLOB value; if an invalid position is set; if an invalid offset value is set; or the combined values of the length and offset is greater than the length of str; if the free method had been previously called on this object
truncateback to summary
public void truncate(long length) throws SerialException

Implements java.sql.Clob.truncate.

Truncates the CLOB value that this SerialClob object represents so that it has a length of len characters.

Truncating a SerialClob object to length 0 has the effect of clearing its contents.

Parameters
length:long

the length, in bytes, to which the CLOB value should be truncated

Exceptions
SerialException:
if there is an error accessing the CLOB value; if the free method had been previously called on this object
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

writeObject is called to save the state of the SerialClob to a stream.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to write to.

Exceptions
IOException:
if an I/O error occurs.