public void testRename() {
   try {
     FileAccessor fe = null;
     fe = FileSystem.open("file:///test0.txt");
     fe.create();
     assertEquals("before write : size = 0", 0L, fe.fileSize());
     OutputStream os = fe.openOutputStream();
     byte[] data = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04};
     os.write(data);
     try {
       fe.rename("rename0.jpg");
       fail("unable to rename while writing");
     } catch (IOException e) {
     }
     os.close();
     fe.rename("rename0.jpg");
     assertEquals("after rename : name = rename0.jpg", "rename0.jpg", fe.getName());
     fe.close();
     fe = FileSystem.open("file:///test0.txt");
     assertTrue("test0.txt not exists", !fe.exsists());
     fe.close();
     fe = FileSystem.open("file:///rename0.jpg");
     assertTrue("ename0.jpg exists", fe.exsists());
     InputStream is = fe.openInputStream();
     byte[] buf = new byte[5];
     is.read(buf);
     assertSame("read data", data, buf);
     assertTrue("eof", is.read() == -1);
     is.close();
     fe.close();
   } catch (Exception e) {
     fail(e.toString());
   }
 }
 public void testWriteAndReadFileData() {
   try {
     FileAccessor fe = null;
     fe = FileSystem.open("file:///test0.txt");
     fe.create();
     assertEquals("before write : size = 0", 0L, fe.fileSize());
     OutputStream os = fe.openOutputStream();
     byte[] data = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04};
     for (int i = 0; i < 195; ++i) {
       os.write(data);
     }
     assertEquals("before flush : size = 0", 0L, fe.fileSize());
     os.flush();
     assertEquals("after flush : size = 5 * 195", 5L * 195, fe.fileSize());
     os.close();
     fe.close();
     fe = FileSystem.open("file:///test0.txt");
     InputStream is = fe.openInputStream();
     for (int i = 0; i < 195; ++i) {
       byte[] buf = new byte[5];
       is.read(buf);
       assertSame("series[" + i + "]", data, buf);
     }
     assertTrue("eof", is.read() == -1);
     is.close();
     fe.close();
   } catch (Exception e) {
     fail(e.toString());
   }
 }
 public void testGetFileName() {
   try {
     FileAccessor fe = null;
     fe = FileSystem.open("file:///test0.txt");
     fe.close();
     assertEquals("flat file", "test0.txt", fe.getName());
     fe = FileSystem.open("file:///test/test1.txt");
     fe.close();
     assertEquals("dir file", "test1.txt", fe.getName());
     fe = FileSystem.open("file:///test/dir");
     fe.close();
     assertEquals("dir not end with slash", "dir", fe.getName());
     fe = FileSystem.open("file:///test/");
     fe.close();
     assertEquals("dir end with slash", "test", fe.getName());
     fe = FileSystem.open("file:///");
     fe.close();
     assertEquals("root dir", "", fe.getName());
     try {
       fe = FileSystem.open("file://");
       fail("detect root slash");
       fe.close();
     } catch (IOException e) {
     }
     try {
       fe = FileSystem.open("file://partition/test0.txt");
       fail("detect ghost partition...");
       fe.close();
     } catch (IOException ioe) {
     }
   } catch (Exception e) {
     fail(e.toString());
   }
 }
 public void testOpen() {
   try {
     FileAccessor fe = FileSystem.open("file:///test.txt");
     assertNotNull("file entry not null", fe);
     assertTrue("not file exists", !fe.exsists());
     fe.close();
   } catch (Exception e) {
     fail(e.toString());
   }
 }
 public void testCreateAndDeleteFile() {
   try {
     FileAccessor fe = null;
     fe = FileSystem.open("file:///test0.txt");
     assertTrue("before create : file not exists", !fe.exsists());
     fe.create();
     assertTrue("after create : file exists", fe.exsists());
     assertEquals("size = 0", 0L, fe.fileSize());
     fe.close();
     fe = FileSystem.open("file:///test0.txt");
     assertTrue("reopen : file exists", fe.exsists());
     assertEquals("size = 0", 0L, fe.fileSize());
     fe.delete();
     assertTrue("after delete : file not exists", !fe.exsists());
     fe.close();
     fe = FileSystem.open("file:///test0.txt");
     assertTrue("rereopen : not exists", !fe.exsists());
     fe.close();
   } catch (Exception e) {
     fail(e.toString());
   }
 }
示例#6
0
  public void close() throws IOException {

    input.close();
  }