[
https://issues.apache.org/jira/browse/HADOOP-11392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14243684#comment-14243684
]
Yongjun Zhang commented on HADOOP-11392:
----------------------------------------
Thanks [~cnauroth], after looking closer at {{IOUtils.copyBytes(in, out, conf,
true);}}, I think you are right. There is actually no functionality problem. I
was a bit confused earlier because I didn't expect {{IOUtils.copyBytes(in, out,
conf);}} would close the streams.
I think having open/close of stream at the same piece of code would be more
clear:
{code}
InputStream in = null;
try {
in = new FileInputStream(src);
// do stuff with in
} catch (IOException e) {
throw e;
} finally {
IOUtils.closeStream(in);
}
{code}
Notice that IOUtils.closeStream() handles null input parameter.
Or, as an improvement for readability, we could rename {{IOUtils.copyBytes}}
here to {{IOUtils.copyBytesAndCloseStreams}}. Unfortunately IOUtils is a public
interface, making such a change would break compatibility.
Hi [~brahmareddy], the other case you listed in your latest comment is also not
an issue because there is one outer "finally" block that closes "out" stream.
Thanks.
> FileUtil.java leaks file descriptor when copybytes success.
> -----------------------------------------------------------
>
> Key: HADOOP-11392
> URL: https://issues.apache.org/jira/browse/HADOOP-11392
> Project: Hadoop Common
> Issue Type: Bug
> Reporter: Brahma Reddy Battula
> Assignee: Brahma Reddy Battula
> Attachments: HADOOP-11392.patch
>
>
> Please check following code for same..
> {code}
> try {
> in = srcFS.open(src);
> out = dstFS.create(dst, overwrite);
> IOUtils.copyBytes(in, out, conf, true);
> } catch (IOException e) {
> IOUtils.closeStream(out);
> IOUtils.closeStream(in);
> throw e;
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)