src/share/classes/java/time/chrono/Ser.java

Print this page

        

*** 52,62 **** * 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.calendar; import java.io.Externalizable; import java.io.IOException; import java.io.InvalidClassException; import java.io.ObjectInput; --- 52,62 ---- * 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;
*** 70,80 **** * * <h3>Implementation notes</h3> * 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 JAPANESE_DATE_TYPE_VERSION_2 = 21}. * <p> * In order to serialise the object it writes its byte and then calls back to the appropriate class where * the serialisation is performed. In order to deserialise the object it read in the type byte, switching * in order to select which class to call back into. * <p> --- 70,80 ---- * * <h3>Implementation notes</h3> * 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} * <p> * In order to serialise the object it writes its byte and then calls back to the appropriate class where * the serialisation is performed. In order to deserialise the object it read in the type byte, switching * in order to select which class to call back into. * <p>
*** 92,111 **** final class Ser implements Externalizable { /** * Serialization version. */ ! private static final long serialVersionUID = 7857518227608961174L; ! static final byte JAPANESE_DATE_TYPE = 1; ! static final byte JAPANESE_ERA_TYPE = 2; ! static final byte HIJRAH_DATE_TYPE = 3; ! static final byte HIJRAH_ERA_TYPE = 4; ! static final byte MINGUO_DATE_TYPE = 5; ! static final byte MINGUO_ERA_TYPE = 6; ! static final byte THAIBUDDHIST_DATE_TYPE = 7; ! static final byte THAIBUDDHIST_ERA_TYPE = 8; /** The type being serialized. */ private byte type; /** The object being serialized. */ private Object object; --- 92,114 ---- 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 HIJRAH_ERA_TYPE = 7; ! static final byte MINGUO_DATE_TYPE = 8; ! static final byte MINGUO_ERA_TYPE = 9; ! static final byte THAIBUDDHIST_DATE_TYPE = 10; ! static final byte THAIBUDDHIST_ERA_TYPE = 11; /** The type being serialized. */ private byte type; /** The object being serialized. */ private Object object;
*** 139,148 **** --- 142,160 ---- } private static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException { out.writeByte(type); switch (type) { + case CHRONO_TYPE: + ((Chronology) object).writeExternal(out); + break; + case CHRONO_LOCAL_DATE_TIME_TYPE: + ((ChronoLocalDateTimeImpl<?>) object).writeExternal(out); + break; + case CHRONO_ZONE_DATE_TIME_TYPE: + ((ChronoZonedDateTimeImpl<?>) object).writeExternal(out); + break; case JAPANESE_DATE_TYPE: ((JapaneseDate) object).writeExternal(out); break; case JAPANESE_ERA_TYPE: ((JapaneseEra) object).writeExternal(out);
*** 187,206 **** return readInternal(type, in); } private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException { switch (type) { case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in); case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in); case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in); case HIJRAH_ERA_TYPE: return HijrahEra.readExternal(in); case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in); case MINGUO_ERA_TYPE: return MinguoEra.readExternal(in); case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in); case THAIBUDDHIST_ERA_TYPE: return ThaiBuddhistEra.readExternal(in); ! default: ! throw new StreamCorruptedException("Unknown serialized type"); } } /** * Returns the object that will replace this one. --- 199,220 ---- return readInternal(type, in); } private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException { switch (type) { + case CHRONO_TYPE: return Chronology.readExternal(in); + case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in); + case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in); case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in); case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in); case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in); case HIJRAH_ERA_TYPE: return HijrahEra.readExternal(in); case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in); case MINGUO_ERA_TYPE: return MinguoEra.readExternal(in); case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in); case THAIBUDDHIST_ERA_TYPE: return ThaiBuddhistEra.readExternal(in); ! default: throw new StreamCorruptedException("Unknown serialized type"); } } /** * Returns the object that will replace this one.