1 16 package org.apache.commons.vfs.test; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.RandomAccessContent; 21 import org.apache.commons.vfs.util.RandomAccessMode; 22 23 28 public class ProviderRandomReadTests 29 extends AbstractProviderTestCase 30 { 31 private final String TEST_DATA = "This is a test file."; 32 33 36 protected Capability[] getRequiredCaps() 37 { 38 return new Capability[] 39 { 40 Capability.GET_TYPE, 41 Capability.RANDOM_ACCESS_READ 42 }; 43 } 44 45 48 public void testRandomRead() throws Exception 49 { 50 FileObject file = null; 51 try 52 { 53 file = getReadFolder().resolveFile("file1.txt"); 54 RandomAccessContent ra = file.getContent().getRandomAccessContent(RandomAccessMode.READ); 55 56 byte c = ra.readByte(); 58 assertEquals(c, TEST_DATA.charAt(0)); 59 assertEquals("fp", ra.getFilePointer(), 1); 60 61 ra.seek(3); 63 c = ra.readByte(); 64 assertEquals(c, TEST_DATA.charAt(3)); 65 assertEquals("fp", ra.getFilePointer(), 4); 66 67 c = ra.readByte(); 68 assertEquals(c, TEST_DATA.charAt(4)); 69 assertEquals("fp", ra.getFilePointer(), 5); 70 71 ra.seek(3); 73 c = ra.readByte(); 74 assertEquals(c, TEST_DATA.charAt(3)); 75 assertEquals("fp", ra.getFilePointer(), 4); 76 77 c = ra.readByte(); 78 assertEquals(c, TEST_DATA.charAt(4)); 79 assertEquals("fp", ra.getFilePointer(), 5); 80 81 ra.seek(10); 83 c = ra.readByte(); 84 assertEquals(c, TEST_DATA.charAt(10)); 85 assertEquals("fp", ra.getFilePointer(), 11); 86 87 c = ra.readByte(); 88 assertEquals(c, TEST_DATA.charAt(11)); 89 assertEquals("fp", ra.getFilePointer(), 12); 90 } 91 finally 92 { 93 if (file != null) 94 { 95 file.close(); 96 } 97 } 98 } 99 } 100 | Popular Tags |