jdk/src/java.base/share/specs/serialization/class.md
author rriggs
Fri, 12 May 2017 15:15:43 -0400
changeset 45138 ddcafe0d0ea3
parent 44787 0b323ea6d5ad
child 45142 be2c212f16dd
permissions -rw-r--r--
8180082: Broken javadoc links Reviewed-by: mchung, bpb, chegar, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44787
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     1
---
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     2
# Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     4
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     7
# published by the Free Software Foundation.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     8
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    13
# accompanied this code).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    14
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    18
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    21
# questions.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    22
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    23
include-before: '[CONTENTS](index.html) | [PREV](input.html) | [NEXT](version.html)'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    24
include-after: '[CONTENTS](index.html) | [PREV](input.html) | [NEXT](version.html)'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    25
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    26
title: 'Java Object Serialization Specification: 4 - Class Descriptors'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    27
---
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    28
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    29
-   [The ObjectStreamClass Class](#the-objectstreamclass-class)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    30
-   [Dynamic Proxy Class Descriptors](#dynamic-proxy-class-descriptors)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    31
-   [Serialized Form](#serialized-form)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    32
-   [The ObjectStreamField Class](#the-objectstreamfield-class)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    33
-   [Inspecting Serializable Classes](#inspecting-serializable-classes)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    34
-   [Stream Unique Identifiers](#stream-unique-identifiers)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    35
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    36
-------------------------------------------------------------------------------
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    37
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    38
## 4.1 The ObjectStreamClass Class
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    39
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    40
The `ObjectStreamClass` provides information about classes that are saved in a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    41
Serialization stream. The descriptor provides the fully-qualified name of the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    42
class and its serialization version UID. A `SerialVersionUID` identifies the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    43
unique original class version for which this class is capable of writing
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    44
streams and from which it can read.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    45
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    46
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    47
package java.io;
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    48
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    49
public class ObjectStreamClass
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    50
{
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    51
    public static ObjectStreamClass lookup(Class cl);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    52
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    53
        public static ObjectStreamClass lookupAny(Class cl);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    54
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    55
    public String getName();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    56
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    57
    public Class forClass();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    58
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    59
    public ObjectStreamField[] getFields();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    60
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    61
    public long getSerialVersionUID();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    62
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    63
    public String toString();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    64
}
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    65
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    66
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    67
The `lookup` method returns the `ObjectStreamClass` descriptor for the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    68
specified class in the virtual machine. If the class has defined
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    69
`serialVersionUID` it is retrieved from the class. If the `serialVersionUID` is
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    70
not defined by the class, it is computed from the definition of the class in
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    71
the virtual machine. *I*f the specified class is not serializable or
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    72
externalizable, *null* is returned.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    73
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    74
The `lookupAny` method behaves like the `lookup` method, except that it returns
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    75
the descriptor for any class, regardless of whether it implements
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    76
`Serializable`. The `serialVersionUID` of a class that does not implement
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    77
`Serializable` is *0L.*
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    78
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    79
The `getName` method returns the name of the class, in the same format that is
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    80
used by the `Class.getName` method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    81
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    82
The `forClass` method returns the `Class` in the local virtual machine if one
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    83
was found by `ObjectInputStream.resolveClass` method. Otherwise, it returns
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    84
*null*.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    85
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    86
The `getFields` method returns an array of `ObjectStreamField` objects that
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    87
represent the serializable fields of this class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    88
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    89
The `getSerialVersionUID` method returns the `serialVersionUID` of this class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    90
Refer to [Section 4.6, "Stream Unique
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    91
Identifiers"](#stream-unique-identifiers). If not specified by the class, the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    92
value returned is a hash computed from the class's name, interfaces, methods,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    93
and fields using the Secure Hash Algorithm (SHA) as defined by the National
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    94
Institute of Standards.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    95
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    96
The `toString` method returns a printable representation of the class
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    97
descriptor including the name of the class and the `serialVersionUID`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    98
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    99
## 4.2 Dynamic Proxy Class Descriptors
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   100
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   101
ObjectStreamClass descriptors are also used to provide information about
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   102
dynamic proxy classes (e.g., classes obtained via calls to the getProxyClass
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   103
method of java.lang.reflect.Proxy) saved in a serialization stream. A dynamic
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   104
proxy class itself has no serializable fields and a serialVersionUID of 0L. In
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   105
other words, when the Class object for a dynamic proxy class is passed to the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   106
static lookup method of ObjectStreamClass, the returned ObjectStreamClass
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   107
instance will have the following properties:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   108
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   109
-   Invoking its getSerialVersionUID method will return 0L.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   110
-   Invoking its getFields method will return an array of length zero.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   111
-   Invoking its getField method with any String argument will return null.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   112
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   113
## 4.3 Serialized Form
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   114
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   115
The serialized form of an ObjectStreamClass instance depends on whether or not
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   116
the Class object it represents is serializable, externalizable, or a dynamic
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   117
proxy class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   118
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   119
When an `ObjectStreamClass` instance that does not represent a dynamic proxy
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   120
class is written to the stream, it writes the class name and
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   121
`serialVersionUID`, flags, and the number of fields. Depending on the class,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   122
additional information may be written:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   123
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   124
-   For non-serializable classes, the number of fields is always zero. Neither
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   125
    the `SC_SERIALIZABLE` nor the `SC_EXTERNALIZABLE` flag bits are set.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   126
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   127
-   For serializable classes, the `SC_SERIALIZABLE` flag is set, the number of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   128
    fields counts the number of serializable fields and is followed by a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   129
    descriptor for each serializable field. The descriptors are written in
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   130
    canonical order. The descriptors for primitive typed fields are written
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   131
    first sorted by field name followed by descriptors for the object typed
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   132
    fields sorted by field name. The names are sorted using `String.compareTo`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   133
    For details of the format, refer to [Section 6.4, "Grammar for the Stream
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   134
    Format"](protocol.html#grammar-for-the-stream-format).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   135
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   136
-   For externalizable classes, flags includes the `SC_EXTERNALIZABLE` flag,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   137
    and the number of fields is always zero.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   138
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   139
-   For enum types, flags includes the `SC_ENUM` flag, and the number of fields
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   140
    is always zero.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   141
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   142
When an ObjectOutputStream serializes the ObjectStreamClass descriptor for a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   143
dynamic proxy class, as determined by passing its Class object to the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   144
isProxyClass method of java.lang.reflect.Proxy, it writes the number of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   145
interfaces that the dynamic proxy class implements, followed by the interface
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   146
names. Interfaces are listed in the order that they are returned by invoking
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   147
the getInterfaces method on the Class object of the dynamic proxy class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   148
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   149
The serialized representations of ObjectStreamClass descriptors for dynamic
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   150
proxy classes and non-dynamic proxy classes are differentiated through the use
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   151
of different typecodes (`TC_PROXYCLASSDESC` and `TC_CLASSDESC`, respectively);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   152
for a more detailed specification of the grammar, see [Section 6.4, "Grammar
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   153
for the Stream Format"](protocol.html#grammar-for-the-stream-format).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   154
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   155
## 4.4 The ObjectStreamField Class
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   156
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   157
An `ObjectStreamField` represents a serializable field of a serializable class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   158
The serializable fields of a class can be retrieved from the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   159
`ObjectStreamClass`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   160
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   161
The special static serializable field, `serialPersistentFields`, is an array of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   162
`ObjectStreamField` components that is used to override the default
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   163
serializable fields.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   164
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   165
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   166
package java.io;
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   167
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   168
public class ObjectStreamField implements Comparable {
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   169
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   170
    public ObjectStreamField(String fieldName,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   171
                             Class fieldType);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   172
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   173
    public ObjectStreamField(String fieldName,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   174
                             Class fieldType,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   175
                             boolean unshared);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   176
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   177
    public String getName();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   178
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   179
    public Class getType();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   180
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   181
    public String getTypeString();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   182
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   183
    public char getTypeCode();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   184
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   185
    public boolean isPrimitive();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   186
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   187
    public boolean isUnshared();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   188
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   189
    public int getOffset();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   190
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   191
    protected void setOffset(int offset);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   192
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   193
    public int compareTo(Object obj);
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   194
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   195
    public String toString();
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   196
}
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   197
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   198
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   199
`ObjectStreamField` objects are used to specify the serializable fields of a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   200
class or to describe the fields present in a stream. Its constructors accept
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   201
arguments describing the field to represent: a string specifying the name of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   202
the field, a `Class` object specifying the type of the field, and a `boolean`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   203
flag (implicitly `false` for the two-argument constructor) indicating whether
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   204
or not values of the represented field should be read and written as "unshared"
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   205
objects if default serialization/deserialization is in use (see the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   206
descriptions of the `ObjectInputStream.readUnshared` and
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   207
`ObjectOutputStream.writeUnshared` methods in [Section 3.1, "The
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   208
ObjectInputStream Class"](input.html#the-objectinputstream-class) and [Section
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   209
2.1, "The ObjectOutputStream Class"](output.html#the-objectoutputstream-class),
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   210
respectively).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   211
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   212
The `getName` method returns the name of the serializable field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   213
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   214
The `getType` method returns the type of the field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   215
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   216
The `getTypeString` method returns the type signature of the field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   217
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   218
The `getTypeCode` method returns a character encoding of the field type ('`B`'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   219
for `byte`, '`C`' for `char`, '`D`' for `double`, '`F`' for `float`, '`I`' for
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   220
`int`, '`J`' for `long`, '`L`' for non-array object types, '`S`' for `short`,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   221
'`Z`' for `boolean`, and '`[`' for arrays).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   222
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   223
The `isPrimitive` method returns `true` if the field is of primitive type, or
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   224
`false` otherwise.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   225
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   226
The `isUnshared` method returns `true` if values of the field should be written
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   227
as "unshared" objects, or `false` otherwise.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   228
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   229
The `getOffset` method returns the offset of the field's value within instance
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   230
data of the class defining the field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   231
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   232
The `setOffset` method allows `ObjectStreamField` subclasses to modify the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   233
offset value returned by the `getOffset` method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   234
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   235
The `compareTo` method compares `ObjectStreamFields` for use in sorting.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   236
Primitive fields are ranked as "smaller" than non-primitive fields; fields
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   237
otherwise equal are ranked alphabetically.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   238
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   239
The `toString` method returns a printable representation with name and type.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   240
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   241
## 4.5 Inspecting Serializable Classes
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   242
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   243
The program *serialver* can be used to find out if a class is serializable and
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   244
to get its `serialVersionUID`. When invoked with the-show option, it puts up a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   245
simple user interface. To find out if a class is serializable and to find out
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   246
its *serialVersionUID*`,` enter its full class name, then press either the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   247
Enter or the Show button. The string printed can be copied and pasted into the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   248
evolved class.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   249
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   250
>   ![*serialver, Serial Version Inspector program*](images/class.gif)
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   251
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   252
When invoked on the command line with one or more class names, serialver prints
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   253
the `serialVersionUID` for each class in a form suitable for copying into an
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   254
evolving class. When invoked with no arguments, it prints a usage line.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   255
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   256
## 4.6 Stream Unique Identifiers
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   257
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   258
Each versioned class must identify the original class version for which it is
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   259
capable of writing streams and from which it can read. For example, a versioned
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   260
class must declare:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   261
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   262
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   263
private static final long serialVersionUID = 3487495895819393L;
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   264
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   265
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   266
The stream-unique identifier is a 64-bit hash of the class name, interface
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   267
class names, methods, and fields. The value must be declared in all versions of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   268
a class except the first. It may be declared in the original class but is not
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   269
required. The value is fixed for all compatible classes. If the SUID is not
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   270
declared for a class, the value defaults to the hash for that class. The
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   271
`serialVersionUID` for dynamic proxy classes and enum types always have the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   272
value *0L*. Array classes cannot declare an explicit `serialVersionUID`, so
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   273
they always have the default computed value, but the requirement for matching
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   274
`serialVersionUID` values is waived for array classes.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   275
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   276
**Note:** It is strongly recommended that all serializable classes explicitly
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   277
declare `serialVersionUID` values, since the default `serialVersionUID`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   278
computation is highly sensitive to class details that may vary depending on
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   279
compiler implementations, and can thus result in unexpected `serialVersionUID`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   280
conflicts during deserialization, causing deserialization to fail.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   281
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   282
The initial version of an `Externalizable` class must output a stream data
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   283
format that is extensible in the future. The initial version of the method
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   284
`readExternal` has to be able to read the output format of all future versions
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   285
of the method `writeExternal`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   286
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   287
The `serialVersionUID` is computed using the signature of a stream of bytes
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   288
that reflect the class definition. The National Institute of Standards and
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   289
Technology (NIST) Secure Hash Algorithm (SHA-1) is used to compute a signature
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   290
for the stream. The first two 32-bit quantities are used to form a 64-bit hash.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   291
A `java.lang.DataOutputStream` is used to convert primitive data types to a
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   292
sequence of bytes. The values input to the stream are defined by the Java
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   293
Virtual Machine (VM) specification for classes. Class modifiers may include the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   294
`ACC_PUBLIC`, `ACC_FINAL`, `ACC_INTERFACE`, and `ACC_ABSTRACT` flags; other
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   295
flags are ignored and do not affect `serialVersionUID` computation. Similarly,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   296
for field modifiers, only the `ACC_PUBLIC`, `ACC_PRIVATE`, `ACC_PROTECTED`,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   297
`ACC_STATIC`, `ACC_FINAL`, `ACC_VOLATILE`, and `ACC_TRANSIENT` flags are used
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   298
when computing `serialVersionUID` values. For constructor and method modifiers,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   299
only the `ACC_PUBLIC`, `ACC_PRIVATE`, `ACC_PROTECTED`, `ACC_STATIC`,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   300
`ACC_FINAL`, `ACC_SYNCHRONIZED`, `ACC_NATIVE`, `ACC_ABSTRACT` and `ACC_STRICT`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   301
flags are used. Names and descriptors are written in the format used by the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   302
`java.io.DataOutputStream.writeUTF` method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   303
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   304
The sequence of items in the stream is as follows:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   305
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   306
1.  The class name.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   307
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   308
2.  The class modifiers written as a 32-bit integer.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   309
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   310
3.  The name of each interface sorted by name.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   311
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   312
4.  For each field of the class sorted by field name (except `private static`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   313
    and `private transient` fields:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   314
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   315
    a.  The name of the field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   316
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   317
    b.  The modifiers of the field written as a 32-bit integer.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   318
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   319
    c.  The descriptor of the field.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   320
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   321
5.  If a class initializer exists, write out the following:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   322
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   323
    a.  The name of the method, `<clinit>`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   324
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   325
    b.  The modifier of the method, `java.lang.reflect.Modifier.STATIC`,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   326
        written as a 32-bit integer.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   327
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   328
    c.  The descriptor of the method, `()V`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   329
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   330
6.  For each non-`private` constructor sorted by method name and signature:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   331
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   332
    a.  The name of the method, `<init>`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   333
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   334
    b.  The modifiers of the method written as a 32-bit integer.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   335
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   336
    c.  The descriptor of the method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   337
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   338
7.  For each non-`private` method sorted by method name and signature:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   339
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   340
    a.  The name of the method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   341
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   342
    b.  The modifiers of the method written as a 32-bit integer.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   343
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   344
    c.  The descriptor of the method.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   345
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   346
8.  The SHA-1 algorithm is executed on the stream of bytes produced by
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   347
    `DataOutputStream` and produces five 32-bit values `sha[0..4]`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   348
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   349
9.  The hash value is assembled from the first and second 32-bit values of the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   350
    SHA-1 message digest. If the result of the message digest, the five 32-bit
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   351
    words `H0 H1 H2 H3 H4`, is in an array of five `int` values named `sha`,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   352
    the hash value would be computed as follows:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   353
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   354
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   355
      long hash = ((sha[0] >>> 24) & 0xFF) |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   356
                  ((sha[0] >>> 16) & 0xFF) << 8 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   357
                  ((sha[0] >>> 8) & 0xFF) << 16 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   358
                  ((sha[0] >>> 0) & 0xFF) << 24 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   359
                  ((sha[1] >>> 24) & 0xFF) << 32 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   360
                  ((sha[1] >>> 16) & 0xFF) << 40 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   361
                  ((sha[1] >>> 8) & 0xFF) << 48 |
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   362
                  ((sha[1] >>> 0) & 0xFF) << 56;
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   363
```
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   364
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   365
-------------------------------------------------------------------------------
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   366
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   367
*[Copyright](../../../legal/SMICopyright.html) &copy; 2005, 2017, Oracle
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
   368
and/or its affiliates. All rights reserved.*