jclx commented on issue #30: VFS-614 MonitorInputStream should not close the 
stream in "read"
URL: https://github.com/apache/commons-vfs/pull/30#issuecomment-503345452
 
 
   just need to remove the close() from the 'public int read()' method. I have 
not created an account to create a jira issue yet. VFS 2.3 won't work for us 
with this bug as we use marking / reset a lot.
   
   A simple test case converting the one in the pr to call 'int read()' instead.
   
   `    public void testMarkingWhenReadEOS() 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];
                                                int readCount = 0;
                                                int bt = 0;
   
                                                while ((bt = stream.read()) != 
-1)
                                                {
                                                        data[readCount] = 
(byte) bt;
                                                        readCount++;
                                                }
   
                                                Assert.assertEquals(readCount, 
7);
                                                Assert.assertEquals(expected, 
new String(data).trim());
   
                                                Assert.assertEquals(bt, -1);
                                                stream.reset();
                                        }
                                }
                        }
                }
        }
   `
   yields this exception:
   Exception in thread "main" java.io.IOException: Stream closed
        at 
java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
        at java.io.BufferedInputStream.reset(BufferedInputStream.java:446)
        at Tester.testMarkingWhenReadEOS(Tester.java:123)
        at Tester.main(Tester.java:25)
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to