--- a/jdk/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialBlob.java Fri May 15 16:09:55 2015 +0200
+++ b/jdk/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialBlob.java Fri May 15 22:09:49 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,7 @@
* value of this <code>SerialBlob</code> object.
* @serial
*/
- private byte buf[];
+ private byte[] buf;
/**
* The internal representation of the <code>Blob</code> object on which this
@@ -103,12 +103,13 @@
* @throws SerialException if an error occurs during serialization
* @throws SQLException if a SQL errors occurs
*/
- public SerialBlob(byte[] b) throws SerialException, SQLException {
+ public SerialBlob(byte[] b)
+ throws SerialException, SQLException {
len = b.length;
buf = new byte[(int)len];
for(int i = 0; i < len; i++) {
- buf[i] = b[i];
+ buf[i] = b[i];
}
origLen = len;
}
@@ -133,19 +134,17 @@
* to this constructor is a <code>null</code>.
* @see java.sql.Blob
*/
- public SerialBlob (Blob blob) throws SerialException, SQLException {
+ public SerialBlob (Blob blob)
+ throws SerialException, SQLException {
if (blob == null) {
- throw new SQLException("Cannot instantiate a SerialBlob " +
- "object with a null Blob object");
+ throw new SQLException(
+ "Cannot instantiate a SerialBlob object with a null Blob object");
}
len = blob.length();
buf = blob.getBytes(1, (int)len );
this.blob = blob;
-
- //if ( len < 10240000)
- // len = 10240000;
origLen = len;
}
@@ -246,7 +245,8 @@
* value from the database
*/
public long position(byte[] pattern, long start)
- throws SerialException, SQLException {
+ throws SerialException, SQLException {
+
isValid();
if (start < 1 || start > len) {
return -1;
@@ -291,7 +291,7 @@
* value from the database
*/
public long position(Blob pattern, long start)
- throws SerialException, SQLException {
+ throws SerialException, SQLException {
isValid();
return position(pattern.getBytes(1, (int)(pattern.length())), start);
}
@@ -317,8 +317,8 @@
* @see #getBytes
*/
public int setBytes(long pos, byte[] bytes)
- throws SerialException, SQLException {
- return (setBytes(pos, bytes, 0, bytes.length));
+ throws SerialException, SQLException {
+ return setBytes(pos, bytes, 0, bytes.length);
}
/**
@@ -353,7 +353,7 @@
* @see #getBytes
*/
public int setBytes(long pos, byte[] bytes, int offset, int length)
- throws SerialException, SQLException {
+ throws SerialException, SQLException {
isValid();
if (offset < 0 || offset > bytes.length) {
@@ -370,7 +370,7 @@
if ((length + offset) > bytes.length) {
throw new SerialException("Invalid OffSet. Cannot have combined offset " +
- "and length that is greater that the Blob buffer");
+ "and length that is greater that the Blob buffer");
}
int i = 0;
@@ -403,7 +403,8 @@
* @see #getBinaryStream
*/
public java.io.OutputStream setBinaryStream(long pos)
- throws SerialException, SQLException {
+ throws SerialException, SQLException {
+
isValid();
if (this.blob != null) {
return this.blob.setBinaryStream(pos);
@@ -426,17 +427,16 @@
* if {@code free} had previously been called on this object
*/
public void truncate(long length) throws SerialException {
-
isValid();
if (length > len) {
- throw new SerialException
- ("Length more than what can be truncated");
+ throw new SerialException(
+ "Length more than what can be truncated");
} else if((int)length == 0) {
- buf = new byte[0];
- len = length;
+ buf = new byte[0];
+ len = length;
} else {
- len = length;
- buf = this.getBytes(1, (int)len);
+ len = length;
+ buf = this.getBytes(1, (int)len);
}
}
@@ -467,8 +467,8 @@
throw new SerialException("Invalid position in BLOB object set");
}
if (length < 1 || length > len - pos + 1) {
- throw new SerialException("length is < 1 or pos + length >"
- + "total number of bytes");
+ throw new SerialException(
+ "length is < 1 or pos + length > total number of bytes");
}
return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
}
@@ -537,14 +537,13 @@
public Object clone() {
try {
SerialBlob sb = (SerialBlob) super.clone();
- sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
+ sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
sb.blob = null;
return sb;
} catch (CloneNotSupportedException ex) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
-
}
/**
@@ -555,15 +554,15 @@
throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = s.readFields();
- byte[] tmp = (byte[])fields.get("buf", null);
- if (tmp == null)
- throw new InvalidObjectException("buf is null and should not be!");
- buf = tmp.clone();
- len = fields.get("len", 0L);
- if (buf.length != len)
- throw new InvalidObjectException("buf is not the expected size");
- origLen = fields.get("origLen", 0L);
- blob = (Blob) fields.get("blob", null);
+ byte[] tmp = (byte[])fields.get("buf", null);
+ if (tmp == null)
+ throw new InvalidObjectException("buf is null and should not be!");
+ buf = tmp.clone();
+ len = fields.get("len", 0L);
+ if (buf.length != len)
+ throw new InvalidObjectException("buf is not the expected size");
+ origLen = fields.get("origLen", 0L);
+ blob = (Blob) fields.get("blob", null);
}
/**
@@ -591,8 +590,8 @@
*/
private void isValid() throws SerialException {
if (buf == null) {
- throw new SerialException("Error: You cannot call a method on a "
- + "SerialBlob instance once free() has been called.");
+ throw new SerialException("Error: You cannot call a method on a " +
+ "SerialBlob instance once free() has been called.");
}
}