You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "emopers (JIRA)" <ji...@apache.org> on 2016/02/04 06:39:39 UTC
[jira] [Updated] (PIG-4795) Flushing ObjectOutputStream before
calling toByteArray on the underlying ByteArrayOutputStream
[ https://issues.apache.org/jira/browse/PIG-4795?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
emopers updated PIG-4795:
-------------------------
Status: Patch Available (was: Open)
> Flushing ObjectOutputStream before calling toByteArray on the underlying ByteArrayOutputStream
> ----------------------------------------------------------------------------------------------
>
> Key: PIG-4795
> URL: https://issues.apache.org/jira/browse/PIG-4795
> Project: Pig
> Issue Type: Bug
> Reporter: emopers
> Labels: easyfix, patch
> Attachments: PIG-4795-0.patch
>
>
> In PigSplit.java
> {code}
> private void writeObject(Serializable obj, DataOutput os)
> throws IOException {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(baos);
> oos.writeObject(obj);
> byte[] bytes = baos.toByteArray();
> os.writeInt(bytes.length);
> os.write(bytes);
> }
> {code}
> When an ObjectOutputStream instance wraps an underlying ByteArrayOutputStream instance,
> it is recommended to flush or close the ObjectOutputStream before invoking the underlying instances's toByteArray(). Also, it is a good practice to call flush/close explicitly as mentioned for example at http://stackoverflow.com/questions/2984538/how-to-use-bytearrayoutputstream-and-dataoutputstream-simultaneously-java.
> The patch adds a flush method before calling toByteArray().
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)