Skip to content

Instantly share code, notes, and snippets.

@emopers
Last active December 28, 2015 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emopers/b8cd798fb22ed1e28949 to your computer and use it in GitHub Desktop.
Save emopers/b8cd798fb22ed1e28949 to your computer and use it in GitHub Desktop.
baos
Title:
Closing DataOutputStream before calling toByteArray on the underlying ByteArrayOutputStream
Subject:
When an DataOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the ObjectOutputStream before invoking the underlying instances's toByteArray().
Although in these cases this is not strictly necessary because the
DataOutputStream flush and close method have no effect. However, it is a good practice to call
flush/close explicitly as mentioned for example (here)
[http://stackoverflow.com/questions/2984538/how-to-use-bytearrayoutputstream-and-dataoutputstream-simultaneously-java]
This pull request adds close methods to close DataOutputStream. Even in the cases where DataOutputStream can
wrap any OutputStream like EncryptionParameters.java#writeTo, I added close method because some of the tests like EncryptionParametersTest.java
wraps them with ByteArrayOutputStream and then calls toByteArray.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment