jdk/src/share/classes/java/time/temporal/Ser.java
author sherman
Tue, 22 Jan 2013 20:59:21 -0800
changeset 15289 3ac550392e43
permissions -rw-r--r--
8003680: JSR 310 Date/Time API Summary: Integration of JSR310 Date/Time API for M6 Reviewed-by: alanb, naoto, dholmes Contributed-by: scolebourne@joda.org, roger.riggs@oracle.com, richard.warburton@gmail.com, misterm@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     4
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    10
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    15
 * accompanied this code).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    16
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    20
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    23
 * questions.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    24
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    25
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    26
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    27
 * Copyright (c) 2011-2012, Stephen Colebourne & Michael Nascimento Santos
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    28
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    29
 * All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    30
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    31
 * Redistribution and use in source and binary forms, with or without
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    32
 * modification, are permitted provided that the following conditions are met:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    33
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    34
 *  * Redistributions of source code must retain the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    35
 *    this list of conditions and the following disclaimer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    36
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    37
 *  * Redistributions in binary form must reproduce the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    38
 *    this list of conditions and the following disclaimer in the documentation
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    39
 *    and/or other materials provided with the distribution.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    40
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    41
 *  * Neither the name of JSR-310 nor the names of its contributors
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    42
 *    may be used to endorse or promote products derived from this software
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    43
 *    without specific prior written permission.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    44
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    45
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    46
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    47
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    48
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    49
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    50
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    51
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    52
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    53
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    54
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    55
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    56
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    57
package java.time.temporal;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    58
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    59
import java.io.Externalizable;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    60
import java.io.IOException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    61
import java.io.InvalidClassException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    62
import java.io.ObjectInput;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    63
import java.io.ObjectOutput;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    64
import java.io.StreamCorruptedException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
import java.time.LocalDate;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
import java.time.LocalDateTime;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    68
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
 * The shared serialization delegate for this package.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    70
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
 * <h3>Implementation notes</h3>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    72
 * This class wraps the object being serialized, and takes a byte representing the type of the class to
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    73
 * be serialized.  This byte can also be used for versioning the serialization format.  In this case another
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    74
 * byte flag would be used in order to specify an alternative version of the type format.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
 * For example {@code CHRONO_TYPE_VERSION_2 = 21}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    76
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    77
 * In order to serialise the object it writes its byte and then calls back to the appropriate class where
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * the serialisation is performed.  In order to deserialise the object it read in the type byte, switching
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * in order to select which class to call back into.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    80
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * The serialisation format is determined on a per class basis.  In the case of field based classes each
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    82
 * of the fields is written out with an appropriate size format in descending order of the field's size.  For
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    83
 * example in the case of {@link LocalDate} year is written before month.  Composite classes, such as
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    84
 * {@link LocalDateTime} are serialised as one object.  Enum classes are serialised using the index of their
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    85
 * element.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    86
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 * This class is mutable and should be created once per serialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    88
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 * @serial include
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
 * @since 1.8
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
final class Ser implements Externalizable {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    93
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    95
     * Serialization version.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
    private static final long serialVersionUID = -6103370247208168577L;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
    static final byte OFFSET_DATE_TYPE = 1;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
    static final byte OFFSET_TIME_TYPE = 2;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
    static final byte OFFSET_DATE_TIME_TYPE = 3;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
    static final byte YEAR_TYPE = 4;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
    static final byte YEAR_MONTH_TYPE = 5;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
    static final byte MONTH_DAY_TYPE = 6;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
    static final byte CHRONO_TYPE = 7;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   106
    static final byte CHRONO_LOCAL_DATE_TIME_TYPE = 8;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   107
    static final byte CHRONO_ZONE_DATE_TIME_TYPE = 9;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   108
    static final byte SIMPLE_PERIOD_TYPE = 10;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   109
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   110
    /** The type being serialized. */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   111
    private byte type;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
    /** The object being serialized. */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
    private Object object;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   116
     * Constructor for deserialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
    public Ser() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   121
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
     * Creates an instance for serialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   123
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
     * @param type  the type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   125
     * @param object  the object
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   126
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
    Ser(byte type, Object object) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
        this.type = type;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   129
        this.object = object;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   130
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
     * Implements the {@code Externalizable} interface to write the object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
     * @param out  the data stream to write to, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   138
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   139
    public void writeExternal(ObjectOutput out) throws IOException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   140
        writeInternal(type, object, out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   141
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   142
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   143
    private static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   144
        out.writeByte(type);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   145
        switch (type) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   146
            case OFFSET_DATE_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   147
                ((OffsetDate) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   148
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   149
            case OFFSET_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   150
                ((OffsetTime) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   151
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   152
            case OFFSET_DATE_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   153
                ((OffsetDateTime) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   154
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   155
            case YEAR_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   156
                ((Year) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   157
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   158
            case YEAR_MONTH_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
                ((YearMonth) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
            case MONTH_DAY_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   162
                ((MonthDay) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   163
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
            case CHRONO_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
                ((Chrono<?>) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   167
            case CHRONO_LOCAL_DATE_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
                ((ChronoLocalDateTimeImpl<?>) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
            case CHRONO_ZONE_DATE_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
                ((ChronoZonedDateTimeImpl<?>) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   172
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   173
            case SIMPLE_PERIOD_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
                ((SimplePeriod) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   175
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   176
            default:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
                throw new InvalidClassException("Unknown serialized type");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
     * Implements the {@code Externalizable} interface to read the object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
     * @param in  the data to read, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
        type = in.readByte();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
        object = readInternal(type, in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
    static Object read(ObjectInput in) throws IOException, ClassNotFoundException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   194
        byte type = in.readByte();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   195
        return readInternal(type, in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   196
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   197
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   198
    private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   199
        switch (type) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   200
            case OFFSET_DATE_TYPE: return OffsetDate.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   201
            case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   202
            case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   203
            case YEAR_TYPE: return Year.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   204
            case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   205
            case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   206
            case CHRONO_TYPE: return Chrono.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   207
            case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   208
            case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   209
            case SIMPLE_PERIOD_TYPE: return SimplePeriod.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   210
            default: throw new StreamCorruptedException("Unknown serialized type");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   211
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
     * Returns the object that will replace this one.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
     * @return the read object, should never be null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
    private Object readResolve() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   220
         return object;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   221
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   222
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   223
}