< prev index next >

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

301      * reference to a clone of the underlying attribs array, not a reference
302      * to the original underlying attribs array of this {@code SerialStruct} object.
303      *
304      * @return  a clone of this SerialStruct
305      */
306     public Object clone() {
307         try {
308             SerialStruct ss = (SerialStruct) super.clone();
309             ss.attribs = Arrays.copyOf(attribs, attribs.length);
310             return ss;
311         } catch (CloneNotSupportedException ex) {
312             // this shouldn't happen, since we are Cloneable
313             throw new InternalError();
314         }
315 
316     }
317 
318     /**
319      * readObject is called to restore the state of the {@code SerialStruct} from
320      * a stream.





321      */
322     private void readObject(ObjectInputStream s)
323             throws IOException, ClassNotFoundException {
324 
325        ObjectInputStream.GetField fields = s.readFields();
326        Object[] tmp = (Object[])fields.get("attribs", null);
327        attribs = tmp == null ? null : tmp.clone();
328        SQLTypeName = (String)fields.get("SQLTypeName", null);
329     }
330 
331     /**
332      * writeObject is called to save the state of the {@code SerialStruct}
333      * to a stream.


334      */
335     private void writeObject(ObjectOutputStream s)
336             throws IOException {
337 
338         ObjectOutputStream.PutField fields = s.putFields();
339         fields.put("attribs", attribs);
340         fields.put("SQLTypeName", SQLTypeName);
341         s.writeFields();
342     }
343 
344     /**
345      * The identifier that assists in the serialization of this
346      * <code>SerialStruct</code> object.
347      */
348     static final long serialVersionUID = -8322445504027483372L;
349 }

  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

301      * reference to a clone of the underlying attribs array, not a reference
302      * to the original underlying attribs array of this {@code SerialStruct} object.
303      *
304      * @return  a clone of this SerialStruct
305      */
306     public Object clone() {
307         try {
308             SerialStruct ss = (SerialStruct) super.clone();
309             ss.attribs = Arrays.copyOf(attribs, attribs.length);
310             return ss;
311         } catch (CloneNotSupportedException ex) {
312             // this shouldn't happen, since we are Cloneable
313             throw new InternalError();
314         }
315 
316     }
317 
318     /**
319      * readObject is called to restore the state of the {@code SerialStruct} from
320      * a stream.
321      * @param s the {@code ObjectInputStream} to read from.
322      *
323      * @throws  ClassNotFoundException if the class of a serialized object
324      *          could not be found.
325      * @throws  IOException if an I/O error occurs.
326      */
327     private void readObject(ObjectInputStream s)
328             throws IOException, ClassNotFoundException {
329 
330        ObjectInputStream.GetField fields = s.readFields();
331        Object[] tmp = (Object[])fields.get("attribs", null);
332        attribs = tmp == null ? null : tmp.clone();
333        SQLTypeName = (String)fields.get("SQLTypeName", null);
334     }
335 
336     /**
337      * writeObject is called to save the state of the {@code SerialStruct}
338      * to a stream.
339      * @param s the {@code ObjectOutputStream} to write to.
340      + @throws  IOException if I/O errors occur.
341      */
342     private void writeObject(ObjectOutputStream s)
343             throws IOException {
344 
345         ObjectOutputStream.PutField fields = s.putFields();
346         fields.put("attribs", attribs);
347         fields.put("SQLTypeName", SQLTypeName);
348         s.writeFields();
349     }
350 
351     /**
352      * The identifier that assists in the serialization of this
353      * <code>SerialStruct</code> object.
354      */
355     static final long serialVersionUID = -8322445504027483372L;
356 }
< prev index next >