/* * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ /* * Copyright (c) 2011-2012, Stephen Colebourne & Michael Nascimento Santos * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of JSR-310 nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package java.time.chrono; import java.io.Externalizable; import java.io.IOException; import java.io.InvalidClassException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.StreamCorruptedException; import java.time.LocalDate; import java.time.LocalDateTime; /** * The shared serialization delegate for this package. * * @implNote * This class wraps the object being serialized, and takes a byte representing the type of the class to * be serialized. This byte can also be used for versioning the serialization format. In this case another * byte flag would be used in order to specify an alternative version of the type format. * For example {@code CHRONO_TYPE_VERSION_2 = 21} *
* In order to serialize the object it writes its byte and then calls back to the appropriate class where * the serialization is performed. In order to deserialize the object it read in the type byte, switching * in order to select which class to call back into. *
* The serialization format is determined on a per class basis. In the case of field based classes each * of the fields is written out with an appropriate size format in descending order of the field's size. For * example in the case of {@link LocalDate} year is written before month. Composite classes, such as * {@link LocalDateTime} are serialized as one object. Enum classes are serialized using the index of their * element. *
* This class is mutable and should be created once per serialization. * * @serial include * @since 1.8 */ final class Ser implements Externalizable { /** * Serialization version. */ private static final long serialVersionUID = -6103370247208168577L; static final byte CHRONO_TYPE = 1; static final byte CHRONO_LOCAL_DATE_TIME_TYPE = 2; static final byte CHRONO_ZONE_DATE_TIME_TYPE = 3; static final byte JAPANESE_DATE_TYPE = 4; static final byte JAPANESE_ERA_TYPE = 5; static final byte HIJRAH_DATE_TYPE = 6; static final byte MINGUO_DATE_TYPE = 7; static final byte THAIBUDDHIST_DATE_TYPE = 8; static final byte CHRONO_PERIOD_TYPE = 9; /** The type being serialized. */ private byte type; /** The object being serialized. */ private Object object; /** * Constructor for deserialization. */ public Ser() { } /** * Creates an instance for serialization. * * @param type the type * @param object the object */ Ser(byte type, Object object) { this.type = type; this.object = object; } //----------------------------------------------------------------------- /** * Implements the {@code Externalizable} interface to write the object. * @serialData * Each serializable class is mapped to a type that is the first byte * in the stream. Refer to each class {@code writeReplace} * serialized form for the value of the type and sequence of values for the type. *