public void testInfoEntry() throws IOException { File file = File.createTempFile("test", ".txt"); FileWriter writer = new FileWriter(file); try { writer.write("read content"); } finally { writer.close(); } String uri = file.toURI().toASCIIString(); store.readEntry(uri, uri, "*/*", null, new DataReader() { public void load(URI id, String media, InputStream content, long len) throws IOException { assertEquals("text/plain", media); } }); store.deleteEntry(file.getPath(), tmp); }
public void testReadEntry() throws IOException { File file = File.createTempFile("test", ".txt"); FileWriter writer = new FileWriter(file); try { writer.write("read content"); } finally { writer.close(); } String uri = file.toURI().toASCIIString(); store.readEntry(uri, uri, "*/*", null, new DataReader() { public void load(URI id, String media, InputStream content, long len) throws IOException { byte[] buf = new byte[1024]; assertEquals("read content", new String(buf, 0, content.read(buf))); } }); store.deleteEntry(file.getPath(), tmp); }
public void testDeleteEntry() throws IOException { URI file = store.writeEntry("dir/", tmp, "text/plain", new DataWriter() { public void store(OutputStream content) throws IOException { content.write("content".getBytes()); } }); assertTrue(new File(file).exists()); store.deleteEntry(file.getPath(), tmp); assertFalse(new File(file).exists()); }
public void testListEachEntry() throws IOException { URI dir = store.createList("dir", tmp); final File text = File.createTempFile("test", ".txt", new File(dir)); final File xml = File.createTempFile("test", ".xml", new File(dir)); store.listEachEntry("dir", tmp, "text/plain", new DataInfo() { public void list(URI id, String media, long lastModified) throws IOException { assertEquals("text/plain", media); assertEquals(text.getAbsolutePath(), new File(id).getAbsolutePath()); } }); store.listEachEntry("dir", tmp, "application/xml", new DataInfo() { public void list(URI id, String media, long lastModified) throws IOException { assertEquals("application/xml", media); assertEquals(xml.getAbsolutePath(), new File(id).getAbsolutePath()); } }); store.deleteEntry(text.getPath(), tmp); store.deleteEntry(xml.getPath(), tmp); store.deleteEntry(dir.getPath(), tmp); }
public void testWriteDirectory() throws IOException { URI file = store.writeEntry("dir/", tmp, "text/plain", new DataWriter() { public void store(OutputStream content) throws IOException { content.write("content".getBytes()); } }); store.infoEntry(file.getPath(), tmp, "text/plain", new DataInfo() { public void list(URI id, String media, long lastModified) throws IOException { assertEquals("text/plain", media); } }); store.readEntry(file.getPath(), tmp, "text/plain", null, new DataReader() { public void load(URI id, String media, InputStream content, long len) throws IOException { byte[] buf = new byte[1024]; assertEquals("content", new String(buf, 0, content.read(buf))); } }); store.deleteEntry(file.getPath(), tmp); store.deleteEntry("dir", tmp); }
public void testWriteFile() throws IOException { store.writeEntry("file.txt", tmp, "text/plain", new DataWriter() { public void store(OutputStream content) throws IOException { content.write("content".getBytes()); } }); store.readEntry("file.txt", tmp, "text/plain", null, new DataReader() { public void load(URI id, String media, InputStream content, long len) throws IOException { byte[] buf = new byte[1024]; assertEquals("content", new String(buf, 0, content.read(buf))); } }); store.deleteEntry("file.txt", tmp); }