性能提高技巧之一:使用ByteArrayInputStream或ByteArrayOnputStream
和sokcet的结合
DataInputStream in = new DataInputStream ( socket.getInputStream ( ) );
byte[ ] barray = new Byte [ sizeNeeded ];
in.read ( barray );
ByteArrayInputStream bais = new ByteArrayInputStream ( barray );
对象可以通过数据包传送:
Writing Object to stream
-------------------------
//create ByteArrayOutputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//create ObjectOutputStream to write objects
ObjectOutputStream oos = new ObjectOutputStream(baos);
//write the object to the stream
oos.writeObject(obj);
//flush the stream
oos.flush();
Reading Object from stream
-------------------------
//byte array input stream
ByteArrayInputStream bais = new ByteArrayInputStream(data);
//object input stream
ObjectInputStream ois = new ObjectInputStream(bais);
//object from the stream
ois.readObject();