72 * This class wraps the object being serialized, and takes a byte representing the type of the class to |
72 * This class wraps the object being serialized, and takes a byte representing the type of the class to |
73 * be serialized. This byte can also be used for versioning the serialization format. In this case another |
73 * be serialized. This byte can also be used for versioning the serialization format. In this case another |
74 * byte flag would be used in order to specify an alternative version of the type format. |
74 * byte flag would be used in order to specify an alternative version of the type format. |
75 * For example {@code CHRONO_TYPE_VERSION_2 = 21} |
75 * For example {@code CHRONO_TYPE_VERSION_2 = 21} |
76 * <p> |
76 * <p> |
77 * In order to serialise the object it writes its byte and then calls back to the appropriate class where |
77 * In order to serialize the object it writes its byte and then calls back to the appropriate class where |
78 * the serialisation is performed. In order to deserialise the object it read in the type byte, switching |
78 * the serialization is performed. In order to deserialize the object it read in the type byte, switching |
79 * in order to select which class to call back into. |
79 * in order to select which class to call back into. |
80 * <p> |
80 * <p> |
81 * The serialisation format is determined on a per class basis. In the case of field based classes each |
81 * The serialization format is determined on a per class basis. In the case of field based classes each |
82 * of the fields is written out with an appropriate size format in descending order of the field's size. For |
82 * of the fields is written out with an appropriate size format in descending order of the field's size. For |
83 * example in the case of {@link LocalDate} year is written before month. Composite classes, such as |
83 * example in the case of {@link LocalDate} year is written before month. Composite classes, such as |
84 * {@link LocalDateTime} are serialised as one object. Enum classes are serialised using the index of their |
84 * {@link LocalDateTime} are serialized as one object. Enum classes are serialized using the index of their |
85 * element. |
85 * element. |
86 * <p> |
86 * <p> |
87 * This class is mutable and should be created once per serialization. |
87 * This class is mutable and should be created once per serialization. |
88 * |
88 * |
89 * @serial include |
89 * @serial include |
100 static final byte CHRONO_LOCAL_DATE_TIME_TYPE = 2; |
100 static final byte CHRONO_LOCAL_DATE_TIME_TYPE = 2; |
101 static final byte CHRONO_ZONE_DATE_TIME_TYPE = 3; |
101 static final byte CHRONO_ZONE_DATE_TIME_TYPE = 3; |
102 static final byte JAPANESE_DATE_TYPE = 4; |
102 static final byte JAPANESE_DATE_TYPE = 4; |
103 static final byte JAPANESE_ERA_TYPE = 5; |
103 static final byte JAPANESE_ERA_TYPE = 5; |
104 static final byte HIJRAH_DATE_TYPE = 6; |
104 static final byte HIJRAH_DATE_TYPE = 6; |
105 static final byte HIJRAH_ERA_TYPE = 7; |
105 static final byte MINGUO_DATE_TYPE = 7; |
106 static final byte MINGUO_DATE_TYPE = 8; |
106 static final byte THAIBUDDHIST_DATE_TYPE = 8; |
107 static final byte MINGUO_ERA_TYPE = 9; |
|
108 static final byte THAIBUDDHIST_DATE_TYPE = 10; |
|
109 static final byte THAIBUDDHIST_ERA_TYPE = 11; |
|
110 |
107 |
111 /** The type being serialized. */ |
108 /** The type being serialized. */ |
112 private byte type; |
109 private byte type; |
113 /** The object being serialized. */ |
110 /** The object being serialized. */ |
114 private Object object; |
111 private Object object; |
131 } |
128 } |
132 |
129 |
133 //----------------------------------------------------------------------- |
130 //----------------------------------------------------------------------- |
134 /** |
131 /** |
135 * Implements the {@code Externalizable} interface to write the object. |
132 * Implements the {@code Externalizable} interface to write the object. |
|
133 * @serialData |
|
134 * Each serializable class is mapped to a type that is the first byte |
|
135 * in the stream. Refer to each class {@code writeReplace} |
|
136 * serialized form for the value of the type and sequence of values for the type. |
|
137 * <ul> |
|
138 * <li><a href="../../../serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology.writeReplace</a> |
|
139 * <li><a href="../../../serialized-form.html#java.time.chrono.IsoChronology">IsoChronology.writeReplace</a> |
|
140 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology.writeReplace</a> |
|
141 * <li><a href="../../../serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology.writeReplace</a> |
|
142 * <li><a href="../../../serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology.writeReplace</a> |
|
143 * <li><a href="../../../serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime.writeReplace</a> |
|
144 * <li><a href="../../../serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime.writeReplace</a> |
|
145 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate.writeReplace</a> |
|
146 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra.writeReplace</a> |
|
147 * <li><a href="../../../serialized-form.html#java.time.chrono.HijrahDate">HijrahDate.writeReplace</a> |
|
148 * <li><a href="../../../serialized-form.html#java.time.chrono.MinguoDate">MinguoDate.writeReplace</a> |
|
149 * <li><a href="../../../serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate.writeReplace</a> |
|
150 * </ul> |
136 * |
151 * |
137 * @param out the data stream to write to, not null |
152 * @param out the data stream to write to, not null |
138 */ |
153 */ |
139 @Override |
154 @Override |
140 public void writeExternal(ObjectOutput out) throws IOException { |
155 public void writeExternal(ObjectOutput out) throws IOException { |
160 ((JapaneseEra) object).writeExternal(out); |
175 ((JapaneseEra) object).writeExternal(out); |
161 break; |
176 break; |
162 case HIJRAH_DATE_TYPE: |
177 case HIJRAH_DATE_TYPE: |
163 ((HijrahDate) object).writeExternal(out); |
178 ((HijrahDate) object).writeExternal(out); |
164 break; |
179 break; |
165 case HIJRAH_ERA_TYPE: |
|
166 ((HijrahEra) object).writeExternal(out); |
|
167 break; |
|
168 case MINGUO_DATE_TYPE: |
180 case MINGUO_DATE_TYPE: |
169 ((MinguoDate) object).writeExternal(out); |
181 ((MinguoDate) object).writeExternal(out); |
170 break; |
182 break; |
171 case MINGUO_ERA_TYPE: |
|
172 ((MinguoEra) object).writeExternal(out); |
|
173 break; |
|
174 case THAIBUDDHIST_DATE_TYPE: |
183 case THAIBUDDHIST_DATE_TYPE: |
175 ((ThaiBuddhistDate) object).writeExternal(out); |
184 ((ThaiBuddhistDate) object).writeExternal(out); |
176 break; |
|
177 case THAIBUDDHIST_ERA_TYPE: |
|
178 ((ThaiBuddhistEra) object).writeExternal(out); |
|
179 break; |
185 break; |
180 default: |
186 default: |
181 throw new InvalidClassException("Unknown serialized type"); |
187 throw new InvalidClassException("Unknown serialized type"); |
182 } |
188 } |
183 } |
189 } |
184 |
190 |
185 //----------------------------------------------------------------------- |
191 //----------------------------------------------------------------------- |
186 /** |
192 /** |
187 * Implements the {@code Externalizable} interface to read the object. |
193 * Implements the {@code Externalizable} interface to read the object. |
188 * |
194 * @serialData |
189 * @param in the data to read, not null |
195 * The streamed type and parameters defined by the type's {@code writeReplace} |
|
196 * method are read and passed to the corresponding static factory for the type |
|
197 * to create a new instance. That instance is returned as the de-serialized |
|
198 * {@code Ser} object. |
|
199 * |
|
200 * <ul> |
|
201 * <li><a href="../../../serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology</a> - Chronology.of(id) |
|
202 * <li><a href="../../../serialized-form.html#java.time.chrono.IsoChronology">IsoChronology</a> - Chronology.of(id) |
|
203 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology</a> - Chronology.of(id) |
|
204 * <li><a href="../../../serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology</a> - Chronology.of(id) |
|
205 * <li><a href="../../../serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology</a> - Chronology.of(id) |
|
206 * <li><a href="../../../serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime</a> - date.atTime(time) |
|
207 * <li><a href="../../../serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime</a> - dateTime.atZone(offset).withZoneSameLocal(zone) |
|
208 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate</a> - JapaneseChronology.INSTANCE.date(year, month, dayOfMonth) |
|
209 * <li><a href="../../../serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra</a> - JapaneseEra.of(eraValue) |
|
210 * <li><a href="../../../serialized-form.html#java.time.chrono.HijrahDate">HijrahDate</a> - HijrahChronology chrono.date(year, month, dayOfMonth) |
|
211 * <li><a href="../../../serialized-form.html#java.time.chrono.MinguoDate">MinguoDate</a> - MinguoChronology.INSTANCE.date(year, month, dayOfMonth) |
|
212 * <li><a href="../../../serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate</a> - ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth) |
|
213 * </ul> |
|
214 * |
|
215 * @param in the data stream to read from, not null |
190 */ |
216 */ |
191 @Override |
217 @Override |
192 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { |
218 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { |
193 type = in.readByte(); |
219 type = in.readByte(); |
194 object = readInternal(type, in); |
220 object = readInternal(type, in); |
205 case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in); |
231 case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in); |
206 case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in); |
232 case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in); |
207 case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in); |
233 case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in); |
208 case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in); |
234 case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in); |
209 case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in); |
235 case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in); |
210 case HIJRAH_ERA_TYPE: return HijrahEra.readExternal(in); |
|
211 case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in); |
236 case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in); |
212 case MINGUO_ERA_TYPE: return MinguoEra.readExternal(in); |
|
213 case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in); |
237 case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in); |
214 case THAIBUDDHIST_ERA_TYPE: return ThaiBuddhistEra.readExternal(in); |
|
215 default: throw new StreamCorruptedException("Unknown serialized type"); |
238 default: throw new StreamCorruptedException("Unknown serialized type"); |
216 } |
239 } |
217 } |
240 } |
218 |
241 |
219 /** |
242 /** |