src/share/classes/javax/sql/rowset/serial/SerialBlob.java
Print this page
*** 79,88 ****
--- 79,90 ----
* array of bytes when it was first established.
* @serial
*/
private long origLen;
+ private transient boolean isFree = false;
+
/**
* Constructs a <code>SerialBlob</code> object that is a serialized version of
* the given <code>byte</code> array.
* <p>
* The new <code>SerialBlob</code> object is initialized with the data from the
*** 160,169 ****
--- 162,177 ----
* <code>SerialBlob</code> object, starting at the given
* position and containing the given number of consecutive bytes
* @throws SerialException if the given starting position is out of bounds
*/
public byte[] getBytes(long pos, int length) throws SerialException {
+ if (isFree == true) {
+ throw new SerialException(
+ "Unsupported operation. SerialBlob cannot "
+ + "get bytes when it has already been freed with free()");
+ }
+
if (length > len) {
length = (int)len;
}
if (pos < 1 || len - pos < 0 ) {
*** 204,213 ****
--- 212,227 ----
* this <code>SerialBlob</code> object's array of bytes
* @throws SerialException if an error occurs
* @see #setBinaryStream
*/
public java.io.InputStream getBinaryStream() throws SerialException {
+ if (isFree == true) {
+ throw new SerialException(
+ "Unsupported operation. SerialBlob cannot "
+ + "return a binary stream when it has already been freed with free()");
+ }
+
InputStream stream = new ByteArrayInputStream(buf);
return stream;
}
/**
*** 230,239 ****
--- 244,258 ----
* @throws SQLException if there is an error accessing the <code>BLOB</code>
* value from the database
*/
public long position(byte[] pattern, long start)
throws SerialException, SQLException {
+ if (isFree == true) {
+ throw new SerialException(
+ "Unsupported operation. SerialBlob has already been freed ");
+ }
+
if (start < 1 || start > len) {
return -1;
}
int pos = (int)start-1; // internally Blobs are stored as arrays.
*** 332,341 ****
--- 351,365 ----
* value from the database.
* @see #getBytes
*/
public int setBytes(long pos, byte[] bytes, int offset, int length)
throws SerialException, SQLException {
+ if (isFree == true) {
+ throw new SerialException(
+ "Unsupported operation. SerialBlob cannot "
+ + "set a binary stream when it has already been freed with free()");
+ }
if (offset < 0 || offset > bytes.length) {
throw new SerialException("Invalid offset in byte array set");
}
*** 400,409 ****
--- 424,438 ----
* truncated
* @throws SerialException if there is an error accessing the Blob value;
* or the length to truncate is greater that the SerialBlob length
*/
public void truncate(long length) throws SerialException {
+ if (isFree == true) {
+ throw new SerialException(
+ "Unsupported operation. SerialBlob cannot "
+ + "truncate a SerialBlob when it has already been freed with free()");
+ }
if (length > len) {
throw new SerialException
("Length more than what can be truncated");
} else if((int)length == 0) {
*** 429,439 ****
* in the <code>Blob</code>
*
* @since 1.6
*/
public InputStream getBinaryStream(long pos,long length) throws SQLException {
! throw new java.lang.UnsupportedOperationException("Not supported");
}
/**
* This method frees the <code>Blob</code> object and releases the resources that it holds.
--- 458,480 ----
* in the <code>Blob</code>
*
* @since 1.6
*/
public InputStream getBinaryStream(long pos,long length) throws SQLException {
! if (isFree == true) {
! throw new SerialException(
! "Unsupported operation. SerialBlob cannot "
! + "return a binary stream when it has already been freed with free()");
! }
!
! if (pos < 1 || pos > len || length > len - pos + 1) {
! throw new SerialException("Invalid pos in getBinaryStream");
! }
! if (length > len - pos + 1) {
! throw new SerialException("pos + length greater than total number of bytes");
! }
! return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
}
/**
* This method frees the <code>Blob</code> object and releases the resources that it holds.
*** 444,454 ****
* @throws SQLException if an error occurs releasing
* the Blob's resources
* @since 1.6
*/
public void free() throws SQLException {
! throw new java.lang.UnsupportedOperationException("Not supported");
}
/**
* The identifier that assists in the serialization of this <code>SerialBlob</code>
* object.
*/
--- 485,502 ----
* @throws SQLException if an error occurs releasing
* the Blob's resources
* @since 1.6
*/
public void free() throws SQLException {
! if (isFree == false) {
! len = -1;
! origLen = -1;
! buf = null;
! blob = null;
!
! isFree = true;
! }
}
/**
* The identifier that assists in the serialization of this <code>SerialBlob</code>
* object.
*/