Expand|Select|Wrap|Line Numbers
- public class test_serialisation implements Serializable{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ObjectOutputStream ob;
- FileOutputStream f;
- Object ob1;
- //DatagramSocket sck=new DatagramSocket();
- ByteArrayOutputStream buf;
- byte[] arr1=new byte[256];
- try {
- buf=new ByteArrayOutputStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new test_serialisation());
- oos.flush();
- oos.close();
- byte[] sendBytes = baos.toByteArray();
- System.out.println("testing bytes array.........");
- System.out.println(sendBytes.length);
- System.out.println("sendBytes.length : " + sendBytes.length);
- //ds.send(dp);
- ByteArrayInputStream out=new ByteArrayInputStream(arr1);
- ObjectInputStream n=new ObjectInputStream(out);
- test_serialisation bb=(test_serialisation) n.readObject();
- bb.test();
- FileInputStream in = new FileInputStream("tmp");
- ObjectInputStream ss = new ObjectInputStream(in);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void test(){
- System.out.println("Serialisation working");
- }
- }
Expand|Select|Wrap|Line Numbers
- java.io.StreamCorruptedException: invalid stream header
- at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
- at java.io.ObjectInputStream.<init>(Unknown Source)
- at test_serialisation.main(test_serialisation.java:55)
Thanks in advance