/**
* Read a file
*/
public void testRandomRead() throws Exception
{
FileObject file = null;
try
{
file = getReadFolder().resolveFile("file1.txt");
RandomAccessContent ra = file.getContent().getRandomAccessContent(RandomAccessMode.READ);
// read first byte
byte c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(0));
assertEquals("fp", ra.getFilePointer(), 1);
// start at pos 4
ra.seek(3);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(3));
assertEquals("fp", ra.getFilePointer(), 4);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(4));
assertEquals("fp", ra.getFilePointer(), 5);
// restart at pos 4
ra.seek(3);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(3));
assertEquals("fp", ra.getFilePointer(), 4);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(4));
assertEquals("fp", ra.getFilePointer(), 5);
// advance to pos 11
ra.seek(10);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(10));
assertEquals("fp", ra.getFilePointer(), 11);
c = ra.readByte();
assertEquals(c, TEST_DATA.charAt(11));
assertEquals("fp", ra.getFilePointer(), 12);
}
finally
{
if (file != null)
{
file.close();
}
}
}