You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/05/16 15:30:37 UTC
svn commit: r1831735 - in /commons/proper/vfs/trunk:
commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java
src/changes/changes.xml
Author: ggregory
Date: Wed May 16 15:30:37 2018
New Revision: 1831735
URL: http://svn.apache.org/viewvc?rev=1831735&view=rev
Log:
[VFS-614] MonitorInputStream should not close the stream in read(). Patch by Otto Fowler. I added an EOL to the new file. Closes #30.
Added:
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java
Modified:
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java?rev=1831735&r1=1831734&r2=1831735&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java Wed May 16 15:30:37 2018
@@ -93,9 +93,6 @@ public class MonitorInputStream extends
atomicCount.addAndGet(nread);
return nread;
}
-
- // End-of-stream
- close();
return EOF_CHAR;
}
Added: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java?rev=1831735&view=auto
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java (added)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java Wed May 16 15:30:37 2018
@@ -0,0 +1,71 @@
+package org.apache.commons.vfs2.provider;
+
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.VFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * {@code DefaultFileContentTest} tests for bug-VFS-614. This bug involves the stream implementation closing the stream
+ * after reading to the end of the buffer, which broke marking.
+ */
+public class DefaultFileContentTest {
+ private static final String expected = "testing";
+
+ @Test
+ public void testMarkingWorks() throws Exception {
+ File temp = File.createTempFile("temp-file-name", ".tmp");
+ FileSystemManager fileSystemManager = VFS.getManager();
+
+ try (FileObject file = fileSystemManager.resolveFile(temp.getAbsolutePath())) {
+ try (OutputStream outputStream = file.getContent().getOutputStream()) {
+ outputStream.write(expected.getBytes());
+ outputStream.flush();
+ }
+ try (InputStream stream = file.getContent().getInputStream()) {
+ if (stream.markSupported()) {
+ for (int i = 0; i < 10; i++) {
+ stream.mark(0);
+ byte[] data = new byte[100];
+ stream.read(data, 0, 7);
+ Assert.assertEquals(expected, new String(data).trim());
+ stream.reset();
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testMarkingWhenReadingEOS() throws Exception {
+ File temp = File.createTempFile("temp-file-name", ".tmp");
+ FileSystemManager fileSystemManager = VFS.getManager();
+
+ try (FileObject file = fileSystemManager.resolveFile(temp.getAbsolutePath())) {
+ try (OutputStream outputStream = file.getContent().getOutputStream()) {
+ outputStream.write(expected.getBytes());
+ outputStream.flush();
+ }
+ try (InputStream stream = file.getContent().getInputStream()) {
+ int readCount = 0;
+ if (stream.markSupported()) {
+ for (int i = 0; i < 10; i++) {
+ stream.mark(0);
+ byte[] data = new byte[100];
+ readCount = stream.read(data, 0, 7);
+ Assert.assertEquals(readCount, 7);
+ Assert.assertEquals(expected, new String(data).trim());
+ readCount = stream.read(data, 8, 10);
+ Assert.assertEquals(readCount, -1);
+ stream.reset();
+ }
+ }
+ }
+ }
+ }
+}
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1831735&r1=1831734&r2=1831735&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Wed May 16 15:30:37 2018
@@ -71,6 +71,9 @@ The <action> type attribute can be add,u
<action issue="VFS-657" dev="ggregory" type="fix" due-to="Elias Putz">
FileSelector implementations like FileDepthSelector should throw Exception.
</action>
+ <action issue="VFS-614" dev="ggregory" type="fix" due-to="Boris Petrov, Otto Fowler">
+ MonitorInputStream should not close the stream in read().
+ </action>
</release>
<release version="2.2" date="2017-10-06" description="New features and bug fix release.">
<action issue="VFS-642" dev="pschumacher" type="update" due-to="ilangoldfeld">