Sunday, January 27, 2008

converting inputstream to octetstream

The other day I was working with soap attachments and stumbled across OctetStream. Had no idea on this stream type which made me lookaround and came up with this info:

org.apache.axis.attachments.OctetStream corresponds to mime type "application/octetstream"

-- Converting Inputstream to OctetStream

ByteArrayOutputStream baos = new ByteArrayOutputStream();
int byte1 = -1;
while ((byte1 = in.read()) != -1)
baos.write(byte1);
return new OctetStream(baos.toByteArray());