533 * to the original internal byte array of this {@code SerialBlob} object.
534 * The underlying {@code Blob} object will be set to null.
535 *
536 * @return a clone of this SerialBlob
537 */
538 public Object clone() {
539 try {
540 SerialBlob sb = (SerialBlob) super.clone();
541 sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
542 sb.blob = null;
543 return sb;
544 } catch (CloneNotSupportedException ex) {
545 // this shouldn't happen, since we are Cloneable
546 throw new InternalError();
547 }
548 }
549
550 /**
551 * readObject is called to restore the state of the SerialBlob from
552 * a stream.
553 */
554 private void readObject(ObjectInputStream s)
555 throws IOException, ClassNotFoundException {
556
557 ObjectInputStream.GetField fields = s.readFields();
558 byte[] tmp = (byte[])fields.get("buf", null);
559 if (tmp == null)
560 throw new InvalidObjectException("buf is null and should not be!");
561 buf = tmp.clone();
562 len = fields.get("len", 0L);
563 if (buf.length != len)
564 throw new InvalidObjectException("buf is not the expected size");
565 origLen = fields.get("origLen", 0L);
566 blob = (Blob) fields.get("blob", null);
567 }
568
569 /**
570 * writeObject is called to save the state of the SerialBlob
571 * to a stream.
572 */
573 private void writeObject(ObjectOutputStream s)
574 throws IOException {
575
576 ObjectOutputStream.PutField fields = s.putFields();
577 fields.put("buf", buf);
578 fields.put("len", len);
579 fields.put("origLen", origLen);
580 // Note: this check to see if it is an instance of Serializable
581 // is for backwards compatibility
582 fields.put("blob", blob instanceof Serializable ? blob : null);
583 s.writeFields();
584 }
585
586 /**
587 * Check to see if this object had previously had its {@code free} method
588 * called
589 *
590 * @throws SerialException
591 */
|
533 * to the original internal byte array of this {@code SerialBlob} object.
534 * The underlying {@code Blob} object will be set to null.
535 *
536 * @return a clone of this SerialBlob
537 */
538 public Object clone() {
539 try {
540 SerialBlob sb = (SerialBlob) super.clone();
541 sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
542 sb.blob = null;
543 return sb;
544 } catch (CloneNotSupportedException ex) {
545 // this shouldn't happen, since we are Cloneable
546 throw new InternalError();
547 }
548 }
549
550 /**
551 * readObject is called to restore the state of the SerialBlob from
552 * a stream.
553 * @param s the {@code ObjectInputStream} to read from.
554 *
555 * @throws ClassNotFoundException if the class of a serialized object
556 * could not be found.
557 * @throws IOException if an I/O error occurs.
558 */
559 private void readObject(ObjectInputStream s)
560 throws IOException, ClassNotFoundException {
561
562 ObjectInputStream.GetField fields = s.readFields();
563 byte[] tmp = (byte[])fields.get("buf", null);
564 if (tmp == null)
565 throw new InvalidObjectException("buf is null and should not be!");
566 buf = tmp.clone();
567 len = fields.get("len", 0L);
568 if (buf.length != len)
569 throw new InvalidObjectException("buf is not the expected size");
570 origLen = fields.get("origLen", 0L);
571 blob = (Blob) fields.get("blob", null);
572 }
573
574 /**
575 * writeObject is called to save the state of the SerialBlob
576 * to a stream.
577 * @param s the {@code ObjectOutputStream} to write to.
578 + @throws IOException if I/O errors occur.
579 */
580 private void writeObject(ObjectOutputStream s)
581 throws IOException {
582
583 ObjectOutputStream.PutField fields = s.putFields();
584 fields.put("buf", buf);
585 fields.put("len", len);
586 fields.put("origLen", origLen);
587 // Note: this check to see if it is an instance of Serializable
588 // is for backwards compatibility
589 fields.put("blob", blob instanceof Serializable ? blob : null);
590 s.writeFields();
591 }
592
593 /**
594 * Check to see if this object had previously had its {@code free} method
595 * called
596 *
597 * @throws SerialException
598 */
|