> Anyway, for anyone else wanting to use ByteArrayStream in Java for
> writing a Google , here is some code I've used:
>
> ServerSocket serverSocket = new ServerSocket(2004, 10);
> Socket socket = serverSocket.accept();
> OutputStream outputStream = socket.getOutputStream();
> outputStream.flush();
>
> MyGPBObjects.MyGPBObject myGPBObject =
> MyGPBObjectsFactory.instance.createMyGPBObject();
> ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream
> ();
> myGPBObject.writeTo(byteArrayOutputStream);
> byteArrayOutputStream.flush();
> byteArrayOutputStream.writeTo(outputStream);

What you're doing with the ByteArrayOutputStream will do the same thing as:

OutputStream outputStream = socket.getOutputStream();
myGPBObject.writeTo(outputStream);

except that it takes more time and uses more memory.  You don't need
an intermediate output stream, you already have the socket's output
stream.  You can just write directly to that.

- Adam

--

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.


Reply via email to