lnykww commented on PR #700:
URL: https://github.com/apache/commons-vfs/pull/700#issuecomment-3068121140

   I cannot reproduce this issue with the following unit tests, but it occurs 
consistently in Hop. However, the problem disappears after the fix in the PR 
code is applied.
    `
   @Test
       public void testReadFileOperations() throws Exception {
           DefaultFileSystemManager manager = new DefaultFileSystemManager();
           manager.addProvider("http5", new 
org.apache.commons.vfs2.provider.http5.Http5FileProvider());
           manager.setFilesCache(new SoftRefFilesCache());
           manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
   
           // Step 1: Test reading a non-existent file
           final String nonExistentFileUri = connectionUri + 
"/read-tests/nonexistent.txt";
           try {
               final FileObject nonExistentFileObject = 
manager.resolveFile(nonExistentFileUri);
               try (InputStream inputStream = 
nonExistentFileObject.getContent().getInputStream()) {
                   inputStream.read(); // Attempt to read from the stream
                   Assertions.fail("Expected FileSystemException for 
non-existent file (HTTP 404)");
               }
           } catch (final FileSystemException e) {
               
Assertions.assertTrue(e.getCode().contains("read-not-file.error"),
                       "Expected HTTP 404 Not Found error, but got: " + 
e.getMessage() + " " + e.getCode());
           }
   
           // Step 2: Test reading an existing file
           final String existentFileUri = connectionUri + 
"/read-tests/file1.txt";
           final FileObject existentFileObject = 
manager.resolveFile(existentFileUri);
           Assertions.assertTrue(existentFileObject.exists(), "File should 
exist");
           try (InputStream inputStream = 
existentFileObject.getContent().getInputStream()) {
               Assertions.assertNotNull(inputStream, "InputStream should not be 
null");
               int available = inputStream.available();
               Assertions.assertTrue(available > 0, "InputStream should have 
content available");
               byte[] buffer = new byte[1024];
               int bytesRead = inputStream.read(buffer);
               Assertions.assertTrue(bytesRead > 0, "InputStream should read 
non-empty content");
           }
       }
      `


-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

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

Reply via email to