644 * Write the specified class descriptor to the ObjectOutputStream. Class |
644 * Write the specified class descriptor to the ObjectOutputStream. Class |
645 * descriptors are used to identify the classes of objects written to the |
645 * descriptors are used to identify the classes of objects written to the |
646 * stream. Subclasses of ObjectOutputStream may override this method to |
646 * stream. Subclasses of ObjectOutputStream may override this method to |
647 * customize the way in which class descriptors are written to the |
647 * customize the way in which class descriptors are written to the |
648 * serialization stream. The corresponding method in ObjectInputStream, |
648 * serialization stream. The corresponding method in ObjectInputStream, |
649 * <code>readClassDescriptor</code>, should then be overridden to |
649 * {@code readClassDescriptor}, should then be overridden to |
650 * reconstitute the class descriptor from its custom stream representation. |
650 * reconstitute the class descriptor from its custom stream representation. |
651 * By default, this method writes class descriptors according to the format |
651 * By default, this method writes class descriptors according to the format |
652 * defined in the Object Serialization specification. |
652 * defined in the Object Serialization specification. |
653 * |
653 * |
654 * <p>Note that this method will only be called if the ObjectOutputStream |
654 * <p>Note that this method will only be called if the ObjectOutputStream |
655 * is not using the old serialization stream format (set by calling |
655 * is not using the old serialization stream format (set by calling |
656 * ObjectOutputStream's <code>useProtocolVersion</code> method). If this |
656 * ObjectOutputStream's {@code useProtocolVersion} method). If this |
657 * serialization stream is using the old format |
657 * serialization stream is using the old format |
658 * (<code>PROTOCOL_VERSION_1</code>), the class descriptor will be written |
658 * ({@code PROTOCOL_VERSION_1}), the class descriptor will be written |
659 * internally in a manner that cannot be overridden or customized. |
659 * internally in a manner that cannot be overridden or customized. |
660 * |
660 * |
661 * @param desc class descriptor to write to the stream |
661 * @param desc class descriptor to write to the stream |
662 * @throws IOException If an I/O error has occurred. |
662 * @throws IOException If an I/O error has occurred. |
663 * @see java.io.ObjectInputStream#readClassDescriptor() |
663 * @see java.io.ObjectInputStream#readClassDescriptor() |
877 * to ObjectOutput. |
877 * to ObjectOutput. |
878 * |
878 * |
879 * @since 1.2 |
879 * @since 1.2 |
880 */ |
880 */ |
881 public abstract static class PutField { |
881 public abstract static class PutField { |
|
882 /** |
|
883 * Constructor for subclasses to call. |
|
884 */ |
|
885 public PutField() {} |
882 |
886 |
883 /** |
887 /** |
884 * Put the value of the named boolean field into the persistent field. |
888 * Put the value of the named boolean field into the persistent field. |
885 * |
889 * |
886 * @param name the name of the serializable field |
890 * @param name the name of the serializable field |
887 * @param val the value to assign to the field |
891 * @param val the value to assign to the field |
888 * @throws IllegalArgumentException if <code>name</code> does not |
892 * @throws IllegalArgumentException if {@code name} does not |
889 * match the name of a serializable field for the class whose fields |
893 * match the name of a serializable field for the class whose fields |
890 * are being written, or if the type of the named field is not |
894 * are being written, or if the type of the named field is not |
891 * <code>boolean</code> |
895 * {@code boolean} |
892 */ |
896 */ |
893 public abstract void put(String name, boolean val); |
897 public abstract void put(String name, boolean val); |
894 |
898 |
895 /** |
899 /** |
896 * Put the value of the named byte field into the persistent field. |
900 * Put the value of the named byte field into the persistent field. |
897 * |
901 * |
898 * @param name the name of the serializable field |
902 * @param name the name of the serializable field |
899 * @param val the value to assign to the field |
903 * @param val the value to assign to the field |
900 * @throws IllegalArgumentException if <code>name</code> does not |
904 * @throws IllegalArgumentException if {@code name} does not |
901 * match the name of a serializable field for the class whose fields |
905 * match the name of a serializable field for the class whose fields |
902 * are being written, or if the type of the named field is not |
906 * are being written, or if the type of the named field is not |
903 * <code>byte</code> |
907 * {@code byte} |
904 */ |
908 */ |
905 public abstract void put(String name, byte val); |
909 public abstract void put(String name, byte val); |
906 |
910 |
907 /** |
911 /** |
908 * Put the value of the named char field into the persistent field. |
912 * Put the value of the named char field into the persistent field. |
909 * |
913 * |
910 * @param name the name of the serializable field |
914 * @param name the name of the serializable field |
911 * @param val the value to assign to the field |
915 * @param val the value to assign to the field |
912 * @throws IllegalArgumentException if <code>name</code> does not |
916 * @throws IllegalArgumentException if {@code name} does not |
913 * match the name of a serializable field for the class whose fields |
917 * match the name of a serializable field for the class whose fields |
914 * are being written, or if the type of the named field is not |
918 * are being written, or if the type of the named field is not |
915 * <code>char</code> |
919 * {@code char} |
916 */ |
920 */ |
917 public abstract void put(String name, char val); |
921 public abstract void put(String name, char val); |
918 |
922 |
919 /** |
923 /** |
920 * Put the value of the named short field into the persistent field. |
924 * Put the value of the named short field into the persistent field. |
921 * |
925 * |
922 * @param name the name of the serializable field |
926 * @param name the name of the serializable field |
923 * @param val the value to assign to the field |
927 * @param val the value to assign to the field |
924 * @throws IllegalArgumentException if <code>name</code> does not |
928 * @throws IllegalArgumentException if {@code name} does not |
925 * match the name of a serializable field for the class whose fields |
929 * match the name of a serializable field for the class whose fields |
926 * are being written, or if the type of the named field is not |
930 * are being written, or if the type of the named field is not |
927 * <code>short</code> |
931 * {@code short} |
928 */ |
932 */ |
929 public abstract void put(String name, short val); |
933 public abstract void put(String name, short val); |
930 |
934 |
931 /** |
935 /** |
932 * Put the value of the named int field into the persistent field. |
936 * Put the value of the named int field into the persistent field. |
933 * |
937 * |
934 * @param name the name of the serializable field |
938 * @param name the name of the serializable field |
935 * @param val the value to assign to the field |
939 * @param val the value to assign to the field |
936 * @throws IllegalArgumentException if <code>name</code> does not |
940 * @throws IllegalArgumentException if {@code name} does not |
937 * match the name of a serializable field for the class whose fields |
941 * match the name of a serializable field for the class whose fields |
938 * are being written, or if the type of the named field is not |
942 * are being written, or if the type of the named field is not |
939 * <code>int</code> |
943 * {@code int} |
940 */ |
944 */ |
941 public abstract void put(String name, int val); |
945 public abstract void put(String name, int val); |
942 |
946 |
943 /** |
947 /** |
944 * Put the value of the named long field into the persistent field. |
948 * Put the value of the named long field into the persistent field. |
945 * |
949 * |
946 * @param name the name of the serializable field |
950 * @param name the name of the serializable field |
947 * @param val the value to assign to the field |
951 * @param val the value to assign to the field |
948 * @throws IllegalArgumentException if <code>name</code> does not |
952 * @throws IllegalArgumentException if {@code name} does not |
949 * match the name of a serializable field for the class whose fields |
953 * match the name of a serializable field for the class whose fields |
950 * are being written, or if the type of the named field is not |
954 * are being written, or if the type of the named field is not |
951 * <code>long</code> |
955 * {@code long} |
952 */ |
956 */ |
953 public abstract void put(String name, long val); |
957 public abstract void put(String name, long val); |
954 |
958 |
955 /** |
959 /** |
956 * Put the value of the named float field into the persistent field. |
960 * Put the value of the named float field into the persistent field. |
957 * |
961 * |
958 * @param name the name of the serializable field |
962 * @param name the name of the serializable field |
959 * @param val the value to assign to the field |
963 * @param val the value to assign to the field |
960 * @throws IllegalArgumentException if <code>name</code> does not |
964 * @throws IllegalArgumentException if {@code name} does not |
961 * match the name of a serializable field for the class whose fields |
965 * match the name of a serializable field for the class whose fields |
962 * are being written, or if the type of the named field is not |
966 * are being written, or if the type of the named field is not |
963 * <code>float</code> |
967 * {@code float} |
964 */ |
968 */ |
965 public abstract void put(String name, float val); |
969 public abstract void put(String name, float val); |
966 |
970 |
967 /** |
971 /** |
968 * Put the value of the named double field into the persistent field. |
972 * Put the value of the named double field into the persistent field. |
969 * |
973 * |
970 * @param name the name of the serializable field |
974 * @param name the name of the serializable field |
971 * @param val the value to assign to the field |
975 * @param val the value to assign to the field |
972 * @throws IllegalArgumentException if <code>name</code> does not |
976 * @throws IllegalArgumentException if {@code name} does not |
973 * match the name of a serializable field for the class whose fields |
977 * match the name of a serializable field for the class whose fields |
974 * are being written, or if the type of the named field is not |
978 * are being written, or if the type of the named field is not |
975 * <code>double</code> |
979 * {@code double} |
976 */ |
980 */ |
977 public abstract void put(String name, double val); |
981 public abstract void put(String name, double val); |
978 |
982 |
979 /** |
983 /** |
980 * Put the value of the named Object field into the persistent field. |
984 * Put the value of the named Object field into the persistent field. |
981 * |
985 * |
982 * @param name the name of the serializable field |
986 * @param name the name of the serializable field |
983 * @param val the value to assign to the field |
987 * @param val the value to assign to the field |
984 * (which may be <code>null</code>) |
988 * (which may be {@code null}) |
985 * @throws IllegalArgumentException if <code>name</code> does not |
989 * @throws IllegalArgumentException if {@code name} does not |
986 * match the name of a serializable field for the class whose fields |
990 * match the name of a serializable field for the class whose fields |
987 * are being written, or if the type of the named field is not a |
991 * are being written, or if the type of the named field is not a |
988 * reference type |
992 * reference type |
989 */ |
993 */ |
990 public abstract void put(String name, Object val); |
994 public abstract void put(String name, Object val); |
991 |
995 |
992 /** |
996 /** |
993 * Write the data and fields to the specified ObjectOutput stream, |
997 * Write the data and fields to the specified ObjectOutput stream, |
994 * which must be the same stream that produced this |
998 * which must be the same stream that produced this |
995 * <code>PutField</code> object. |
999 * {@code PutField} object. |
996 * |
1000 * |
997 * @param out the stream to write the data and fields to |
1001 * @param out the stream to write the data and fields to |
998 * @throws IOException if I/O errors occur while writing to the |
1002 * @throws IOException if I/O errors occur while writing to the |
999 * underlying stream |
1003 * underlying stream |
1000 * @throws IllegalArgumentException if the specified stream is not |
1004 * @throws IllegalArgumentException if the specified stream is not |
1001 * the same stream that produced this <code>PutField</code> |
1005 * the same stream that produced this {@code PutField} |
1002 * object |
1006 * object |
1003 * @deprecated This method does not write the values contained by this |
1007 * @deprecated This method does not write the values contained by this |
1004 * <code>PutField</code> object in a proper format, and may |
1008 * {@code PutField} object in a proper format, and may |
1005 * result in corruption of the serialization stream. The |
1009 * result in corruption of the serialization stream. The |
1006 * correct way to write <code>PutField</code> data is by |
1010 * correct way to write {@code PutField} data is by |
1007 * calling the {@link java.io.ObjectOutputStream#writeFields()} |
1011 * calling the {@link java.io.ObjectOutputStream#writeFields()} |
1008 * method. |
1012 * method. |
1009 */ |
1013 */ |
1010 @Deprecated |
1014 @Deprecated |
1011 public abstract void write(ObjectOutput out) throws IOException; |
1015 public abstract void write(ObjectOutput out) throws IOException; |