< prev index next >

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialArray.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

591      * reference to a clone of the underlying objects array, not a reference
592      * to the original underlying object array of this {@code SerialArray} object.
593      *
594      * @return a clone of this SerialArray
595      */
596     public Object clone() {
597         try {
598             SerialArray sa = (SerialArray) super.clone();
599             sa.elements = (elements != null) ? Arrays.copyOf(elements, len) : null;
600             return sa;
601         } catch (CloneNotSupportedException ex) {
602             // this shouldn't happen, since we are Cloneable
603             throw new InternalError();
604         }
605 
606     }
607 
608     /**
609      * readObject is called to restore the state of the {@code SerialArray} from
610      * a stream.





611      */
612     private void readObject(ObjectInputStream s)
613             throws IOException, ClassNotFoundException {
614 
615        ObjectInputStream.GetField fields = s.readFields();
616        Object[] tmp = (Object[])fields.get("elements", null);
617        if (tmp == null)
618            throw new InvalidObjectException("elements is null and should not be!");
619        elements = tmp.clone();
620        len = fields.get("len", 0);
621        if(elements.length != len)
622            throw new InvalidObjectException("elements is not the expected size");
623 
624        baseType = fields.get("baseType", 0);
625        baseTypeName = (String)fields.get("baseTypeName", null);
626     }
627 
628     /**
629      * writeObject is called to save the state of the {@code SerialArray}
630      * to a stream.


631      */
632     private void writeObject(ObjectOutputStream s)
633             throws IOException {
634 
635         ObjectOutputStream.PutField fields = s.putFields();
636         fields.put("elements", elements);
637         fields.put("len", len);
638         fields.put("baseType", baseType);
639         fields.put("baseTypeName", baseTypeName);
640         s.writeFields();
641     }
642 
643     /**
644      * Check to see if this object had previously had its {@code free} method
645      * called
646      *
647      * @throws SerialException
648      */
649     private void isValid() throws SerialException {
650         if (elements == null) {

  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

591      * reference to a clone of the underlying objects array, not a reference
592      * to the original underlying object array of this {@code SerialArray} object.
593      *
594      * @return a clone of this SerialArray
595      */
596     public Object clone() {
597         try {
598             SerialArray sa = (SerialArray) super.clone();
599             sa.elements = (elements != null) ? Arrays.copyOf(elements, len) : null;
600             return sa;
601         } catch (CloneNotSupportedException ex) {
602             // this shouldn't happen, since we are Cloneable
603             throw new InternalError();
604         }
605 
606     }
607 
608     /**
609      * readObject is called to restore the state of the {@code SerialArray} from
610      * a stream.
611      * @param s the {@code ObjectInputStream} to read from.
612      *
613      * @throws  ClassNotFoundException if the class of a serialized object
614      *          could not be found.
615      * @throws  IOException if an I/O error occurs.
616      */
617     private void readObject(ObjectInputStream s)
618             throws IOException, ClassNotFoundException {
619 
620        ObjectInputStream.GetField fields = s.readFields();
621        Object[] tmp = (Object[])fields.get("elements", null);
622        if (tmp == null)
623            throw new InvalidObjectException("elements is null and should not be!");
624        elements = tmp.clone();
625        len = fields.get("len", 0);
626        if(elements.length != len)
627            throw new InvalidObjectException("elements is not the expected size");
628 
629        baseType = fields.get("baseType", 0);
630        baseTypeName = (String)fields.get("baseTypeName", null);
631     }
632 
633     /**
634      * writeObject is called to save the state of the {@code SerialArray}
635      * to a stream.
636      * @param s the {@code ObjectOutputStream} to write to.
637      + @throws  IOException if I/O errors occur.
638      */
639     private void writeObject(ObjectOutputStream s)
640             throws IOException {
641 
642         ObjectOutputStream.PutField fields = s.putFields();
643         fields.put("elements", elements);
644         fields.put("len", len);
645         fields.put("baseType", baseType);
646         fields.put("baseTypeName", baseTypeName);
647         s.writeFields();
648     }
649 
650     /**
651      * Check to see if this object had previously had its {@code free} method
652      * called
653      *
654      * @throws SerialException
655      */
656     private void isValid() throws SerialException {
657         if (elements == null) {
< prev index next >