src/java.base/share/classes/java/io/ObjectInputStream.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 53304 9e968a576dd2
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    72  * Machine.  Classes are loaded as required using the standard mechanisms.
    72  * Machine.  Classes are loaded as required using the standard mechanisms.
    73  *
    73  *
    74  * <p>Only objects that support the java.io.Serializable or
    74  * <p>Only objects that support the java.io.Serializable or
    75  * java.io.Externalizable interface can be read from streams.
    75  * java.io.Externalizable interface can be read from streams.
    76  *
    76  *
    77  * <p>The method <code>readObject</code> is used to read an object from the
    77  * <p>The method {@code readObject} is used to read an object from the
    78  * stream.  Java's safe casting should be used to get the desired type.  In
    78  * stream.  Java's safe casting should be used to get the desired type.  In
    79  * Java, strings and arrays are objects and are treated as objects during
    79  * Java, strings and arrays are objects and are treated as objects during
    80  * serialization. When read they need to be cast to the expected type.
    80  * serialization. When read they need to be cast to the expected type.
    81  *
    81  *
    82  * <p>Primitive data types can be read from the stream using the appropriate
    82  * <p>Primitive data types can be read from the stream using the appropriate
   155  * behave in the same manner--if the stream is already positioned at the end of
   155  * behave in the same manner--if the stream is already positioned at the end of
   156  * data written by the corresponding writeExternal method, object reads will
   156  * data written by the corresponding writeExternal method, object reads will
   157  * throw OptionalDataExceptions with eof set to true, bytewise reads will
   157  * throw OptionalDataExceptions with eof set to true, bytewise reads will
   158  * return -1, and primitive reads will throw EOFExceptions.  Note that this
   158  * return -1, and primitive reads will throw EOFExceptions.  Note that this
   159  * behavior does not hold for streams written with the old
   159  * behavior does not hold for streams written with the old
   160  * <code>ObjectStreamConstants.PROTOCOL_VERSION_1</code> protocol, in which the
   160  * {@code ObjectStreamConstants.PROTOCOL_VERSION_1} protocol, in which the
   161  * end of data written by writeExternal methods is not demarcated, and hence
   161  * end of data written by writeExternal methods is not demarcated, and hence
   162  * cannot be detected.
   162  * cannot be detected.
   163  *
   163  *
   164  * <p>The readObjectNoData method is responsible for initializing the state of
   164  * <p>The readObjectNoData method is responsible for initializing the state of
   165  * the object for its particular class in the event that the serialization
   165  * the object for its particular class in the event that the serialization
   206  * <p>Enum constants are deserialized differently than ordinary serializable or
   206  * <p>Enum constants are deserialized differently than ordinary serializable or
   207  * externalizable objects.  The serialized form of an enum constant consists
   207  * externalizable objects.  The serialized form of an enum constant consists
   208  * solely of its name; field values of the constant are not transmitted.  To
   208  * solely of its name; field values of the constant are not transmitted.  To
   209  * deserialize an enum constant, ObjectInputStream reads the constant name from
   209  * deserialize an enum constant, ObjectInputStream reads the constant name from
   210  * the stream; the deserialized constant is then obtained by calling the static
   210  * the stream; the deserialized constant is then obtained by calling the static
   211  * method <code>Enum.valueOf(Class, String)</code> with the enum constant's
   211  * method {@code Enum.valueOf(Class, String)} with the enum constant's
   212  * base type and the received constant name as arguments.  Like other
   212  * base type and the received constant name as arguments.  Like other
   213  * serializable or externalizable objects, enum constants can function as the
   213  * serializable or externalizable objects, enum constants can function as the
   214  * targets of back references appearing subsequently in the serialization
   214  * targets of back references appearing subsequently in the serialization
   215  * stream.  The process by which enum constants are deserialized cannot be
   215  * stream.  The process by which enum constants are deserialized cannot be
   216  * customized: any class-specific readObject, readObjectNoData, and readResolve
   216  * customized: any class-specific readObject, readObjectNoData, and readResolve
   333      * @param   in input stream to read from
   333      * @param   in input stream to read from
   334      * @throws  StreamCorruptedException if the stream header is incorrect
   334      * @throws  StreamCorruptedException if the stream header is incorrect
   335      * @throws  IOException if an I/O error occurs while reading stream header
   335      * @throws  IOException if an I/O error occurs while reading stream header
   336      * @throws  SecurityException if untrusted subclass illegally overrides
   336      * @throws  SecurityException if untrusted subclass illegally overrides
   337      *          security-sensitive methods
   337      *          security-sensitive methods
   338      * @throws  NullPointerException if <code>in</code> is <code>null</code>
   338      * @throws  NullPointerException if {@code in} is {@code null}
   339      * @see     ObjectInputStream#ObjectInputStream()
   339      * @see     ObjectInputStream#ObjectInputStream()
   340      * @see     ObjectInputStream#readFields()
   340      * @see     ObjectInputStream#readFields()
   341      * @see     ObjectOutputStream#ObjectOutputStream(OutputStream)
   341      * @see     ObjectOutputStream#ObjectOutputStream(OutputStream)
   342      */
   342      */
   343     public ObjectInputStream(InputStream in) throws IOException {
   343     public ObjectInputStream(InputStream in) throws IOException {
   358      *
   358      *
   359      * <p>The serialization filter is initialized to the value of
   359      * <p>The serialization filter is initialized to the value of
   360      * {@linkplain ObjectInputFilter.Config#getSerialFilter() the system-wide filter}.
   360      * {@linkplain ObjectInputFilter.Config#getSerialFilter() the system-wide filter}.
   361      *
   361      *
   362      * <p>If there is a security manager installed, this method first calls the
   362      * <p>If there is a security manager installed, this method first calls the
   363      * security manager's <code>checkPermission</code> method with the
   363      * security manager's {@code checkPermission} method with the
   364      * <code>SerializablePermission("enableSubclassImplementation")</code>
   364      * {@code SerializablePermission("enableSubclassImplementation")}
   365      * permission to ensure it's ok to enable subclassing.
   365      * permission to ensure it's ok to enable subclassing.
   366      *
   366      *
   367      * @throws  SecurityException if a security manager exists and its
   367      * @throws  SecurityException if a security manager exists and its
   368      *          <code>checkPermission</code> method denies enabling
   368      *          {@code checkPermission} method denies enabling
   369      *          subclassing.
   369      *          subclassing.
   370      * @throws  IOException if an I/O error occurs while creating this stream
   370      * @throws  IOException if an I/O error occurs while creating this stream
   371      * @see SecurityManager#checkPermission
   371      * @see SecurityManager#checkPermission
   372      * @see java.io.SerializablePermission
   372      * @see java.io.SerializablePermission
   373      */
   373      */
   445             }
   445             }
   446         }
   446         }
   447     }
   447     }
   448 
   448 
   449     /**
   449     /**
   450      * This method is called by trusted subclasses of ObjectOutputStream that
   450      * This method is called by trusted subclasses of ObjectInputStream that
   451      * constructed ObjectOutputStream using the protected no-arg constructor.
   451      + constructed ObjectInputStream using the protected no-arg constructor.
   452      * The subclass is expected to provide an override method with the modifier
   452      * The subclass is expected to provide an override method with the modifier
   453      * "final".
   453      * "final".
   454      *
   454      *
   455      * @return  the Object read from the stream.
   455      * @return  the Object read from the stream.
   456      * @throws  ClassNotFoundException Class definition of a serialized object
   456      * @throws  ClassNotFoundException Class definition of a serialized object
   585 
   585 
   586     /**
   586     /**
   587      * Reads the persistent fields from the stream and makes them available by
   587      * Reads the persistent fields from the stream and makes them available by
   588      * name.
   588      * name.
   589      *
   589      *
   590      * @return  the <code>GetField</code> object representing the persistent
   590      * @return  the {@code GetField} object representing the persistent
   591      *          fields of the object being deserialized
   591      *          fields of the object being deserialized
   592      * @throws  ClassNotFoundException if the class of a serialized object
   592      * @throws  ClassNotFoundException if the class of a serialized object
   593      *          could not be found.
   593      *          could not be found.
   594      * @throws  IOException if an I/O error occurs.
   594      * @throws  IOException if an I/O error occurs.
   595      * @throws  NotActiveException if the stream is not currently reading
   595      * @throws  NotActiveException if the stream is not currently reading
   649     /**
   649     /**
   650      * Load the local class equivalent of the specified stream class
   650      * Load the local class equivalent of the specified stream class
   651      * description.  Subclasses may implement this method to allow classes to
   651      * description.  Subclasses may implement this method to allow classes to
   652      * be fetched from an alternate source.
   652      * be fetched from an alternate source.
   653      *
   653      *
   654      * <p>The corresponding method in <code>ObjectOutputStream</code> is
   654      * <p>The corresponding method in {@code ObjectOutputStream} is
   655      * <code>annotateClass</code>.  This method will be invoked only once for
   655      * {@code annotateClass}.  This method will be invoked only once for
   656      * each unique class in the stream.  This method can be implemented by
   656      * each unique class in the stream.  This method can be implemented by
   657      * subclasses to use an alternate loading mechanism but must return a
   657      * subclasses to use an alternate loading mechanism but must return a
   658      * <code>Class</code> object. Once returned, if the class is not an array
   658      * {@code Class} object. Once returned, if the class is not an array
   659      * class, its serialVersionUID is compared to the serialVersionUID of the
   659      * class, its serialVersionUID is compared to the serialVersionUID of the
   660      * serialized class, and if there is a mismatch, the deserialization fails
   660      * serialized class, and if there is a mismatch, the deserialization fails
   661      * and an {@link InvalidClassException} is thrown.
   661      * and an {@link InvalidClassException} is thrown.
   662      *
   662      *
   663      * <p>The default implementation of this method in
   663      * <p>The default implementation of this method in
   664      * <code>ObjectInputStream</code> returns the result of calling
   664      * {@code ObjectInputStream} returns the result of calling
   665      * <pre>
   665      * <pre>
   666      *     Class.forName(desc.getName(), false, loader)
   666      *     Class.forName(desc.getName(), false, loader)
   667      * </pre>
   667      * </pre>
   668      * where <code>loader</code> is the first class loader on the current
   668      * where {@code loader} is the first class loader on the current
   669      * thread's stack (starting from the currently executing method) that is
   669      * thread's stack (starting from the currently executing method) that is
   670      * neither the {@linkplain ClassLoader#getPlatformClassLoader() platform
   670      * neither the {@linkplain ClassLoader#getPlatformClassLoader() platform
   671      * class loader} nor its ancestor; otherwise, <code>loader</code> is the
   671      * class loader} nor its ancestor; otherwise, {@code loader} is the
   672      * <em>platform class loader</em>. If this call results in a
   672      * <em>platform class loader</em>. If this call results in a
   673      * <code>ClassNotFoundException</code> and the name of the passed
   673      * {@code ClassNotFoundException} and the name of the passed
   674      * <code>ObjectStreamClass</code> instance is the Java language keyword
   674      * {@code ObjectStreamClass} instance is the Java language keyword
   675      * for a primitive type or void, then the <code>Class</code> object
   675      * for a primitive type or void, then the {@code Class} object
   676      * representing that primitive type or void will be returned
   676      * representing that primitive type or void will be returned
   677      * (e.g., an <code>ObjectStreamClass</code> with the name
   677      * (e.g., an {@code ObjectStreamClass} with the name
   678      * <code>"int"</code> will be resolved to <code>Integer.TYPE</code>).
   678      * {@code "int"} will be resolved to {@code Integer.TYPE}).
   679      * Otherwise, the <code>ClassNotFoundException</code> will be thrown to
   679      * Otherwise, the {@code ClassNotFoundException} will be thrown to
   680      * the caller of this method.
   680      * the caller of this method.
   681      *
   681      *
   682      * @param   desc an instance of class <code>ObjectStreamClass</code>
   682      * @param   desc an instance of class {@code ObjectStreamClass}
   683      * @return  a <code>Class</code> object corresponding to <code>desc</code>
   683      * @return  a {@code Class} object corresponding to {@code desc}
   684      * @throws  IOException any of the usual Input/Output exceptions.
   684      * @throws  IOException any of the usual Input/Output exceptions.
   685      * @throws  ClassNotFoundException if class of a serialized object cannot
   685      * @throws  ClassNotFoundException if class of a serialized object cannot
   686      *          be found.
   686      *          be found.
   687      */
   687      */
   688     protected Class<?> resolveClass(ObjectStreamClass desc)
   688     protected Class<?> resolveClass(ObjectStreamClass desc)
   709      * interfaces and the proxy class.
   709      * interfaces and the proxy class.
   710      *
   710      *
   711      * <p>This method is called exactly once for each unique proxy class
   711      * <p>This method is called exactly once for each unique proxy class
   712      * descriptor in the stream.
   712      * descriptor in the stream.
   713      *
   713      *
   714      * <p>The corresponding method in <code>ObjectOutputStream</code> is
   714      * <p>The corresponding method in {@code ObjectOutputStream} is
   715      * <code>annotateProxyClass</code>.  For a given subclass of
   715      * {@code annotateProxyClass}.  For a given subclass of
   716      * <code>ObjectInputStream</code> that overrides this method, the
   716      * {@code ObjectInputStream} that overrides this method, the
   717      * <code>annotateProxyClass</code> method in the corresponding subclass of
   717      * {@code annotateProxyClass} method in the corresponding subclass of
   718      * <code>ObjectOutputStream</code> must write any data or objects read by
   718      * {@code ObjectOutputStream} must write any data or objects read by
   719      * this method.
   719      * this method.
   720      *
   720      *
   721      * <p>The default implementation of this method in
   721      * <p>The default implementation of this method in
   722      * <code>ObjectInputStream</code> returns the result of calling
   722      * {@code ObjectInputStream} returns the result of calling
   723      * <code>Proxy.getProxyClass</code> with the list of <code>Class</code>
   723      * {@code Proxy.getProxyClass} with the list of {@code Class}
   724      * objects for the interfaces that are named in the <code>interfaces</code>
   724      * objects for the interfaces that are named in the {@code interfaces}
   725      * parameter.  The <code>Class</code> object for each interface name
   725      * parameter.  The {@code Class} object for each interface name
   726      * <code>i</code> is the value returned by calling
   726      * {@code i} is the value returned by calling
   727      * <pre>
   727      * <pre>
   728      *     Class.forName(i, false, loader)
   728      *     Class.forName(i, false, loader)
   729      * </pre>
   729      * </pre>
   730      * where <code>loader</code> is the first class loader on the current
   730      * where {@code loader} is the first class loader on the current
   731      * thread's stack (starting from the currently executing method) that is
   731      * thread's stack (starting from the currently executing method) that is
   732      * neither the {@linkplain ClassLoader#getPlatformClassLoader() platform
   732      * neither the {@linkplain ClassLoader#getPlatformClassLoader() platform
   733      * class loader} nor its ancestor; otherwise, <code>loader</code> is the
   733      * class loader} nor its ancestor; otherwise, {@code loader} is the
   734      * <em>platform class loader</em>.
   734      * <em>platform class loader</em>.
   735      * Unless any of the resolved interfaces are non-public, this same value
   735      * Unless any of the resolved interfaces are non-public, this same value
   736      * of <code>loader</code> is also the class loader passed to
   736      * of {@code loader} is also the class loader passed to
   737      * <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
   737      * {@code Proxy.getProxyClass}; if non-public interfaces are present,
   738      * their class loader is passed instead (if more than one non-public
   738      * their class loader is passed instead (if more than one non-public
   739      * interface class loader is encountered, an
   739      * interface class loader is encountered, an
   740      * <code>IllegalAccessError</code> is thrown).
   740      * {@code IllegalAccessError} is thrown).
   741      * If <code>Proxy.getProxyClass</code> throws an
   741      * If {@code Proxy.getProxyClass} throws an
   742      * <code>IllegalArgumentException</code>, <code>resolveProxyClass</code>
   742      * {@code IllegalArgumentException}, {@code resolveProxyClass}
   743      * will throw a <code>ClassNotFoundException</code> containing the
   743      * will throw a {@code ClassNotFoundException} containing the
   744      * <code>IllegalArgumentException</code>.
   744      * {@code IllegalArgumentException}.
   745      *
   745      *
   746      * @param interfaces the list of interface names that were
   746      * @param interfaces the list of interface names that were
   747      *                deserialized in the proxy class descriptor
   747      *                deserialized in the proxy class descriptor
   748      * @return  a proxy class for the specified interfaces
   748      * @return  a proxy class for the specified interfaces
   749      * @throws        IOException any exception thrown by the underlying
   749      * @throws        IOException any exception thrown by the underlying
   750      *                <code>InputStream</code>
   750      *                {@code InputStream}
   751      * @throws        ClassNotFoundException if the proxy class or any of the
   751      * @throws        ClassNotFoundException if the proxy class or any of the
   752      *                named interfaces could not be found
   752      *                named interfaces could not be found
   753      * @see ObjectOutputStream#annotateProxyClass(Class)
   753      * @see ObjectOutputStream#annotateProxyClass(Class)
   754      * @since 1.3
   754      * @since 1.3
   755      */
   755      */
   861      * The readStreamHeader method is provided to allow subclasses to read and
   861      * The readStreamHeader method is provided to allow subclasses to read and
   862      * verify their own stream headers. It reads and verifies the magic number
   862      * verify their own stream headers. It reads and verifies the magic number
   863      * and version number.
   863      * and version number.
   864      *
   864      *
   865      * @throws  IOException if there are I/O errors while reading from the
   865      * @throws  IOException if there are I/O errors while reading from the
   866      *          underlying <code>InputStream</code>
   866      *          underlying {@code InputStream}
   867      * @throws  StreamCorruptedException if control information in the stream
   867      * @throws  StreamCorruptedException if control information in the stream
   868      *          is inconsistent
   868      *          is inconsistent
   869      */
   869      */
   870     protected void readStreamHeader()
   870     protected void readStreamHeader()
   871         throws IOException, StreamCorruptedException
   871         throws IOException, StreamCorruptedException
   882      * Read a class descriptor from the serialization stream.  This method is
   882      * Read a class descriptor from the serialization stream.  This method is
   883      * called when the ObjectInputStream expects a class descriptor as the next
   883      * called when the ObjectInputStream expects a class descriptor as the next
   884      * item in the serialization stream.  Subclasses of ObjectInputStream may
   884      * item in the serialization stream.  Subclasses of ObjectInputStream may
   885      * override this method to read in class descriptors that have been written
   885      * override this method to read in class descriptors that have been written
   886      * in non-standard formats (by subclasses of ObjectOutputStream which have
   886      * in non-standard formats (by subclasses of ObjectOutputStream which have
   887      * overridden the <code>writeClassDescriptor</code> method).  By default,
   887      * overridden the {@code writeClassDescriptor} method).  By default,
   888      * this method reads class descriptors according to the format defined in
   888      * this method reads class descriptors according to the format defined in
   889      * the Object Serialization specification.
   889      * the Object Serialization specification.
   890      *
   890      *
   891      * @return  the class descriptor read
   891      * @return  the class descriptor read
   892      * @throws  IOException If an I/O error has occurred.
   892      * @throws  IOException If an I/O error has occurred.
   944     /**
   944     /**
   945      * Returns the number of bytes that can be read without blocking.
   945      * Returns the number of bytes that can be read without blocking.
   946      *
   946      *
   947      * @return  the number of available bytes.
   947      * @return  the number of available bytes.
   948      * @throws  IOException if there are I/O errors while reading from the
   948      * @throws  IOException if there are I/O errors while reading from the
   949      *          underlying <code>InputStream</code>
   949      *          underlying {@code InputStream}
   950      */
   950      */
   951     public int available() throws IOException {
   951     public int available() throws IOException {
   952         return bin.available();
   952         return bin.available();
   953     }
   953     }
   954 
   954 
  1127     /**
  1127     /**
  1128      * Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
  1128      * Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
  1129      *
  1129      *
  1130      * @return  a String copy of the line.
  1130      * @return  a String copy of the line.
  1131      * @throws  IOException if there are I/O errors while reading from the
  1131      * @throws  IOException if there are I/O errors while reading from the
  1132      *          underlying <code>InputStream</code>
  1132      *          underlying {@code InputStream}
  1133      * @deprecated This method does not properly convert bytes to characters.
  1133      * @deprecated This method does not properly convert bytes to characters.
  1134      *          see DataInputStream for the details and alternatives.
  1134      *          see DataInputStream for the details and alternatives.
  1135      */
  1135      */
  1136     @Deprecated
  1136     @Deprecated
  1137     public String readLine() throws IOException {
  1137     public String readLine() throws IOException {
  1143      * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  1143      * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  1144      * format.
  1144      * format.
  1145      *
  1145      *
  1146      * @return  the String.
  1146      * @return  the String.
  1147      * @throws  IOException if there are I/O errors while reading from the
  1147      * @throws  IOException if there are I/O errors while reading from the
  1148      *          underlying <code>InputStream</code>
  1148      *          underlying {@code InputStream}
  1149      * @throws  UTFDataFormatException if read bytes do not represent a valid
  1149      * @throws  UTFDataFormatException if read bytes do not represent a valid
  1150      *          modified UTF-8 encoding of a string
  1150      *          modified UTF-8 encoding of a string
  1151      */
  1151      */
  1152     public String readUTF() throws IOException {
  1152     public String readUTF() throws IOException {
  1153         return bin.readUTF();
  1153         return bin.readUTF();
  1319 
  1319 
  1320     /**
  1320     /**
  1321      * Provide access to the persistent fields read from the input stream.
  1321      * Provide access to the persistent fields read from the input stream.
  1322      */
  1322      */
  1323     public abstract static class GetField {
  1323     public abstract static class GetField {
       
  1324         /**
       
  1325          * Constructor for subclasses to call.
       
  1326          */
       
  1327         public GetField() {}
  1324 
  1328 
  1325         /**
  1329         /**
  1326          * Get the ObjectStreamClass that describes the fields in the stream.
  1330          * Get the ObjectStreamClass that describes the fields in the stream.
  1327          *
  1331          *
  1328          * @return  the descriptor class that describes the serializable fields
  1332          * @return  the descriptor class that describes the serializable fields
  1334          * stream.
  1338          * stream.
  1335          *
  1339          *
  1336          * @param  name the name of the field
  1340          * @param  name the name of the field
  1337          * @return true, if and only if the named field is defaulted
  1341          * @return true, if and only if the named field is defaulted
  1338          * @throws IOException if there are I/O errors while reading from
  1342          * @throws IOException if there are I/O errors while reading from
  1339          *         the underlying <code>InputStream</code>
  1343          *         the underlying {@code InputStream}
  1340          * @throws IllegalArgumentException if <code>name</code> does not
  1344          * @throws IllegalArgumentException if {@code name} does not
  1341          *         correspond to a serializable field
  1345          *         correspond to a serializable field
  1342          */
  1346          */
  1343         public abstract boolean defaulted(String name) throws IOException;
  1347         public abstract boolean defaulted(String name) throws IOException;
  1344 
  1348 
  1345         /**
  1349         /**
  1346          * Get the value of the named boolean field from the persistent field.
  1350          * Get the value of the named boolean field from the persistent field.
  1347          *
  1351          *
  1348          * @param  name the name of the field
  1352          * @param  name the name of the field
  1349          * @param  val the default value to use if <code>name</code> does not
  1353          * @param  val the default value to use if {@code name} does not
  1350          *         have a value
  1354          *         have a value
  1351          * @return the value of the named <code>boolean</code> field
  1355          * @return the value of the named {@code boolean} field
  1352          * @throws IOException if there are I/O errors while reading from the
  1356          * @throws IOException if there are I/O errors while reading from the
  1353          *         underlying <code>InputStream</code>
  1357          *         underlying {@code InputStream}
  1354          * @throws IllegalArgumentException if type of <code>name</code> is
  1358          * @throws IllegalArgumentException if type of {@code name} is
  1355          *         not serializable or if the field type is incorrect
  1359          *         not serializable or if the field type is incorrect
  1356          */
  1360          */
  1357         public abstract boolean get(String name, boolean val)
  1361         public abstract boolean get(String name, boolean val)
  1358             throws IOException;
  1362             throws IOException;
  1359 
  1363 
  1360         /**
  1364         /**
  1361          * Get the value of the named byte field from the persistent field.
  1365          * Get the value of the named byte field from the persistent field.
  1362          *
  1366          *
  1363          * @param  name the name of the field
  1367          * @param  name the name of the field
  1364          * @param  val the default value to use if <code>name</code> does not
  1368          * @param  val the default value to use if {@code name} does not
  1365          *         have a value
  1369          *         have a value
  1366          * @return the value of the named <code>byte</code> field
  1370          * @return the value of the named {@code byte} field
  1367          * @throws IOException if there are I/O errors while reading from the
  1371          * @throws IOException if there are I/O errors while reading from the
  1368          *         underlying <code>InputStream</code>
  1372          *         underlying {@code InputStream}
  1369          * @throws IllegalArgumentException if type of <code>name</code> is
  1373          * @throws IllegalArgumentException if type of {@code name} is
  1370          *         not serializable or if the field type is incorrect
  1374          *         not serializable or if the field type is incorrect
  1371          */
  1375          */
  1372         public abstract byte get(String name, byte val) throws IOException;
  1376         public abstract byte get(String name, byte val) throws IOException;
  1373 
  1377 
  1374         /**
  1378         /**
  1375          * Get the value of the named char field from the persistent field.
  1379          * Get the value of the named char field from the persistent field.
  1376          *
  1380          *
  1377          * @param  name the name of the field
  1381          * @param  name the name of the field
  1378          * @param  val the default value to use if <code>name</code> does not
  1382          * @param  val the default value to use if {@code name} does not
  1379          *         have a value
  1383          *         have a value
  1380          * @return the value of the named <code>char</code> field
  1384          * @return the value of the named {@code char} field
  1381          * @throws IOException if there are I/O errors while reading from the
  1385          * @throws IOException if there are I/O errors while reading from the
  1382          *         underlying <code>InputStream</code>
  1386          *         underlying {@code InputStream}
  1383          * @throws IllegalArgumentException if type of <code>name</code> is
  1387          * @throws IllegalArgumentException if type of {@code name} is
  1384          *         not serializable or if the field type is incorrect
  1388          *         not serializable or if the field type is incorrect
  1385          */
  1389          */
  1386         public abstract char get(String name, char val) throws IOException;
  1390         public abstract char get(String name, char val) throws IOException;
  1387 
  1391 
  1388         /**
  1392         /**
  1389          * Get the value of the named short field from the persistent field.
  1393          * Get the value of the named short field from the persistent field.
  1390          *
  1394          *
  1391          * @param  name the name of the field
  1395          * @param  name the name of the field
  1392          * @param  val the default value to use if <code>name</code> does not
  1396          * @param  val the default value to use if {@code name} does not
  1393          *         have a value
  1397          *         have a value
  1394          * @return the value of the named <code>short</code> field
  1398          * @return the value of the named {@code short} field
  1395          * @throws IOException if there are I/O errors while reading from the
  1399          * @throws IOException if there are I/O errors while reading from the
  1396          *         underlying <code>InputStream</code>
  1400          *         underlying {@code InputStream}
  1397          * @throws IllegalArgumentException if type of <code>name</code> is
  1401          * @throws IllegalArgumentException if type of {@code name} is
  1398          *         not serializable or if the field type is incorrect
  1402          *         not serializable or if the field type is incorrect
  1399          */
  1403          */
  1400         public abstract short get(String name, short val) throws IOException;
  1404         public abstract short get(String name, short val) throws IOException;
  1401 
  1405 
  1402         /**
  1406         /**
  1403          * Get the value of the named int field from the persistent field.
  1407          * Get the value of the named int field from the persistent field.
  1404          *
  1408          *
  1405          * @param  name the name of the field
  1409          * @param  name the name of the field
  1406          * @param  val the default value to use if <code>name</code> does not
  1410          * @param  val the default value to use if {@code name} does not
  1407          *         have a value
  1411          *         have a value
  1408          * @return the value of the named <code>int</code> field
  1412          * @return the value of the named {@code int} field
  1409          * @throws IOException if there are I/O errors while reading from the
  1413          * @throws IOException if there are I/O errors while reading from the
  1410          *         underlying <code>InputStream</code>
  1414          *         underlying {@code InputStream}
  1411          * @throws IllegalArgumentException if type of <code>name</code> is
  1415          * @throws IllegalArgumentException if type of {@code name} is
  1412          *         not serializable or if the field type is incorrect
  1416          *         not serializable or if the field type is incorrect
  1413          */
  1417          */
  1414         public abstract int get(String name, int val) throws IOException;
  1418         public abstract int get(String name, int val) throws IOException;
  1415 
  1419 
  1416         /**
  1420         /**
  1417          * Get the value of the named long field from the persistent field.
  1421          * Get the value of the named long field from the persistent field.
  1418          *
  1422          *
  1419          * @param  name the name of the field
  1423          * @param  name the name of the field
  1420          * @param  val the default value to use if <code>name</code> does not
  1424          * @param  val the default value to use if {@code name} does not
  1421          *         have a value
  1425          *         have a value
  1422          * @return the value of the named <code>long</code> field
  1426          * @return the value of the named {@code long} field
  1423          * @throws IOException if there are I/O errors while reading from the
  1427          * @throws IOException if there are I/O errors while reading from the
  1424          *         underlying <code>InputStream</code>
  1428          *         underlying {@code InputStream}
  1425          * @throws IllegalArgumentException if type of <code>name</code> is
  1429          * @throws IllegalArgumentException if type of {@code name} is
  1426          *         not serializable or if the field type is incorrect
  1430          *         not serializable or if the field type is incorrect
  1427          */
  1431          */
  1428         public abstract long get(String name, long val) throws IOException;
  1432         public abstract long get(String name, long val) throws IOException;
  1429 
  1433 
  1430         /**
  1434         /**
  1431          * Get the value of the named float field from the persistent field.
  1435          * Get the value of the named float field from the persistent field.
  1432          *
  1436          *
  1433          * @param  name the name of the field
  1437          * @param  name the name of the field
  1434          * @param  val the default value to use if <code>name</code> does not
  1438          * @param  val the default value to use if {@code name} does not
  1435          *         have a value
  1439          *         have a value
  1436          * @return the value of the named <code>float</code> field
  1440          * @return the value of the named {@code float} field
  1437          * @throws IOException if there are I/O errors while reading from the
  1441          * @throws IOException if there are I/O errors while reading from the
  1438          *         underlying <code>InputStream</code>
  1442          *         underlying {@code InputStream}
  1439          * @throws IllegalArgumentException if type of <code>name</code> is
  1443          * @throws IllegalArgumentException if type of {@code name} is
  1440          *         not serializable or if the field type is incorrect
  1444          *         not serializable or if the field type is incorrect
  1441          */
  1445          */
  1442         public abstract float get(String name, float val) throws IOException;
  1446         public abstract float get(String name, float val) throws IOException;
  1443 
  1447 
  1444         /**
  1448         /**
  1445          * Get the value of the named double field from the persistent field.
  1449          * Get the value of the named double field from the persistent field.
  1446          *
  1450          *
  1447          * @param  name the name of the field
  1451          * @param  name the name of the field
  1448          * @param  val the default value to use if <code>name</code> does not
  1452          * @param  val the default value to use if {@code name} does not
  1449          *         have a value
  1453          *         have a value
  1450          * @return the value of the named <code>double</code> field
  1454          * @return the value of the named {@code double} field
  1451          * @throws IOException if there are I/O errors while reading from the
  1455          * @throws IOException if there are I/O errors while reading from the
  1452          *         underlying <code>InputStream</code>
  1456          *         underlying {@code InputStream}
  1453          * @throws IllegalArgumentException if type of <code>name</code> is
  1457          * @throws IllegalArgumentException if type of {@code name} is
  1454          *         not serializable or if the field type is incorrect
  1458          *         not serializable or if the field type is incorrect
  1455          */
  1459          */
  1456         public abstract double get(String name, double val) throws IOException;
  1460         public abstract double get(String name, double val) throws IOException;
  1457 
  1461 
  1458         /**
  1462         /**
  1459          * Get the value of the named Object field from the persistent field.
  1463          * Get the value of the named Object field from the persistent field.
  1460          *
  1464          *
  1461          * @param  name the name of the field
  1465          * @param  name the name of the field
  1462          * @param  val the default value to use if <code>name</code> does not
  1466          * @param  val the default value to use if {@code name} does not
  1463          *         have a value
  1467          *         have a value
  1464          * @return the value of the named <code>Object</code> field
  1468          * @return the value of the named {@code Object} field
  1465          * @throws IOException if there are I/O errors while reading from the
  1469          * @throws IOException if there are I/O errors while reading from the
  1466          *         underlying <code>InputStream</code>
  1470          *         underlying {@code InputStream}
  1467          * @throws IllegalArgumentException if type of <code>name</code> is
  1471          * @throws IllegalArgumentException if type of {@code name} is
  1468          *         not serializable or if the field type is incorrect
  1472          *         not serializable or if the field type is incorrect
  1469          */
  1473          */
  1470         public abstract Object get(String name, Object val) throws IOException;
  1474         public abstract Object get(String name, Object val) throws IOException;
  1471     }
  1475     }
  1472 
  1476 
  2406             throw new StreamCorruptedException(
  2410             throw new StreamCorruptedException(
  2407                 "unexpected reset; recursion depth: " + depth);
  2411                 "unexpected reset; recursion depth: " + depth);
  2408         }
  2412         }
  2409         clear();
  2413         clear();
  2410     }
  2414     }
  2411 
       
  2412     /**
       
  2413      * Converts specified span of bytes into float values.
       
  2414      */
       
  2415     // REMIND: remove once hotspot inlines Float.intBitsToFloat
       
  2416     private static native void bytesToFloats(byte[] src, int srcpos,
       
  2417                                              float[] dst, int dstpos,
       
  2418                                              int nfloats);
       
  2419 
       
  2420     /**
       
  2421      * Converts specified span of bytes into double values.
       
  2422      */
       
  2423     // REMIND: remove once hotspot inlines Double.longBitsToDouble
       
  2424     private static native void bytesToDoubles(byte[] src, int srcpos,
       
  2425                                               double[] dst, int dstpos,
       
  2426                                               int ndoubles);
       
  2427 
  2415 
  2428     /**
  2416     /**
  2429      * Returns the first non-null and non-platform class loader (not counting
  2417      * Returns the first non-null and non-platform class loader (not counting
  2430      * class loaders of generated reflection implementation classes) up the
  2418      * class loaders of generated reflection implementation classes) up the
  2431      * execution stack, or the platform class loader if only code from the
  2419      * execution stack, or the platform class loader if only code from the
  3427                 }
  3415                 }
  3428             }
  3416             }
  3429         }
  3417         }
  3430 
  3418 
  3431         void readFloats(float[] v, int off, int len) throws IOException {
  3419         void readFloats(float[] v, int off, int len) throws IOException {
  3432             int span, endoff = off + len;
  3420             int stop, endoff = off + len;
  3433             while (off < endoff) {
  3421             while (off < endoff) {
  3434                 if (!blkmode) {
  3422                 if (!blkmode) {
  3435                     span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
  3423                     int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
  3436                     in.readFully(buf, 0, span << 2);
  3424                     in.readFully(buf, 0, span << 2);
       
  3425                     stop = off + span;
  3437                     pos = 0;
  3426                     pos = 0;
  3438                 } else if (end - pos < 4) {
  3427                 } else if (end - pos < 4) {
  3439                     v[off++] = din.readFloat();
  3428                     v[off++] = din.readFloat();
  3440                     continue;
  3429                     continue;
  3441                 } else {
  3430                 } else {
  3442                     span = Math.min(endoff - off, ((end - pos) >> 2));
  3431                     stop = Math.min(endoff, ((end - pos) >> 2));
  3443                 }
  3432                 }
  3444 
  3433 
  3445                 bytesToFloats(buf, pos, v, off, span);
  3434                 while (off < stop) {
  3446                 off += span;
  3435                     v[off++] = Bits.getFloat(buf, pos);
  3447                 pos += span << 2;
  3436                     pos += 4;
       
  3437                 }
  3448             }
  3438             }
  3449         }
  3439         }
  3450 
  3440 
  3451         void readLongs(long[] v, int off, int len) throws IOException {
  3441         void readLongs(long[] v, int off, int len) throws IOException {
  3452             int stop, endoff = off + len;
  3442             int stop, endoff = off + len;
  3469                 }
  3459                 }
  3470             }
  3460             }
  3471         }
  3461         }
  3472 
  3462 
  3473         void readDoubles(double[] v, int off, int len) throws IOException {
  3463         void readDoubles(double[] v, int off, int len) throws IOException {
  3474             int span, endoff = off + len;
  3464             int stop, endoff = off + len;
  3475             while (off < endoff) {
  3465             while (off < endoff) {
  3476                 if (!blkmode) {
  3466                 if (!blkmode) {
  3477                     span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
  3467                     int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
  3478                     in.readFully(buf, 0, span << 3);
  3468                     in.readFully(buf, 0, span << 3);
       
  3469                     stop = off + span;
  3479                     pos = 0;
  3470                     pos = 0;
  3480                 } else if (end - pos < 8) {
  3471                 } else if (end - pos < 8) {
  3481                     v[off++] = din.readDouble();
  3472                     v[off++] = din.readDouble();
  3482                     continue;
  3473                     continue;
  3483                 } else {
  3474                 } else {
  3484                     span = Math.min(endoff - off, ((end - pos) >> 3));
  3475                     stop = Math.min(endoff - off, ((end - pos) >> 3));
  3485                 }
  3476                 }
  3486 
  3477 
  3487                 bytesToDoubles(buf, pos, v, off, span);
  3478                 while (off < stop) {
  3488                 off += span;
  3479                     v[off++] = Bits.getDouble(buf, pos);
  3489                 pos += span << 3;
  3480                     pos += 8;
       
  3481                 }
  3490             }
  3482             }
  3491         }
  3483         }
  3492 
  3484 
  3493         /**
  3485         /**
  3494          * Reads in string written in "long" UTF format.  "Long" UTF format is
  3486          * Reads in string written in "long" UTF format.  "Long" UTF format is