[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2018-06-09 Thread Bruno P. Kinoshita (JIRA)


[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16506882#comment-16506882
 ] 

Bruno P. Kinoshita commented on IO-554:
---

TL;DR;
 * *2.5 did not close the stream*
 * *2.6 closed the stream after the introduction of try-with-resources*
 * *This issue is about the changed behaviour, with a pull request to revert it 
back to 2.5 behaviour*

Recapitulating;

I believe the *copyToFile* method was released with Release 2.5 – 2016-04-22, 
added in this commit from IO-381 from May 2013 
[https://github.com/apache/commons-io/commit/ee2f71d9fd2ce253f53de137950fa90087b9f565]

The code from the 2.5 released tag reads:
{code:java}
/**
 * Copies bytes from an {@link InputStream} source to a file
 * destination. The directories up to destination
 * will be created if they don't already exist. destination
 * will be overwritten if it already exists.
 * The {@code source} stream is left open, e.g. for use with {@link 
java.util.zip.ZipInputStream ZipInputStream}.
 * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
closes the input stream.
 *
 * @param source  the InputStream to copy bytes from, must 
not be {@code null}
 * @param destination the non-directory File to write bytes to
 *(possibly overwriting), must not be {@code null}
 * @throws IOException if destination is a directory
 * @throws IOException if destination cannot be written
 * @throws IOException if destination needs creating but can't 
be
 * @throws IOException if an IO error occurs during copying
 * @since 2.5
 */
public static void copyToFile(final InputStream source, final File 
destination) throws IOException {
final FileOutputStream output = openOutputStream(destination);
try {
IOUtils.copy(source, output);
output.close(); // don't swallow close Exception if copy completes 
normally
} finally {
IOUtils.closeQuietly(output);
}
}
{code}
NB the Javadocs states "*The \{@code source} stream is left open*". I had a 
look at the code, and tested in Eclipse, and it is indeed left open.
 
 But on this commit from May 2016, released later with Release 2.6 – 
2017-10-15, we added try-with-resources, which changed the behaviour of the 
code.
 
 The code from IO-505 from the 2.6 released tag_**_ reads:
{code:java}
    /**
 * Copies bytes from an {@link InputStream} source to a file
 * destination. The directories up to destination
 * will be created if they don't already exist. destination
 * will be overwritten if it already exists.
 * The {@code source} stream is left open, e.g. for use with {@link 
java.util.zip.ZipInputStream ZipInputStream}.
 * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
closes the input stream.
 *
 * @param source  the InputStream to copy bytes from, must 
not be {@code null}
 * @param destination the non-directory File to write bytes to
 *    (possibly overwriting), must not be {@code null}
 * @throws IOException if destination is a directory
 * @throws IOException if destination cannot be written
 * @throws IOException if destination needs creating but can't 
be
 * @throws IOException if an IO error occurs during copying
 * @since 2.5
 */
    public static void copyToFile(final InputStream source, final File 
destination) throws IOException {
    try (InputStream in = source;
 OutputStream out = openOutputStream(destination)) {
    IOUtils.copy(in, out);
    }
    }
{code}
NB the Javadocs states "*The \{@code source} stream is left open*". But the 
try-with-resources closes the in/source input stream. I think this change in 
the behaviour was not intentional.

The pull request for this issue is proposing to revert what was added in 2.6. I 
would not use commons-io-2.6 `copyToFile`, as I would normally handle the 
stream myself, or use the other method that already closed the stream before.

[~tmortagne],

>I agree that behavior should not change but that's actually an argument for a 
>bugfix release as fast as possible, not to keep a regression.

+1

In a similar case, Commons Pool 2.4.3 kept binary compatibility but changed the 
way the code worked when iterating stack traces (see POOL-320), which caused an 
issue and prevented us from using this version in Commons DBCP. Instead of 
keeping the method and adding a new one, or updating documentation, we reverted 
the change in 2.5.0 (see POOL-335).

In my opinion we should revert the regression added in 2.6, with [~mmariotti] 
's pull request suggested, which also includes a unit test to prevent the 
regression from happening again.

Cheers

Bruno

(**) There is a tag commons-io-2.5, but no commons-io-2.6, only RC1, RC2, and 
commons-io-2.6-RC3.

> 

[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2018-06-08 Thread Gary Gregory (JIRA)


[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16506089#comment-16506089
 ] 

Gary Gregory commented on IO-554:
-

We should pull this change in, this is just a plain old bug.

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-06 Thread Bernd Eckenfels (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16240022#comment-16240022
 ] 

Bernd Eckenfels commented on IO-554:


2.5 and before did not close the file. So this is a change which violates the 
Javadoc spec and was introduced in 2.6, this is IMHO enough justification to 
revert to the documented behavior. Of course the releasenotes for 2.7 should 
have a fat warning about this.

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-06 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16240019#comment-16240019
 ] 

Bruno P. Kinoshita commented on IO-554:
---

>Fact is, if we pull that one in, then the next version will behave different, 
>which makes it binary incompatible.

I **think** it would be behavioural imcompatible per [1] and [2]. But I may be 
wrong.

>Perhaps, a discussion on devs@commons is in order.

+1, others would be able to clear up any confusion and having a consensus on 
this now would be better than waiting to discuss it during a release vote. 
Shall I start the thread?

[1] https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.2
[2] 
https://blogs.oracle.com/darcy/kinds-of-compatibility:-source,-binary,-and-behavioral

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Jochen Wiedmann (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16240010#comment-16240010
 ] 

Jochen Wiedmann commented on IO-554:


Fact is, if we pull that one in, then the next version will behave different, 
which makes it binary incompatible. Perhaps, a discussion on devs@commons is in 
order.


> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239738#comment-16239738
 ] 

Bruno P. Kinoshita commented on IO-554:
---

[~joc...@apache.org]

>For the sake of binary compatibility, I'd suggest an alternate proposal

I think the change is still binary compatible, but not API/behavioral 
compatible? Though I always get confused with these two...

As it seems like a bug/regression added accidentally in 2.6, I thought it could 
still be fixed as in the pull request, and released in a 2.7 version. What do 
you think?

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Michele Mariotti (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239595#comment-16239595
 ] 

Michele Mariotti commented on IO-554:
-

There is already a method which closes the input stream: it is 
FileUtils.copyInputStreamToFile.
The only difference between methods is the closure of input stream.
However, I agree that the method names are an unhappy choice and that should be 
renamed to something more meaningful.

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Jochen Wiedmann (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239579#comment-16239579
 ] 

Jochen Wiedmann commented on IO-554:


For the sake of binary compatibility, I'd suggest an alternate proposal:

- Change the Javadocs of FileUtils.copyToFile to reflect the current situation.
- Introduce a new method copyToFile(InputStream, File, boolean), which is 
basically doing the same than the old implementation, except that the last 
parameter decides upon closing, or not.



> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Michele Mariotti (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239495#comment-16239495
 ] 

Michele Mariotti commented on IO-554:
-

test case added

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Bernd Eckenfels (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239471#comment-16239471
 ] 

Bernd Eckenfels commented on IO-554:


Can you add a test case as well?

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread Michele Mariotti (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239466#comment-16239466
 ] 

Michele Mariotti commented on IO-554:
-

Created Pull Request [#49|https://github.com/apache/commons-io/pull/49].

Glad to help :)

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239465#comment-16239465
 ] 

ASF GitHub Bot commented on IO-554:
---

GitHub user mmariotti opened a pull request:

https://github.com/apache/commons-io/pull/49

[IO-554] fixed: prevent input stream close

[IO-554] FileUtils.copyToFile(InputStream source, File destination) closes 
input stream.
Fixed removing 'source' from try-with-resources.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/mmariotti/commons-io patch-1

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/commons-io/pull/49.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #49


commit c9fb10f0e45ec66cff342692fd440d06da250e88
Author: Michele Mariotti 
Date:   2017-11-05T09:32:16Z

[IO-554] fixed: prevent input stream close

[IO-554] FileUtils.copyToFile(InputStream source, File destination) closes 
input stream.
Fixed removing 'source' from try-with-resources.




> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Assignee: Bruno P. Kinoshita
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

2017-11-04 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16239364#comment-16239364
 ] 

Bruno P. Kinoshita commented on IO-554:
---

Nice catch [~mmariotti]

Would you like to submit a pull request with this change? If not, let me know 
and I'll quickly prepare a pull request and credit you.

Thanks
Bruno

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> --
>
> Key: IO-554
> URL: https://issues.apache.org/jira/browse/IO-554
> Project: Commons IO
>  Issue Type: Bug
>  Components: Streams/Writers
>Affects Versions: 2.6
>Reporter: Michele Mariotti
>Priority: Blocker
>  Labels: regression
> Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the 
> opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing 
> code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} source to a file
>  * destination. The directories up to destination
>  * will be created if they don't already exist. destination
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link 
> java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that 
> closes the input stream.
>  *
>  * @param source  the InputStream to copy bytes from, must 
> not be {@code null}
>  * @param destination the non-directory File to write bytes to
>  *(possibly overwriting), must not be {@code null}
>  * @throws IOException if destination is a directory
>  * @throws IOException if destination cannot be written
>  * @throws IOException if destination needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (InputStream in = source;
>OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(in, out);
>   }
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File 
> destination) throws IOException {
>   try (OutputStream out = openOutputStream(destination)) {
>   IOUtils.copy(source, out);
>   }
> }{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)