pig-dev mailing list archives

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

     [ 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)

Mime
View raw message