--- old/src/share/classes/javax/sql/rowset/serial/SerialBlob.java 2012-06-25 15:45:03.952364123 +0800
+++ new/src/share/classes/javax/sql/rowset/serial/SerialBlob.java 2012-06-25 15:45:03.772363227 +0800
@@ -81,6 +81,8 @@
*/
private long origLen;
+ private transient boolean isFree = false;
+
/**
* Constructs a SerialBlob
object that is a serialized version of
* the given byte
array.
@@ -162,6 +164,12 @@
* @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;
}
@@ -206,6 +214,12 @@
* @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;
}
@@ -232,6 +246,11 @@
*/
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;
}
@@ -334,6 +353,11 @@
*/
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");
@@ -402,6 +426,11 @@
* 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
@@ -431,7 +460,19 @@
* @since 1.6
*/
public InputStream getBinaryStream(long pos,long length) throws SQLException {
- throw new java.lang.UnsupportedOperationException("Not supported");
+ 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);
}
@@ -446,7 +487,14 @@
* @since 1.6
*/
public void free() throws SQLException {
- throw new java.lang.UnsupportedOperationException("Not supported");
+ if (isFree == false) {
+ len = -1;
+ origLen = -1;
+ buf = null;
+ blob = null;
+
+ isFree = true;
+ }
}
/**
* The identifier that assists in the serialization of this SerialBlob