📄 xmlobjectoutputstream.java
字号:
} writer.attribute("type", "char"); writer.attribute("value", c); writer.end("primitive"); } /** * Method which writes a double to the stream, as the given field name. * * @param d The value to write to the stream * @param field The field name to use * @throws IOException If an error occurs */ protected void writePrimitive(double d, String field) throws IOException { writer.start("primitive"); if (field != null) { writer.attribute("field", field); } writer.attribute("type", "double"); writer.attribute("value", d); writer.end("primitive"); } /** * Method which writes a float to the stream, as the given field name. * * @param f The value to write to the stream * @param field The field name to use * @throws IOException If an error occurs */ protected void writePrimitive(float f, String field) throws IOException { writer.start("primitive"); if (field != null) { writer.attribute("field", field); } writer.attribute("type", "float"); writer.attribute("value", f); writer.end("primitive"); } /** * Method which writes a long to the stream, as the given field name. * * @param l The value to write to the stream * @param field The field name to use * @throws IOException If an error occurs */ protected void writePrimitive(long l, String field) throws IOException { writer.start("primitive"); if (field != null) { writer.attribute("field", field); } writer.attribute("type", "long"); writer.attribute("value", l); writer.end("primitive"); } /** * Method which writes a short to the stream, as the given field name. * * @param s The value to write to the stream * @param field The field name to use * @throws IOException If an error occurs */ protected void writePrimitive(short s, String field) throws IOException { writer.start("primitive"); if (field != null) { writer.attribute("field", field); } writer.attribute("type", "short"); writer.attribute("value", s); writer.end("primitive"); } /** * This method returns the readResolve() method of a given class, if such a * method exists. This method searches the class's heirarchy for a * readResolve() method which is assessible by the given class. If no such * method is found, null is returned. * * @param cl The class to find the readResolve() of * @return The method, or null if none was found */ private static Method getWriteObject(Class cl) { synchronized (WRITE_OBJECTS) { if (WRITE_OBJECTS.containsKey(cl)) { return (Method) WRITE_OBJECTS.get(cl); } try { Method method = cl.getDeclaredMethod("writeObject", new Class[]{ObjectOutputStream.class}); method.setAccessible(true); WRITE_OBJECTS.put(cl, method); return method; } catch (NoSuchMethodException e) { WRITE_OBJECTS.put(cl, null); return null; } } } // ----- Implementation of PutField ----- /** * This class is an implementation of PutField which is compatible with the * XMLObjectOutputStream. It works in the same manner as the * ObjectInputStream.PutField. * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public class PutField extends ObjectOutputStream.PutField { /** * DESCRIBE THE FIELD */ protected Hashtable primitives = new Hashtable(); /** * DESCRIBE THE FIELD */ protected Hashtable objects = new Hashtable(); /** * Gets the Primitives attribute of the PutField object * * @return The Primitives value */ protected String[] getPrimitives() { return (String[]) primitives.keySet().toArray(new String[0]); } /** * Gets the Objects attribute of the PutField object * * @return The Objects value */ protected String[] getObjects() { return (String[]) objects.keySet().toArray(new String[0]); } /** * Gets the Primitive attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Primitive value */ private Object getPrimitive(String name) { return primitives.get(name); } /** * Gets the Object attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Object value */ protected Object getObject(String name) { return objects.get(name); } /** * Gets the Boolean attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Boolean value */ protected boolean getBoolean(String name) { return ((Boolean) getPrimitive(name)).booleanValue(); } /** * Gets the Byte attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Byte value */ protected byte getByte(String name) { return ((Byte) getPrimitive(name)).byteValue(); } /** * Gets the Char attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Char value */ protected char getChar(String name) { return ((Character) getPrimitive(name)).charValue(); } /** * Gets the Double attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Double value */ protected double getDouble(String name) { return ((Double) getPrimitive(name)).doubleValue(); } /** * Gets the Float attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Float value */ protected float getFloat(String name) { return ((Float) getPrimitive(name)).floatValue(); } /** * Gets the Int attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Int value */ protected int getInt(String name) { return ((Integer) getPrimitive(name)).intValue(); } /** * Gets the Long attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Long value */ protected long getLong(String name) { return ((Long) getPrimitive(name)).longValue(); } /** * Gets the Short attribute of the PutField object * * @param name DESCRIBE THE PARAMETER * @return The Short value */ protected short getShort(String name) { return ((Short) getPrimitive(name)).shortValue(); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, boolean value) { primitives.put(name, new Boolean(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, byte value) { primitives.put(name, new Byte(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, char value) { primitives.put(name, new Character(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, double value) { primitives.put(name, new Double(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, float value) { primitives.put(name, new Float(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, int value) { primitives.put(name, new Integer(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, long value) { primitives.put(name, new Long(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, short value) { primitives.put(name, new Short(value)); } /** * DESCRIBE THE METHOD * * @param name DESCRIBE THE PARAMETER * @param value DESCRIBE THE PARAMETER */ public void put(String name, Object value) { objects.put(name, value); } /** * only exists to satisfy deprecated method in superclass * * @param output DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @deprecated */ public void write(ObjectOutput output) throws IOException { XMLObjectOutputStream xoos = (XMLObjectOutputStream) output; xoos.writeFields(); } } // Internal class for maintaining references /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ private class Reference { private Object object; /** * Constructor for Reference. * * @param object DESCRIBE THE PARAMETER */ public Reference(Object object) { this.object = object; } /** * DESCRIBE THE METHOD * * @return DESCRIBE THE RETURN VALUE */ public int hashCode() { return hash(object); } /** * DESCRIBE THE METHOD * * @param o DESCRIBE THE PARAMETER * @return DESCRIBE THE RETURN VALUE */ public boolean equals(Object o) { return (((Reference) o).object == object); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -