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()); } }