pig-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dai (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PIG-4795) Flushing ObjectOutputStream before calling toByteArray on the underlying ByteArrayOutputStream
Date Fri, 05 Feb 2016 01:06:39 GMT

    [ https://issues.apache.org/jira/browse/PIG-4795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15133445#comment-15133445
] 

Daniel Dai commented on PIG-4795:
---------------------------------

Do you see a specific error in your environment?

> 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
>            Priority: Minor
>              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)

Mime
View raw message