Assuming using an ObjectOutputStream , build it around java.io.ByteArrayOutputStream :
ByteArrayOutputStream contentBytes = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(contentBytes); objectOut.writeObject(content); int contentLength = contentBytes.size();
And then you can send the content using
contentBytes.writeTo(connection.getOutputStream());
where connection is what you get from OutputStream .
Better late than never, right?
source share