< prev index next >

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialClob.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 2019, 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

626      * to the original internal character array of this {@code SerialClob} object.
627      * The underlying {@code Clob} object will be set to null.
628      *
629      * @return  a clone of this SerialClob
630      */
631     public Object clone() {
632         try {
633             SerialClob sc = (SerialClob) super.clone();
634             sc.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
635             sc.clob = null;
636             return sc;
637         } catch (CloneNotSupportedException ex) {
638             // this shouldn't happen, since we are Cloneable
639             throw new InternalError();
640         }
641     }
642 
643     /**
644      * readObject is called to restore the state of the SerialClob from
645      * a stream.





646      */
647     private void readObject(ObjectInputStream s)
648             throws IOException, ClassNotFoundException {
649 
650         ObjectInputStream.GetField fields = s.readFields();
651        char[] tmp = (char[])fields.get("buf", null);
652        if (tmp == null)
653            throw new InvalidObjectException("buf is null and should not be!");
654        buf = tmp.clone();
655        len = fields.get("len", 0L);
656        if (buf.length != len)
657            throw new InvalidObjectException("buf is not the expected size");
658        origLen = fields.get("origLen", 0L);
659        clob = (Clob) fields.get("clob", null);
660     }
661 
662     /**
663      * writeObject is called to save the state of the SerialClob
664      * to a stream.


665      */
666     private void writeObject(ObjectOutputStream s)
667             throws IOException {
668 
669         ObjectOutputStream.PutField fields = s.putFields();
670         fields.put("buf", buf);
671         fields.put("len", len);
672         fields.put("origLen", origLen);
673         // Note: this check to see if it is an instance of Serializable
674         // is for backwards compatibility
675         fields.put("clob", clob instanceof Serializable ? clob : null);
676         s.writeFields();
677     }
678 
679     /**
680      * Check to see if this object had previously had its {@code free} method
681      * called
682      *
683      * @throws SerialException
684      */

  1 /*
  2  * Copyright (c) 2003, 2020, 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

626      * to the original internal character array of this {@code SerialClob} object.
627      * The underlying {@code Clob} object will be set to null.
628      *
629      * @return  a clone of this SerialClob
630      */
631     public Object clone() {
632         try {
633             SerialClob sc = (SerialClob) super.clone();
634             sc.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
635             sc.clob = null;
636             return sc;
637         } catch (CloneNotSupportedException ex) {
638             // this shouldn't happen, since we are Cloneable
639             throw new InternalError();
640         }
641     }
642 
643     /**
644      * readObject is called to restore the state of the SerialClob from
645      * a stream.
646      * @param s the {@code ObjectInputStream} to read from.
647      *
648      * @throws  ClassNotFoundException if the class of a serialized object
649      *          could not be found.
650      * @throws  IOException if an I/O error occurs.
651      */
652     private void readObject(ObjectInputStream s)
653             throws IOException, ClassNotFoundException {
654 
655         ObjectInputStream.GetField fields = s.readFields();
656        char[] tmp = (char[])fields.get("buf", null);
657        if (tmp == null)
658            throw new InvalidObjectException("buf is null and should not be!");
659        buf = tmp.clone();
660        len = fields.get("len", 0L);
661        if (buf.length != len)
662            throw new InvalidObjectException("buf is not the expected size");
663        origLen = fields.get("origLen", 0L);
664        clob = (Clob) fields.get("clob", null);
665     }
666 
667     /**
668      * writeObject is called to save the state of the SerialClob
669      * to a stream.
670      * @param s the {@code ObjectOutputStream} to write to.
671      + @throws  IOException if I/O errors occur.
672      */
673     private void writeObject(ObjectOutputStream s)
674             throws IOException {
675 
676         ObjectOutputStream.PutField fields = s.putFields();
677         fields.put("buf", buf);
678         fields.put("len", len);
679         fields.put("origLen", origLen);
680         // Note: this check to see if it is an instance of Serializable
681         // is for backwards compatibility
682         fields.put("clob", clob instanceof Serializable ? clob : null);
683         s.writeFields();
684     }
685 
686     /**
687      * Check to see if this object had previously had its {@code free} method
688      * called
689      *
690      * @throws SerialException
691      */
< prev index next >