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 */ |
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 |