Description: | When a DataOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the DataOutputStream before invoking the underlying instances's toByteArray().
Also, it is a good practice to call flush/close explicitly as mentioned for example here.
This pull request adds a close method before calling toByteArray(). |
Code with Misuse: |
class BlobTest {
@Test
public void paintingTest() throws Exception
{
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
DataOutputStream outStream = new DataOutputStream(byteOutput);
PaintingBlob blobOut = BlobEntry.create(1, PaintingBlob.class);
blobOut.setArt("artistic");
blobOut.setDirection((byte) 5);
blobOut.write(outStream);
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(byteOutput.toByteArray()));
PaintingBlob blobIn = BlobEntry.create(1, PaintingBlob.class);
blobIn.read(inputStream);
Assert.assertEquals(blobOut, blobIn);
}
}
|