You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/02/19 16:39:48 UTC

[GitHub] [commons-io] jmark109 opened a new pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

jmark109 opened a new pull request #206:
URL: https://github.com/apache/commons-io/pull/206


   Add DeferredFileOutputStream.getInputStream() for efficient retrieval of OutputSteam data.
   
   Fixes IO-651.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580305820



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,

Review comment:
       Won't work here since the `DeferredFileOutputStream` needs to be closed while it is still in scope in order to execute `toInputStream()`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r579489683



##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,31 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @throws IOException if this stream is not yet closed or an error occurs.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream#toInputStream()

Review comment:
       Needs a Javadoc since tag.

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testAboveThresholdGetInputStream(final int initialBufferSize, @TempDir Path tempDir) throws IOException {
+        final File testFile = tempDir.resolve("testAboveThreshold.dat").toFile();
+
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length - 5, initialBufferSize,
+            testFile);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertFalse(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {

Review comment:
       Missing space after "try".

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {

Review comment:
       Missing space after "try".

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testAboveThresholdGetInputStream(final int initialBufferSize, @TempDir Path tempDir) throws IOException {
+        final File testFile = tempDir.resolve("testAboveThreshold.dat").toFile();
+
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length - 5, initialBufferSize,
+            testFile);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertFalse(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);

Review comment:
       No need for intermediary local variable.
   

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,

Review comment:
       Use try-with-resources.

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");

Review comment:
       Useless catch. 

##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")

Review comment:
       See other comments, which apply here as well. Use final in method parmeter.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782228140


   @garydgregory Yes, I see that. I don't think these failures have anything to do with my changes. Looks like some type of misconfiguration with the build. I see errors like this:
   ```
   java.lang.IllegalAccessError: class org.apache.commons.io.input.BufferedFileChannelInputStream (in unnamed module @0x685f4c2e) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x685f4c2e
   ```
   I did not touch that class. I only added one new method to `DeferredFileOutputStream` so it should not affect any other tests.
   
   When I build locally everything works fine.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782252971


   @garydgregory I just ran `mvn package` again and it was successful. I don't see any errors.
   I also tried running `mvn test` just to make sure, and no errors either.
   What errors do you see?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 edited a comment on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 edited a comment on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782320401


   @garydgregory I think this is good to go now. Let me know if there are any other issues.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-783439763


   @garydgregory Issues have been addressed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory merged pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
garydgregory merged pull request #206:
URL: https://github.com/apache/commons-io/pull/206


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] XenoAmess commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
XenoAmess commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r579396064



##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,27 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream.toInputStream()

Review comment:
       @see org.apache.commons.io.output.ByteArrayOutputStream#toInputStream()

##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,27 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream.toInputStream()

Review comment:
       ```@see org.apache.commons.io.output.ByteArrayOutputStream#toInputStream()```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] coveralls edited a comment on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782224839


   
   [![Coverage Status](https://coveralls.io/builds/37332860/badge)](https://coveralls.io/builds/37332860)
   
   Coverage increased (+0.1%) to 89.383% when pulling **99f52c851f263e12da83982d001db190331643d8 on jmark109:IO-651_DeferredFileOutputStream_getInputStream** into **5833b831ffe2bf8cdb74ee5567c8ae33abb0c7f4 on apache:master**.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] coveralls edited a comment on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782224839


   
   [![Coverage Status](https://coveralls.io/builds/37283381/badge)](https://coveralls.io/builds/37283381)
   
   Coverage decreased (-0.1%) to 89.254% when pulling **f424ab6d90fd01a1cad883d3a05c3a409c3a8405 on jmark109:IO-651_DeferredFileOutputStream_getInputStream** into **c54bf688e94b550c3ccd4c0789e0b3e00cf1d0ea on apache:master**.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782232501


   > @garydgregory Yes, I see that. I don't think these failures have anything to do with my changes. Looks like some type of misconfiguration with the build. I see errors like this:
   > 
   > ```
   > java.lang.IllegalAccessError: class org.apache.commons.io.input.BufferedFileChannelInputStream (in unnamed module @0x685f4c2e) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x685f4c2e
   > ```
   > 
   > I did not touch that class. I only added one new method to `DeferredFileOutputStream` so it should not affect any other tests.
   > 
   > When I build locally everything works fine.
   
   Just run the default maven goal and you will see Javadoc errors. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580300360



##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,31 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @throws IOException if this stream is not yet closed or an error occurs.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream#toInputStream()

Review comment:
       Added `@since`.
   
   I tried running the default maven build, but it doesn't work for me. It always dies in the middle with a "killed" message on the terminal. I did run all the individual goal that are part of the default build and they all complete successfully.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] coveralls commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782224839


   
   [![Coverage Status](https://coveralls.io/builds/37280798/badge)](https://coveralls.io/builds/37280798)
   
   Coverage decreased (-0.1%) to 89.254% when pulling **6f50f16c23702947c9d928370ab4f2e585ecfd38 on jmark109:IO-651_DeferredFileOutputStream_getInputStream** into **c54bf688e94b550c3ccd4c0789e0b3e00cf1d0ea on apache:master**.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580302932



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");

Review comment:
       Removed.
   
   Was following pattern of existing test.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580307445



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580302602



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580301812



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testAboveThresholdGetInputStream(final int initialBufferSize, @TempDir Path tempDir) throws IOException {
+        final File testFile = tempDir.resolve("testAboveThreshold.dat").toFile();
+
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length - 5, initialBufferSize,
+            testFile);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertFalse(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);

Review comment:
       Removed.
   Note, I was just following the pattern of the existing test.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580301256



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {
+            final byte[] resultBytes = IOUtils.toByteArray(is);
+            assertArrayEquals(testBytes, resultBytes);
+        }
+    }
+
+    /**
+     * Tests the case where the amount of data exceeds the threshold, and is therefore written to disk. The actual data
+     * written to disk is verified, as is the file itself.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testAboveThresholdGetInputStream(final int initialBufferSize, @TempDir Path tempDir) throws IOException {
+        final File testFile = tempDir.resolve("testAboveThreshold.dat").toFile();
+
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length - 5, initialBufferSize,
+            testFile);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertFalse(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r579716893



##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,31 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @throws IOException if this stream is not yet closed or an error occurs.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream#toInputStream()

Review comment:
       Ping. FYI, you should run the _default_ Maven build: 'mvn'.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r580300990



##########
File path: src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
##########
@@ -365,4 +370,55 @@ private void verifyResultFile(final File testFile) {
             fail("Unexpected IOException");
         }
     }
+
+    /**
+     * Tests the case where the amount of data falls below the threshold, and is therefore confined to memory.
+     * Testing the getInputStream() method.
+     */
+    @ParameterizedTest(name = "initialBufferSize = {0}")
+    @MethodSource("data")
+    public void testBelowThresholdGetInputStream(final int initialBufferSize) throws IOException {
+        final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize,
+            null);
+        try {
+            dfos.write(testBytes, 0, testBytes.length);
+            dfos.close();
+        } catch (final IOException e) {
+            fail("Unexpected IOException");
+        }
+        assertTrue(dfos.isInMemory());
+
+        try(InputStream is = dfos.toInputStream()) {

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782320401


   @garydgregory I think this is good to go now. Let me know if there are any other issue.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] jmark109 commented on a change in pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
jmark109 commented on a change in pull request #206:
URL: https://github.com/apache/commons-io/pull/206#discussion_r579407661



##########
File path: src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
##########
@@ -272,4 +274,27 @@ public void writeTo(final OutputStream outputStream) throws IOException {
             }
         }
     }
+
+    /**
+     * Gets the current contents of this byte stream as an {@link InputStream}.
+     * If the data for this output stream has been retained in memory, the
+     * returned stream is backed by buffers of {@code this} stream,
+     * avoiding memory allocation and copy, thus saving space and time.<br>
+     * Otherwise, the returned stream will be one that is created from the data
+     * that has been committed to disk.
+     *
+     * @return the current contents of this output stream.
+     * @see org.apache.commons.io.output.ByteArrayOutputStream.toInputStream()

Review comment:
       Ok, I see it now. I needed to run the `javadoc:javadoc` goal. I haven't used maven default goals before, so I was just running `package` and `test` manually. 
   It should be fixed now. Sorry for the confusion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #206: IO-651 Add DeferredFileOutputStream.getInputStream()

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #206:
URL: https://github.com/apache/commons-io/pull/206#issuecomment-782225559


   @jmark109 
   This PR causes build failures.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org