jdk/src/share/classes/java/time/chrono/HijrahDate.java
changeset 19841 15c8e97d6a14
parent 19030 32f129cb6351
child 20518 dde564773845
equal deleted inserted replaced
19822:4e10a58fa28f 19841:15c8e97d6a14
    63 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
    63 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
    64 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
    64 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
    65 import static java.time.temporal.ChronoField.YEAR;
    65 import static java.time.temporal.ChronoField.YEAR;
    66 
    66 
    67 import java.io.IOException;
    67 import java.io.IOException;
       
    68 import java.io.InvalidObjectException;
    68 import java.io.ObjectInput;
    69 import java.io.ObjectInput;
    69 import java.io.ObjectOutput;
    70 import java.io.ObjectOutput;
    70 import java.io.Serializable;
    71 import java.io.Serializable;
    71 import java.time.Clock;
    72 import java.time.Clock;
    72 import java.time.DateTimeException;
    73 import java.time.DateTimeException;
   116      */
   117      */
   117     private static final long serialVersionUID = -5207853542612002020L;
   118     private static final long serialVersionUID = -5207853542612002020L;
   118     /**
   119     /**
   119      * The Chronology of this HijrahDate.
   120      * The Chronology of this HijrahDate.
   120      */
   121      */
   121     private final HijrahChronology chrono;
   122     private final transient HijrahChronology chrono;
   122     /**
   123     /**
   123      * The proleptic year.
   124      * The proleptic year.
   124      */
   125      */
   125     private final transient int prolepticYear;
   126     private final transient int prolepticYear;
   126     /**
   127     /**
   598         int months = (int) (totalMonths % 12);  // safe
   599         int months = (int) (totalMonths % 12);  // safe
   599         return Period.of(Math.toIntExact(years), months, days);
   600         return Period.of(Math.toIntExact(years), months, days);
   600     }
   601     }
   601 
   602 
   602     //-----------------------------------------------------------------------
   603     //-----------------------------------------------------------------------
       
   604     /**
       
   605      * Defend against malicious streams.
       
   606      * @return never
       
   607      * @throws InvalidObjectException always
       
   608      */
       
   609     private Object readResolve() throws InvalidObjectException {
       
   610         throw new InvalidObjectException("Deserialization via serialization delegate");
       
   611     }
       
   612 
       
   613     /**
       
   614      * Writes the object using a
       
   615      * <a href="../../../serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
       
   616      * @serialData
       
   617      * <pre>
       
   618      *  out.writeByte(6);                 // identifies a HijrahDate
       
   619      *  out.writeObject(chrono);          // the HijrahChronology variant
       
   620      *  out.writeInt(get(YEAR));
       
   621      *  out.writeByte(get(MONTH_OF_YEAR));
       
   622      *  out.writeByte(get(DAY_OF_MONTH));
       
   623      * </pre>
       
   624      *
       
   625      * @return the instance of {@code Ser}, not null
       
   626      */
   603     private Object writeReplace() {
   627     private Object writeReplace() {
   604         return new Ser(Ser.HIJRAH_DATE_TYPE, this);
   628         return new Ser(Ser.HIJRAH_DATE_TYPE, this);
   605     }
   629     }
   606 
   630 
   607     void writeExternal(ObjectOutput out) throws IOException {
   631     void writeExternal(ObjectOutput out) throws IOException {
   608         // HijrahChronology is implicit in the Hijrah_DATE_TYPE
   632         // HijrahChronology is implicit in the Hijrah_DATE_TYPE
   609         out.writeObject(chrono);
   633         out.writeObject(getChronology());
   610         out.writeInt(get(YEAR));
   634         out.writeInt(get(YEAR));
   611         out.writeByte(get(MONTH_OF_YEAR));
   635         out.writeByte(get(MONTH_OF_YEAR));
   612         out.writeByte(get(DAY_OF_MONTH));
   636         out.writeByte(get(DAY_OF_MONTH));
   613     }
       
   614 
       
   615     /**
       
   616      * Replaces the date instance from the stream with a valid one.
       
   617      * ReadExternal has already read the fields and created a new instance
       
   618      * from the data.
       
   619      *
       
   620      * @return the resolved date, never null
       
   621      */
       
   622     private Object readResolve() {
       
   623         return this;
       
   624     }
   637     }
   625 
   638 
   626     static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   639     static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   627         HijrahChronology chrono = (HijrahChronology) in.readObject();
   640         HijrahChronology chrono = (HijrahChronology) in.readObject();
   628         int year = in.readInt();
   641         int year = in.readInt();