src/java.base/share/classes/java/time/chrono/Ser.java
changeset 58362 628c12967b02
parent 57956 e0b8b019d2f5
child 58679 9c3209ff7550
equal deleted inserted replaced
58361:ad863044567e 58362:628c12967b02
    59 import java.io.Externalizable;
    59 import java.io.Externalizable;
    60 import java.io.IOException;
    60 import java.io.IOException;
    61 import java.io.InvalidClassException;
    61 import java.io.InvalidClassException;
    62 import java.io.ObjectInput;
    62 import java.io.ObjectInput;
    63 import java.io.ObjectOutput;
    63 import java.io.ObjectOutput;
       
    64 import java.io.Serializable;
    64 import java.io.StreamCorruptedException;
    65 import java.io.StreamCorruptedException;
    65 import java.time.LocalDate;
    66 import java.time.LocalDate;
    66 import java.time.LocalDateTime;
    67 import java.time.LocalDateTime;
    67 
    68 
    68 /**
    69 /**
   108     static final byte CHRONO_PERIOD_TYPE = 9;
   109     static final byte CHRONO_PERIOD_TYPE = 9;
   109 
   110 
   110     /** The type being serialized. */
   111     /** The type being serialized. */
   111     private byte type;
   112     private byte type;
   112     /** The object being serialized. */
   113     /** The object being serialized. */
   113     private Object object;
   114     private Serializable object;
   114 
   115 
   115     /**
   116     /**
   116      * Constructor for deserialization.
   117      * Constructor for deserialization.
   117      */
   118      */
   118     public Ser() {
   119     public Ser() {
   122      * Creates an instance for serialization.
   123      * Creates an instance for serialization.
   123      *
   124      *
   124      * @param type  the type
   125      * @param type  the type
   125      * @param object  the object
   126      * @param object  the object
   126      */
   127      */
   127     Ser(byte type, Object object) {
   128     Ser(byte type, Serializable object) {
   128         this.type = type;
   129         this.type = type;
   129         this.object = object;
   130         this.object = object;
   130     }
   131     }
   131 
   132 
   132     //-----------------------------------------------------------------------
   133     //-----------------------------------------------------------------------
   201      * method are read and passed to the corresponding static factory for the type
   202      * method are read and passed to the corresponding static factory for the type
   202      * to create a new instance.  That instance is returned as the de-serialized
   203      * to create a new instance.  That instance is returned as the de-serialized
   203      * {@code Ser} object.
   204      * {@code Ser} object.
   204      *
   205      *
   205      * <ul>
   206      * <ul>
   206      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology</a> - Chronology.of(id)
   207      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology</a> -
   207      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.IsoChronology">IsoChronology</a> - Chronology.of(id)
   208      *          Chronology.of(id)
   208      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology</a> - Chronology.of(id)
   209      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.IsoChronology">IsoChronology</a> -
   209      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology</a> - Chronology.of(id)
   210      *          Chronology.of(id)
   210      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology</a> - Chronology.of(id)
   211      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology</a> -
   211      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime</a> - date.atTime(time)
   212      *          Chronology.of(id)
   212      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime</a> - dateTime.atZone(offset).withZoneSameLocal(zone)
   213      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology</a> -
   213      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate</a> - JapaneseChronology.INSTANCE.date(year, month, dayOfMonth)
   214      *          Chronology.of(id)
   214      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra</a> - JapaneseEra.of(eraValue)
   215      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology</a> -
   215      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahDate">HijrahDate</a> - HijrahChronology chrono.date(year, month, dayOfMonth)
   216      *          Chronology.of(id)
   216      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoDate">MinguoDate</a> - MinguoChronology.INSTANCE.date(year, month, dayOfMonth)
   217      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime</a> -
   217      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate</a> - ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth)
   218      *          date.atTime(time)
       
   219      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime</a> -
       
   220      *          dateTime.atZone(offset).withZoneSameLocal(zone)
       
   221      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate</a> -
       
   222      *          JapaneseChronology.INSTANCE.date(year, month, dayOfMonth)
       
   223      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra</a> -
       
   224      *          JapaneseEra.of(eraValue)
       
   225      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahDate">HijrahDate</a> -
       
   226      *          HijrahChronology chrono.date(year, month, dayOfMonth)
       
   227      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoDate">MinguoDate</a> -
       
   228      *          MinguoChronology.INSTANCE.date(year, month, dayOfMonth)
       
   229      * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate</a> -
       
   230      *          ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth)
   218      * </ul>
   231      * </ul>
   219      *
   232      *
   220      * @param in  the data stream to read from, not null
   233      * @param in  the data stream to read from, not null
   221      */
   234      */
   222     @Override
   235     @Override
   223     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   236     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   224         type = in.readByte();
   237         type = in.readByte();
   225         object = readInternal(type, in);
   238         object = readInternal(type, in);
   226     }
   239     }
   227 
   240 
   228     static Object read(ObjectInput in) throws IOException, ClassNotFoundException {
   241     static Serializable read(ObjectInput in) throws IOException, ClassNotFoundException {
   229         byte type = in.readByte();
   242         byte type = in.readByte();
   230         return readInternal(type, in);
   243         return readInternal(type, in);
   231     }
   244     }
   232 
   245 
   233     private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
   246     private static Serializable readInternal(byte type, ObjectInput in)
       
   247             throws IOException, ClassNotFoundException {
   234         switch (type) {
   248         switch (type) {
   235             case CHRONO_TYPE: return AbstractChronology.readExternal(in);
   249             case CHRONO_TYPE: return (Serializable)AbstractChronology.readExternal(in);
   236             case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
   250             case CHRONO_LOCAL_DATE_TIME_TYPE: return (Serializable)ChronoLocalDateTimeImpl.readExternal(in);
   237             case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
   251             case CHRONO_ZONE_DATE_TIME_TYPE: return (Serializable)ChronoZonedDateTimeImpl.readExternal(in);
   238             case JAPANESE_DATE_TYPE:  return JapaneseDate.readExternal(in);
   252             case JAPANESE_DATE_TYPE:  return JapaneseDate.readExternal(in);
   239             case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in);
   253             case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in);
   240             case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in);
   254             case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in);
   241             case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in);
   255             case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in);
   242             case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in);
   256             case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in);