@Test
  public void testReadWriteBytes() throws Exception {
    long start = System.currentTimeMillis();

    File file1 = system.createFile("testFile1");

    assertEquals(0, file1.getLength());

    OutputStream outputStream1 = file1.getOutputStream();

    // Write some random data. Make sure it fills several chunks
    outputStream1.write(2);
    byte[] data = new byte[LARGE_CHUNK];
    rand.nextBytes(data);
    outputStream1.write(data);
    outputStream1.write(44);
    outputStream1.close();

    assertEquals(2 + LARGE_CHUNK, file1.getLength());
    assertTrue(file1.getModified() >= start);

    // Append to the file with a new outputstream
    OutputStream outputStream2 = file1.getOutputStream();
    outputStream2.write(123);
    byte[] data2 = new byte[SMALL_CHUNK];
    rand.nextBytes(data2);
    outputStream2.write(data2);
    outputStream2.close();

    assertEquals(3 + LARGE_CHUNK + SMALL_CHUNK, file1.getLength());

    // Make sure we can read all of the data back and it matches
    InputStream is = file1.getInputStream();

    assertEquals(2, is.read());
    byte[] resultData = new byte[LARGE_CHUNK];
    assertEquals(LARGE_CHUNK, is.read(resultData));
    assertArrayEquals(data, resultData);
    assertEquals(44, is.read());
    assertEquals(123, is.read());


    // Test read to an offset
    Arrays.fill(resultData, (byte) 0);
    assertEquals(SMALL_CHUNK, is.read(resultData, 50, SMALL_CHUNK));

    // Make sure the data read matches
    byte[] expectedData = new byte[LARGE_CHUNK];
    Arrays.fill(expectedData, (byte) 0);
    System.arraycopy(data2, 0, expectedData, 50, data2.length);
    assertArrayEquals(expectedData, resultData);

    assertEquals(-1, is.read());
    assertEquals(-1, is.read(data));
    is.close();

    // Test the skip interface
    is = file1.getInputStream();
    is.skip(LARGE_CHUNK + 3);


    Arrays.fill(resultData, (byte) 0);
    assertEquals(SMALL_CHUNK, is.read(resultData));

    Arrays.fill(expectedData, (byte) 0);
    System.arraycopy(data2, 0, expectedData, 0, data2.length);
    assertArrayEquals(expectedData, resultData);

    assertEquals(-1, is.read());
  }
A test of reading and writing to a file.
geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystemJUnitTest.java