String className = in.readUTF(); Externalizable extern = null; try { extern = (Externalizable) Class.forName( className ).newInstance(); } catch (Exception e) {  System.out.println("Unable to instantiate Serializable \"" + className + "\"" + e); throw new IOException( e.toString() );
byte type = in.readByte(); switch (type) { case TYPE_EXTERNALIZABLE: String className = in.readUTF(); Externalizable extern = null; try { extern = (Externalizable) Class.forName( className ).newInstance(); } catch (Exception e) {  System.out.println("Unable to instantiate Serializable \"" + className + "\"" + e); throw new IOException( e.toString() ); } extern.read( in ); return extern; case TYPE_EXTERNALIZABLE_ARRAY: int length = in.readInt(); Externalizable[] externalizables = new Externalizable[ length ]; Class[] classes = new Class[ Math.max( length, 7 ) ]; Class currentClass; byte idCounter = 0; for (int i = 0; i < externalizables.length; i++) { int classId = in.readByte(); if (classId == 0) { className = in.readUTF(); try { currentClass = Class.forName( className ); } catch (ClassNotFoundException e) {  System.out.println("Unable to load Serializable class \"" + className + "\"" + e); throw new IOException( e.toString() ); } if (idCounter > classes.length ) { Class[] newClasses = new Class[ classes.length + 7 ]; System.arraycopy(classes, 0, newClasses, 0, classes.length); classes = newClasses; } classes[idCounter] = currentClass; idCounter++; } else { currentClass = classes[ classId ]; } Externalizable externalizable; try { externalizable = (Externalizable) currentClass.newInstance(); externalizable.read(in); externalizables[i] = externalizable; } catch (Exception e) {  System.out.println("Unable to instantiate Serializable \"" + currentClass.getName() + "\"" + e); throw new IOException( e.toString() ); } } return externalizables; case TYPE_OBJECT_ARRAY: length = in.readInt(); Object[] objects = new Object[ length ]; for (int i = 0; i < objects.length; i++) { objects[i] = deserialize(in); } return objects; case TYPE_BYTE: return new Byte( in.readByte() ); case TYPE_SHORT: return new Short( in.readShort() ); case TYPE_INTEGER: return new Integer( in.readInt() ); case TYPE_LONG: return new Long( in.readLong() );  case TYPE_FLOAT: return new Float( in.readFloat() ); case TYPE_DOUBLE: return new Double( in.readDouble() );  case TYPE_STRING: return in.readUTF(); case TYPE_STRING_BUFFER: return new StringBuffer( in.readUTF() ); case TYPE_CHARACTER: return new Character( in.readChar() ); case TYPE_BOOLEAN: return new Boolean( in.readBoolean() ); case TYPE_DATE: return new Date( in.readLong() ); case TYPE_CALENDAR: Calendar calendar = Calendar.getInstance(); calendar.setTime( new Date(in.readLong()) ); return calendar; case TYPE_RANDOM: return new Random(); case TYPE_HASHTABLE: int size = in.readInt(); Hashtable hashtable = new Hashtable( size ); for (int i = 0; i < size; i++) { Object key = deserialize(in); Object value = deserialize(in); hashtable.put( key, value ); } return hashtable; case TYPE_STACK: case TYPE_VECTOR: size = in.readInt(); Vector vector; if (type == TYPE_STACK) { vector = new Stack(); } else { vector = new Vector( size ); } for (int i = 0; i < size; i++) { Object value = deserialize(in); vector.addElement( value ); } return vector;  case TYPE_IMAGE: int width = in.readInt(); int height = in.readInt(); int[] rgb = new int[ width * height ]; for (int i = 0; i < rgb.length; i++) { rgb[i] = in.readInt(); } return Image.createRGBImage(rgb, width, height, true );   case TYPE_FONT: int face = in.readInt(); int style = in.readInt(); size = in.readInt(); return Font.getFont(face, style, size); case TYPE_COMMAND: int cmdType = in.readInt(); int priority = in.readInt(); String label = in.readUTF(); return new Command( label, cmdType, priority );  default: throw new IOException("Unknown type: " + type );
	public static Serializable deserialize( DataInputStream in )	throws IOException	{		byte version = in.readByte();		//#if polish.debug.warn			if (version > VERSION) {				//#debug warn				System.out.println("Warning: trying to deserialize class that has been serialized with a newer version (" + version + ">" + VERSION + ").");			}		//#endif		boolean isNull = in.readBoolean();		if (isNull) {			return null;		}		String className = in.readUTF();		Externalizable extern = null;		try {			extern = (Externalizable) Class.forName( className ).newInstance();		} catch (Exception e) {			//#debug error			System.out.println("Unable to instantiate Serializable \"" + className + "\"" + e);			throw new IOException( e.toString() );		}		extern.read( in );		return extern;	}