private void doUnclosedStream(int size) throws IOException {
    String name1 = "testFile1";
    File file1 = system.createFile(name1);
    byte[] bytes = getRandomBytes(size);
    file1.getOutputStream().write(bytes);

    FileSystem system2 = new FileSystem(fileAndChunkRegion, fileSystemStats);
    File file = system2.getFile(name1);

    assertTrue(file.getLength() <= bytes.length);

    long length = file.getLength();


    byte[] results = new byte[bytes.length];

    if (length == 0) {
      assertEquals(-1, file.getInputStream().read(results));
      assertEquals(0, numberOfChunks(fileAndChunkRegion));
    } else {
      // Make sure the amount of data we can read matches the length
      assertEquals(length, file.getInputStream().read(results));

      if (length != bytes.length) {
        Arrays.fill(bytes, (int) length, bytes.length, (byte) 0);
      }

      assertArrayEquals(bytes, results);
    }
  }
Test what happens if you have an unclosed stream and you create a new file.
geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystemJUnitTest.java