- All Implemented Interfaces:
Serializable
,Cloneable
,Clob
public class SerialClob extends Object implements Clob, Serializable, Cloneable
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.
- Since:
- 1.5
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description SerialClob(char[] ch)
Constructs aSerialClob
object that is a serialized version of the givenchar
array.SerialClob(Clob clob)
Constructs aSerialClob
object that is a serialized version of the givenClob
object. -
Method Summary
Modifier and Type Method Description Object
clone()
Returns a clone of thisSerialClob
.boolean
equals(Object obj)
Compares this SerialClob to the specified object.void
free()
This method frees theSerialClob
object and releases the resources that it holds.InputStream
getAsciiStream()
Retrieves theCLOB
value designated by thisSerialClob
object as an ascii stream.Reader
getCharacterStream()
Returns thisSerialClob
object's data as a stream of Unicode characters.Reader
getCharacterStream(long pos, long length)
Returns aReader
object that contains a partialSerialClob
value, starting with the character specified by pos, which is length characters in length.String
getSubString(long pos, int length)
Returns a copy of the substring contained in thisSerialClob
object, starting at the given position and continuing for the specified number or characters.int
hashCode()
Returns a hash code for thisSerialClob
.long
length()
Retrieves the number of characters in thisSerialClob
object's array of characters.long
position(String searchStr, long start)
Returns the position in thisSerialClob
object where the givenString
object begins, starting the search at the specified position.long
position(Clob searchStr, long start)
Returns the position in thisSerialClob
object where the givenClob
signature begins, starting the search at the specified position.OutputStream
setAsciiStream(long pos)
Retrieves a stream to be used to write Ascii characters to theCLOB
value that thisSerialClob
object represents, starting at positionpos
.Writer
setCharacterStream(long pos)
Retrieves a stream to be used to write a stream of Unicode characters to theCLOB
value that thisSerialClob
object represents, at positionpos
.int
setString(long pos, String str)
Writes the given JavaString
to theCLOB
value that thisSerialClob
object represents, at the positionpos
.int
setString(long pos, String str, int offset, int length)
Writeslen
characters ofstr
, starting at characteroffset
, to theCLOB
value that thisClob
represents.void
truncate(long length)
Truncates theCLOB
value that thisSerialClob
object represents so that it has a length oflen
characters.
-
Constructor Details
-
SerialClob
Constructs aSerialClob
object that is a serialized version of the givenchar
array.The new
SerialClob
object is initialized with the data from thechar
array, thus allowing disconnectedRowSet
objects to establish a serializedClob
object without touching the data source.- Parameters:
ch
- the char array representing theClob
object to be serialized- Throws:
SerialException
- if an error occurs during serializationSQLException
- if a SQL error occurs
-
SerialClob
Constructs aSerialClob
object that is a serialized version of the givenClob
object.The new
SerialClob
object is initialized with the data from theClob
object; therefore, theClob
object should have previously brought the SQLCLOB
value's data over to the client from the database. Otherwise, the newSerialClob
object object will contain no data.Note: The
Clob
object supplied to this constructor must return non-null for both theClob.getCharacterStream()
andClob.getAsciiStream
methods. ThisSerialClob
constructor cannot serialize aClob
object in this instance and will throw anSQLException
object.- Parameters:
clob
- theClob
object from which thisSerialClob
object is to be constructed; cannot be null- Throws:
SerialException
- if an error occurs during serializationSQLException
- if a SQL error occurs in capturing the CLOB; if theClob
object is a null; or if either of theClob.getCharacterStream()
andClob.getAsciiStream()
methods on theClob
returns a null- See Also:
Clob
-
-
Method Details
-
length
Retrieves the number of characters in thisSerialClob
object's array of characters.- Specified by:
length
in interfaceClob
- Returns:
- a
long
indicating the length in characters of thisSerialClob
object's array of character - Throws:
SerialException
- if an error occurs; iffree
had previously been called on this object
-
getCharacterStream
Returns thisSerialClob
object's data as a stream of Unicode characters. Unlike the related method,getAsciiStream
, a stream is produced regardless of whether theSerialClob
object was created with aClob
object or achar
array.- Specified by:
getCharacterStream
in interfaceClob
- Returns:
- a
java.io.Reader
object containing thisSerialClob
object's data - Throws:
SerialException
- if an error occurs; iffree
had previously been called on this object- See Also:
Clob.setCharacterStream(long)
-
getAsciiStream
Retrieves theCLOB
value designated by thisSerialClob
object as an ascii stream. This method forwards thegetAsciiStream
call to the underlyingClob
object in the event that thisSerialClob
object is instantiated with aClob
object. If thisSerialClob
object is instantiated with achar
array, aSerialException
object is thrown.- Specified by:
getAsciiStream
in interfaceClob
- Returns:
- a
java.io.InputStream
object containing thisSerialClob
object's data - Throws:
SerialException
- if thisSerialClob
object was not instantiated with aClob
object; iffree
had previously been called on this objectSQLException
- if there is an error accessing theCLOB
value represented by theClob
object that was used to create thisSerialClob
object- See Also:
Clob.setAsciiStream(long)
-
getSubString
Returns a copy of the substring contained in thisSerialClob
object, starting at the given position and continuing for the specified number or characters.- Specified by:
getSubString
in interfaceClob
- Parameters:
pos
- the position of the first character in the substring to be copied; the first character of theSerialClob
object is at position1
; must not be less than1
, and the sum of the starting position and the length of the substring must be less than the length of thisSerialClob
objectlength
- the number of characters in the substring to be returned; must not be greater than the length of thisSerialClob
object, and the sum of the starting position and the length of the substring must be less than the length of thisSerialClob
object- Returns:
- a
String
object containing a substring of thisSerialClob
object beginning at the given position and containing the specified number of consecutive characters - Throws:
SerialException
- if either of the arguments is out of bounds; iffree
had previously been called on this object
-
position
Returns the position in thisSerialClob
object where the givenString
object begins, starting the search at the specified position. This method returns-1
if the pattern is not found.- Specified by:
position
in interfaceClob
- Parameters:
searchStr
- theString
object for which to searchstart
- the position in thisSerialClob
object at which to start the search; the first position is1
; must not be less than1
nor greater than the length of thisSerialClob
object- Returns:
- the position at which the given
String
object begins, starting the search at the specified position;-1
if the givenString
object is not found or the starting position is out of bounds; position numbering for the return value starts at1
- Throws:
SerialException
- if thefree
method had been previously called on this objectSQLException
- if there is an error accessing the Clob value from the database.
-
position
Returns the position in thisSerialClob
object where the givenClob
signature begins, starting the search at the specified position. This method returns-1
if the pattern is not found.- Specified by:
position
in interfaceClob
- Parameters:
searchStr
- theClob
object for which to searchstart
- the position in thisSerialClob
object at which to begin the search; the first position is1
; must not be less than1
nor greater than the length of thisSerialClob
object- Returns:
- the position at which the given
Clob
object begins in thisSerialClob
object, at or after the specified starting position - Throws:
SerialException
- if an error occurs locating the Clob signature; if thefree
method had been previously called on this objectSQLException
- if there is an error accessing the Clob value from the database
-
setString
Writes the given JavaString
to theCLOB
value that thisSerialClob
object represents, at the positionpos
.- Specified by:
setString
in interfaceClob
- Parameters:
pos
- the position at which to start writing to theCLOB
value that thisSerialClob
object represents; the first position is1
; must not be less than1
nor greater than the length of thisSerialClob
objectstr
- the string to be written to theCLOB
value that thisSerialClob
object represents- Returns:
- the number of characters written
- Throws:
SerialException
- if there is an error accessing theCLOB
value; if an invalid position is set; if an invalid offset value is set; if number of bytes to be written is greater than theSerialClob
length; or the combined values of the length and offset is greater than the Clob buffer; if thefree
method had been previously called on this object
-
setString
Writeslen
characters ofstr
, starting at characteroffset
, to theCLOB
value that thisClob
represents.- Specified by:
setString
in interfaceClob
- Parameters:
pos
- the position at which to start writing to theCLOB
value that thisSerialClob
object represents; the first position is1
; must not be less than1
nor greater than the length of thisSerialClob
objectstr
- the string to be written to theCLOB
value that thisClob
object representsoffset
- the offset intostr
to start reading the characters to be writtenlength
- the number of characters to be written- Returns:
- the number of characters written
- Throws:
SerialException
- if there is an error accessing theCLOB
value; if an invalid position is set; if an invalid offset value is set; if number of bytes to be written is greater than theSerialClob
length; or the combined values of the length and offset is greater than the Clob buffer; if thefree
method had been previously called on this object
-
setAsciiStream
Retrieves a stream to be used to write Ascii characters to theCLOB
value that thisSerialClob
object represents, starting at positionpos
. This method forwards thesetAsciiStream()
call to the underlyingClob
object in the event that thisSerialClob
object is instantiated with aClob
object. If thisSerialClob
object is instantiated with achar
array, aSerialException
object is thrown.- Specified by:
setAsciiStream
in interfaceClob
- Parameters:
pos
- the position at which to start writing to theCLOB
object- Returns:
- the stream to which ASCII encoded characters can be written
- Throws:
SerialException
- if SerialClob is not instantiated with a Clob object; if thefree
method had been previously called on this objectSQLException
- if there is an error accessing theCLOB
value- See Also:
getAsciiStream()
-
setCharacterStream
Retrieves a stream to be used to write a stream of Unicode characters to theCLOB
value that thisSerialClob
object represents, at positionpos
. This method forwards thesetCharacterStream()
call to the underlyingClob
object in the event that thisSerialClob
object is instantiated with aClob
object. If thisSerialClob
object is instantiated with achar
array, aSerialException
is thrown.- Specified by:
setCharacterStream
in interfaceClob
- Parameters:
pos
- the position at which to start writing to theCLOB
value- Returns:
- a stream to which Unicode encoded characters can be written
- Throws:
SerialException
- if the SerialClob is not instantiated with a Clob object; if thefree
method had been previously called on this objectSQLException
- if there is an error accessing theCLOB
value- See Also:
getCharacterStream()
-
truncate
Truncates theCLOB
value that thisSerialClob
object represents so that it has a length oflen
characters.Truncating a
SerialClob
object to length 0 has the effect of clearing its contents.- Specified by:
truncate
in interfaceClob
- Parameters:
length
- the length, in bytes, to which theCLOB
value should be truncated- Throws:
SerialException
- if there is an error accessing theCLOB
value; if thefree
method had been previously called on this object
-
getCharacterStream
Returns aReader
object that contains a partialSerialClob
value, starting with the character specified by pos, which is length characters in length.- Specified by:
getCharacterStream
in interfaceClob
- Parameters:
pos
- the offset to the first character of the partial value to be retrieved. The first character in theSerialClob
is at position 1.length
- the length in characters of the partial value to be retrieved.- Returns:
Reader
through which the partialSerialClob
value can be read.- Throws:
SQLException
- if pos is less than 1 or if pos is greater than the number of characters in theSerialClob
or if pos + length is greater than the number of characters in theSerialClob
;SerialException
- if thefree
method had been previously called on this object- Since:
- 1.6
-
free
This method frees theSerialClob
object and releases the resources that it holds. The object is invalid once thefree
method is called.If
free
is called multiple times, the subsequent calls tofree
are treated as a no-op.- Specified by:
free
in interfaceClob
- Throws:
SQLException
- if an error occurs releasing the Clob's resources- Since:
- 1.6
-
equals
Compares this SerialClob to the specified object. The result istrue
if and only if the argument is notnull
and is aSerialClob
object that represents the same sequence of characters as this object.- Overrides:
equals
in classObject
- Parameters:
obj
- The object to compare thisSerialClob
against- Returns:
true
if the given object represents aSerialClob
equivalent to this SerialClob,false
otherwise- See Also:
Object.hashCode()
,HashMap
-
hashCode
public int hashCode()Returns a hash code for thisSerialClob
.- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
clone
Returns a clone of thisSerialClob
. The copy will contain a reference to a clone of the internal character array, not a reference to the original internal character array of thisSerialClob
object. The underlyingClob
object will be set to null.
-