src/java.base/share/classes/java/time/Ser.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58362 628c12967b02
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52078
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
15289
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;
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;
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
    64
import java.io.Serializable;
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
import java.io.StreamCorruptedException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    68
 * The shared serialization delegate for this package.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
 *
17474
8c100beabcc0 8013730: JSR 310 DateTime API Updates III
sherman
parents: 15658
diff changeset
    70
 * @implNote
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
 * 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
    72
 * 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
    73
 * 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
    74
 * For example {@code LOCAL_DATE_TYPE_VERSION_2 = 21}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
 * <p>
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
    76
 * In order to serialize the object it writes its byte and then calls back to the appropriate class where
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
    77
 * the serialization is performed.  In order to deserialize the object it read in the type byte, switching
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * in order to select which class to call back into.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * <p>
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
    80
 * The serialization format is determined on a per class basis.  In the case of field based classes each
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * 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
    82
 * example in the case of {@link LocalDate} year is written before month.  Composite classes, such as
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
    83
 * {@link LocalDateTime} are serialized as one object.
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    84
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    85
 * This class is mutable and should be created once per serialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    86
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 * @serial include
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    88
 * @since 1.8
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
final class Ser implements Externalizable {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    93
     * Serialization version.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52078
diff changeset
    95
    @java.io.Serial
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
    private static final long serialVersionUID = -7683839454370182990L;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
    static final byte DURATION_TYPE = 1;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
    static final byte INSTANT_TYPE = 2;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
    static final byte LOCAL_DATE_TYPE = 3;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
    static final byte LOCAL_TIME_TYPE = 4;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
    static final byte LOCAL_DATE_TIME_TYPE = 5;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
    static final byte ZONE_DATE_TIME_TYPE = 6;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
    static final byte ZONE_REGION_TYPE = 7;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
    static final byte ZONE_OFFSET_TYPE = 8;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   106
    static final byte OFFSET_TIME_TYPE = 9;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   107
    static final byte OFFSET_DATE_TIME_TYPE = 10;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   108
    static final byte YEAR_TYPE = 11;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   109
    static final byte YEAR_MONTH_TYPE = 12;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   110
    static final byte MONTH_DAY_TYPE = 13;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   111
    static final byte PERIOD_TYPE = 14;
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
    /** The type being serialized. */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
    private byte type;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
    /** The object being serialized. */
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   116
    private Serializable object;
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
     * Constructor for deserialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   121
    public Ser() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   123
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   125
     * Creates an instance for serialization.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   126
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
     * @param type  the type
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
     * @param object  the object
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   129
     */
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   130
    Ser(byte type, Serializable object) {
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
        this.type = type;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
        this.object = object;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
     * Implements the {@code Externalizable} interface to write the object.
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   138
     * @serialData
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   139
     *
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   140
     * Each serializable class is mapped to a type that is the first byte
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   141
     * in the stream.  Refer to each class {@code writeReplace}
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   142
     * serialized form for the value of the type and sequence of values for the type.
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   143
     * <ul>
52078
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   144
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Duration">Duration.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   145
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Instant">Instant.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   146
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDate">LocalDate.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   147
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDateTime">LocalDateTime.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   148
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalTime">LocalTime.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   149
     * <li><a href="{@docRoot}/serialized-form.html#java.time.MonthDay">MonthDay.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   150
     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetTime">OffsetTime.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   151
     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetDateTime">OffsetDateTime.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   152
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Period">Period.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   153
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Year">Year.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   154
     * <li><a href="{@docRoot}/serialized-form.html#java.time.YearMonth">YearMonth.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   155
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneId">ZoneId.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   156
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">ZoneOffset.writeReplace</a>
4a63197816ce 8211952: Broken links in java.time API
jjg
parents: 47216
diff changeset
   157
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZonedDateTime">ZonedDateTime.writeReplace</a>
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   158
     * </ul>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
     * @param out  the data stream to write to, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
     */
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   162
    @Override
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   163
    public void writeExternal(ObjectOutput out) throws IOException {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
        writeInternal(type, object, out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   167
    static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
        out.writeByte(type);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
        switch (type) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
            case DURATION_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
                ((Duration) 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 INSTANT_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
                ((Instant) 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
            case LOCAL_DATE_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
                ((LocalDate) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
            case LOCAL_DATE_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
                ((LocalDateTime) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
            case LOCAL_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
                ((LocalTime) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
            case ZONE_REGION_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
                ((ZoneRegion) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
            case ZONE_OFFSET_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
                ((ZoneOffset) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
                break;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
            case ZONE_DATE_TIME_TYPE:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
                ((ZonedDateTime) object).writeExternal(out);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
                break;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   194
            case OFFSET_TIME_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   195
                ((OffsetTime) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   196
                break;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   197
            case OFFSET_DATE_TIME_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   198
                ((OffsetDateTime) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   199
                break;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   200
            case YEAR_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   201
                ((Year) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   202
                break;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   203
            case YEAR_MONTH_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   204
                ((YearMonth) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   205
                break;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   206
            case MONTH_DAY_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   207
                ((MonthDay) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   208
                break;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   209
            case PERIOD_TYPE:
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   210
                ((Period) object).writeExternal(out);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   211
                break;
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
            default:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
                throw new InvalidClassException("Unknown serialized type");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
     * Implements the {@code Externalizable} interface to read the object.
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   220
     * @serialData
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   221
     *
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   222
     * The streamed type and parameters defined by the type's {@code writeReplace}
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   223
     * method are read and passed to the corresponding static factory for the type
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   224
     * to create a new instance.  That instance is returned as the de-serialized
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   225
     * {@code Ser} object.
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   226
     *
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   227
     * <ul>
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   228
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Duration">Duration</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   229
     *          {@code Duration.ofSeconds(seconds, nanos);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   230
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Instant">Instant</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   231
     *          {@code Instant.ofEpochSecond(seconds, nanos);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   232
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDate">LocalDate</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   233
     *          {@code LocalDate.of(year, month, day);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   234
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDateTime">LocalDateTime</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   235
     *          {@code LocalDateTime.of(date, time);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   236
     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalTime">LocalTime</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   237
     *          {@code LocalTime.of(hour, minute, second, nano);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   238
     * <li><a href="{@docRoot}/serialized-form.html#java.time.MonthDay">MonthDay</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   239
     *          {@code MonthDay.of(month, day);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   240
     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetTime">OffsetTime</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   241
     *          {@code OffsetTime.of(time, offset);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   242
     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetDateTime">OffsetDateTime</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   243
     *          {@code OffsetDateTime.of(dateTime, offset);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   244
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Period">Period</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   245
     *          {@code Period.of(years, months, days);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   246
     * <li><a href="{@docRoot}/serialized-form.html#java.time.Year">Year</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   247
     *          {@code Year.of(year);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   248
     * <li><a href="{@docRoot}/serialized-form.html#java.time.YearMonth">YearMonth</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   249
     *          {@code YearMonth.of(year, month);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   250
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZonedDateTime">ZonedDateTime</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   251
     *          {@code ZonedDateTime.ofLenient(dateTime, offset, zone);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   252
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneId">ZoneId</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   253
     *          {@code ZoneId.of(id);}
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   254
     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">ZoneOffset</a> -
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   255
     *          {@code (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) :
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   256
     *          ZoneOffset.ofTotalSeconds(offsetByte * 900));}
19841
15c8e97d6a14 8024164: JSR310 serialization should be described in details
rriggs
parents: 17474
diff changeset
   257
     * </ul>
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   258
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   259
     * @param in  the data to read, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   260
     */
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   261
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   262
        type = in.readByte();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   263
        object = readInternal(type, in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   264
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   265
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   266
    static Serializable read(ObjectInput in) throws IOException, ClassNotFoundException {
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   267
        byte type = in.readByte();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   268
        return readInternal(type, in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   269
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   270
58362
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   271
    private static Serializable readInternal(byte type, ObjectInput in)
628c12967b02 8231314: java.time serialization warning cleanup
rriggs
parents: 57956
diff changeset
   272
            throws IOException, ClassNotFoundException {
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   273
        switch (type) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   274
            case DURATION_TYPE: return Duration.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   275
            case INSTANT_TYPE: return Instant.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   276
            case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   277
            case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   278
            case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   279
            case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   280
            case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   281
            case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   282
            case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   283
            case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   284
            case YEAR_TYPE: return Year.readExternal(in);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   285
            case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   286
            case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15289
diff changeset
   287
            case PERIOD_TYPE: return Period.readExternal(in);
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   288
            default:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   289
                throw new StreamCorruptedException("Unknown serialized type");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   290
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   291
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   292
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   293
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   294
     * Returns the object that will replace this one.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   295
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   296
     * @return the read object, should never be null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   297
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 52078
diff changeset
   298
    @java.io.Serial
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   299
    private Object readResolve() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   300
         return object;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   301
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   302
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   303
}