3

how to remove the Header added by objectOutputStream? what way should be the writeStreamHeader be Overriden..?

 @Override
 protected void writeStreamHeader() throws IOException {

   }

It want the byteOutputStream (to which i m writing the object) to contain only data ,no extra data ,byte etc..

Manas Pratim Chamuah
  • 1,527
  • 2
  • 15
  • 33
  • 2
    You have already answered your question yourself… – Holger Aug 26 '14 at 10:50
  • 1
    @Holger it just reduces 2-4 bytes.It want the size of the byteOutputStream (to which i m writing the object) to be same as the size of inputStream.plz help. – Manas Pratim Chamuah Aug 26 '14 at 10:54
  • 1
    The header consists of four bytes. When overriding the method with an empty method, these four bytes are not written. That’s what you asked for. I have no idea what inputStream you are talking about. There is no inputStream mentioned in your question. – Holger Aug 26 '14 at 11:12
  • 1
    If you want to write bytes then write to an `OutputStream`. If you want to write *objects* then accept that an `ObjectOutputStream` has a well defined format. After all, you want to *read* the objects somehow at a later time. – Holger Aug 26 '14 at 11:47

1 Answers1

0

If you want no header at all and only want to output Bytes. The following is an example to output INT 16(short) to a new file named "filename1". There will be no header at all.

FileOutputStream filOs = new FileOutputStream("fileName1");
ByteBuffer b = ByteBuffer.allocate(2);
b.order(ByteOrder.LITTLE_ENDIAN);
b.putShort(Short.valueOf("1"));
filOs.write(b.array());
filOs.close();
heinels
  • 189
  • 1
  • 6