1 /*
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.sql.rowset.serial;
27
28 import java.sql.*;
29 import java.io.*;
30 import java.lang.reflect.*;
31
32
33 /**
34 * A serialized mapping in the Java programming language of an SQL
35 * <code>BLOB</code> value.
36 * <P>
37 * The <code>SerialBlob</code> class provides a constructor for creating
38 * an instance from a <code>Blob</code> object. Note that the
39 * <code>Blob</code>
40 * object should have brought the SQL <code>BLOB</code> value's data over
41 * to the client before a <code>SerialBlob</code> object
42 * is constructed from it. The data of an SQL <code>BLOB</code> value can
43 * be materialized on the client as an array of bytes (using the method
44 * <code>Blob.getBytes</code>) or as a stream of uninterpreted bytes
45 * (using the method <code>Blob.getBinaryStream</code>).
46 * <P>
47 * <code>SerialBlob</code> methods make it possible to make a copy of a
48 * <code>SerialBlob</code> object as an array of bytes or as a stream.
49 * They also make it possible to locate a given pattern of bytes or a
50 * <code>Blob</code> object within a <code>SerialBlob</code> object
431 * @since 1.6
432 */
433 public InputStream getBinaryStream(long pos,long length) throws SQLException {
434 throw new java.lang.UnsupportedOperationException("Not supported");
435 }
436
437
438 /**
439 * This method frees the <code>Blob</code> object and releases the resources that it holds.
440 * <code>Blob</code> object. The object is invalid once the <code>free</code>
441 * method is called. If <code>free</code> is called multiple times, the subsequent
442 * calls to <code>free</code> are treated as a no-op.
443 *
444 * @throws SQLException if an error occurs releasing
445 * the Blob's resources
446 * @since 1.6
447 */
448 public void free() throws SQLException {
449 throw new java.lang.UnsupportedOperationException("Not supported");
450 }
451 /**
452 * The identifier that assists in the serialization of this <code>SerialBlob</code>
453 * object.
454 */
455
456 static final long serialVersionUID = -8144641928112860441L;
457 }
|
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.sql.rowset.serial;
27
28 import java.sql.*;
29 import java.io.*;
30 import java.lang.reflect.*;
31 import java.util.Arrays;
32 import java.util.Objects;
33
34
35 /**
36 * A serialized mapping in the Java programming language of an SQL
37 * <code>BLOB</code> value.
38 * <P>
39 * The <code>SerialBlob</code> class provides a constructor for creating
40 * an instance from a <code>Blob</code> object. Note that the
41 * <code>Blob</code>
42 * object should have brought the SQL <code>BLOB</code> value's data over
43 * to the client before a <code>SerialBlob</code> object
44 * is constructed from it. The data of an SQL <code>BLOB</code> value can
45 * be materialized on the client as an array of bytes (using the method
46 * <code>Blob.getBytes</code>) or as a stream of uninterpreted bytes
47 * (using the method <code>Blob.getBinaryStream</code>).
48 * <P>
49 * <code>SerialBlob</code> methods make it possible to make a copy of a
50 * <code>SerialBlob</code> object as an array of bytes or as a stream.
51 * They also make it possible to locate a given pattern of bytes or a
52 * <code>Blob</code> object within a <code>SerialBlob</code> object
433 * @since 1.6
434 */
435 public InputStream getBinaryStream(long pos,long length) throws SQLException {
436 throw new java.lang.UnsupportedOperationException("Not supported");
437 }
438
439
440 /**
441 * This method frees the <code>Blob</code> object and releases the resources that it holds.
442 * <code>Blob</code> object. The object is invalid once the <code>free</code>
443 * method is called. If <code>free</code> is called multiple times, the subsequent
444 * calls to <code>free</code> are treated as a no-op.
445 *
446 * @throws SQLException if an error occurs releasing
447 * the Blob's resources
448 * @since 1.6
449 */
450 public void free() throws SQLException {
451 throw new java.lang.UnsupportedOperationException("Not supported");
452 }
453
454 /**
455 * Compares this SerialBlob to the specified object. The result is {@code
456 * true} if and only if the argument is not {@code null} and is a {@code
457 * SerialBlob} object that represents the same sequence of bytes as this
458 * object.
459 *
460 * @param obj
461 * The object to compare this {@code SerialBlob} against
462 *
463 * @return {@code true} if the given object represents a {@code SerialBlob}
464 * equivalent to this SerialBlob, {@code false} otherwise
465 *
466 */
467 public boolean equals(Object obj) {
468 if (this == obj) {
469 return true;
470 }
471 if(obj == null || !(obj instanceof SerialBlob)) {
472 return false;
473 }
474
475 SerialBlob sb = (SerialBlob)obj;
476 if(this.len == sb.len) {
477 return Arrays.equals(buf, sb.buf);
478 }
479 return false;
480 }
481
482 /**
483 * Returns a hash code for this {@code SerialBlob}.
484 * @return a hash code value for this object.
485 */
486 public int hashCode() {
487 return Objects.hash(buf, len, origLen);
488 }
489
490 /**
491 * Returns a clone of this {@code SerialBlob}. The copy will contain a
492 * reference to a clone of the internal byte array, not a reference
493 * to the original internal byte array of this {@code SerialBlob} object.
494 * The internal {@code Blob} field will be set to null.
495 *
496 * @return a clone of this SerialBlob
497 */
498 public Object clone() {
499 SerialBlob sb = null;
500 try {
501 sb = (SerialBlob) super.clone();
502 sb.buf = Arrays.copyOf(buf, (int)len);
503 sb.blob = null;
504
505 } catch (CloneNotSupportedException ex) {
506 // this shouldn't happen, since we are Cloneable
507 }
508 return sb;
509 }
510
511 /**
512 * readObject is called to restore the state of the SerialBlob from
513 * a stream.
514 */
515 private void readObject(ObjectInputStream s)
516 throws IOException, ClassNotFoundException {
517
518 ObjectInputStream.GetField fields = s.readFields();
519 byte[] tmp = (byte[])fields.get("buf", null);
520 if (tmp == null)
521 throw new InvalidObjectException("buf is null and should not be!");
522 buf = tmp.clone();
523 len = fields.get("len", 0L);
524 origLen = fields.get("origLen", 0L);
525 blob = (Blob) fields.get("blob", null);
526 if(buf.length != len)
527 throw new InvalidObjectException("buf is not the expected size");
528 }
529
530 /**
531 * writeObject is called to save the state of the SerialBlob
532 * to a stream.
533 */
534 private void writeObject(ObjectOutputStream s)
535 throws IOException, ClassNotFoundException {
536
537 ObjectOutputStream.PutField fields = s.putFields();
538 fields.put("buf", buf);
539 fields.put("len", len);
540 fields.put("origLen", origLen);
541 fields.put("blob", null);
542 fields.put("blob", blob instanceof Serializable ? blob : null);
543 s.writeFields();
544 }
545
546 /**
547 * The identifier that assists in the serialization of this <code>SerialBlob</code>
548 * object.
549 */
550
551 static final long serialVersionUID = -8144641928112860441L;
552 }
|