Methods Summary |
---|
public void | free()This method frees the Blob object and releases the resources that it holds.
Blob object. 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.
throw new java.lang.UnsupportedOperationException("Not supported");
|
public java.io.InputStream | getBinaryStream(long pos, long length)Returns an InputStream object that contains a partial Blob value,
starting with the byte specified by pos, which is length bytes in length.
throw new java.lang.UnsupportedOperationException("Not supported");
|
public java.io.InputStream | getBinaryStream()Returns this SerialBlob object as an input stream.
Unlike the related method, setBinaryStream ,
a stream is produced regardless of whether the SerialBlob
was created with a Blob object or a byte array.
InputStream stream = new ByteArrayInputStream(buf);
return (java.io.InputStream)stream;
|
public byte[] | getBytes(long pos, int length)Copies the specified number of bytes, starting at the given
position, from this SerialBlob object to
another array of bytes.
Note that if the given number of bytes to be copied is larger than
the length of this SerialBlob object's array of
bytes, the given number will be shortened to the array's length.
if (length > len) {
length = (int)len;
}
if (pos < 1 || length - pos < 0 ) {
throw new SerialException("Invalid arguments: position cannot be less that 1");
}
pos--; // correct pos to array index
byte[] b = new byte[length];
for (int i = 0; i < length; i++) {
b[i] = this.buf[(int)pos];
pos++;
}
return b;
|
public long | length()Retrieves the number of bytes in this SerialBlob
object's array of bytes.
return len;
|
public long | position(byte[] pattern, long start)Returns the position in this SerialBlob object where
the given pattern of bytes begins, starting the search at the
specified position.
if (start < 1 || start > len) {
return -1;
}
int pos = (int)start-1; // internally Blobs are stored as arrays.
int i = 0;
long patlen = pattern.length;
while (pos < len) {
if (pattern[i] == buf[pos]) {
if (i + 1 == patlen) {
return (pos + 1) - (patlen - 1);
}
i++; pos++; // increment pos, and i
} else if (pattern[i] != buf[pos]) {
pos++; // increment pos only
}
}
return -1; // not found
|
public long | position(java.sql.Blob pattern, long start)Returns the position in this SerialBlob object where
the given Blob object begins, starting the search at the
specified position.
return position(pattern.getBytes(1, (int)(pattern.length())), start);
|
public java.io.OutputStream | setBinaryStream(long pos)Retrieves a stream that can be used to write to the BLOB
value that this Blob object represents. The stream begins
at position pos . This method forwards the
setBinaryStream() call to the underlying Blob in
the event that this SerialBlob object is instantiated with a
Blob . If this SerialBlob is instantiated with
a byte array, a SerialException is thrown.
if (this.blob.setBinaryStream(pos) != null) {
return this.blob.setBinaryStream(pos);
} else {
throw new SerialException("Unsupported operation. SerialBlob cannot " +
"return a writable binary stream, unless instantiated with a Blob object " +
"that provides a setBinaryStream() implementation");
}
|
public int | setBytes(long pos, byte[] bytes)Writes the given array of bytes to the BLOB value that
this Blob object represents, starting at position
pos , and returns the number of bytes written.
return (setBytes(pos, bytes, 0, bytes.length));
|
public int | setBytes(long pos, byte[] bytes, int offset, int length)Writes all or part of the given byte array to the
BLOB value that this Blob object represents
and returns the number of bytes written.
Writing starts at position pos in the BLOB
value; len bytes from the given byte array are written.
if (offset < 0 || offset > bytes.length) {
throw new SerialException("Invalid offset in byte array set");
}
if (pos < 1 || pos > this.length()) {
throw new SerialException("Invalid position in BLOB object set");
}
if ((long)(length) > origLen) {
throw new SerialException("Buffer is not sufficient to hold the value");
}
if ((length + offset) > bytes.length) {
throw new SerialException("Invalid OffSet. Cannot have combined offset " +
"and length that is greater that the Blob buffer");
}
int i = 0;
pos--; // correct to array indexing
while ( i < length || (offset + i +1) < (bytes.length-offset) ) {
this.buf[(int)pos + i] = bytes[offset + i ];
i++;
}
return i;
|
public void | truncate(long length)Truncates the BLOB value that this Blob
object represents to be len bytes in length.
if (length > len) {
throw new SerialException
("Length more than what can be truncated");
} else if((int)length == 0) {
buf = new byte[0];
len = length;
} else {
len = length;
buf = this.getBytes(1, (int)len);
}
|