@Override public Timestamped<Resource> getResource(File file) throws IOException { FileInputStream in = new FileInputStream(file); try { ByteArrayOutputStream resource = new ByteArrayOutputStream(); byte[] buffer = new byte[256]; for (int l = in.read(buffer);l != -1;l = in.read(buffer)) { resource.write(buffer, 0, l); } return new Timestamped<Resource>(file.lastModified(), new Resource(resource.toByteArray(), encoding)); } finally { Tools.safeClose(in); } }
@Override public Timestamped<Resource> getResource(File file) throws IOException { FileInputStream in = new FileInputStream(file); try { ByteArrayOutputStream resource = new ByteArrayOutputStream(); byte[] buffer = new byte[256]; for (int l = in.read(buffer);l != -1;l = in.read(buffer)) { resource.write(buffer, 0, l); } return new Timestamped<Resource>(file.lastModified(), new Resource(resource.toByteArray(), encoding)); } finally { Tools.safeClose(in); } }
@Override public Timestamped<Resource> getResource(String file) throws IOException { URL url = getURL(file); URLConnection conn = url.openConnection(); long lastModified = conn.getLastModified(); byte[] bytes = Tools.bytes(conn.getInputStream()); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); }
@Override public Timestamped<Resource> getResource(Node file) throws IOException { if (file.url == null) { throw new IOException("Cannot find file " + file.getPath()); } // URLConnection conn = file.url.openConnection(); long lastModified = conn.getLastModified(); byte[] bytes = Tools.bytes(conn.getInputStream()); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); }
@Override public Timestamped<Resource> getResource(String file) throws IOException { URL url = getURL(file); URLConnection conn = url.openConnection(); long lastModified = conn.getLastModified(); byte[] bytes = Tools.bytes(conn.getInputStream()); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); }
@Override public Timestamped<Resource> getResource(Node file) throws IOException { if (file.url == null) { throw new IOException("Cannot find file " + file.getPath()); } // URLConnection conn = file.url.openConnection(); long lastModified = conn.getLastModified(); byte[] bytes = Tools.bytes(conn.getInputStream()); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); }
@Override public void close() throws IOException { Resource content = new Resource(toByteArray(), null); long lastModified = fs.updateResource(file, content); JavaFileObjectImpl.this.content = new Timestamped<Resource>(lastModified, content); JavaFileObjectImpl.this.writing = false; } };
@Override public void close() throws IOException { Resource content = new Resource(getBuffer()); long lastModified = fs.updateResource(file, content); JavaFileObjectImpl.this.content = new Timestamped<Resource>(lastModified, content); JavaFileObjectImpl.this.writing = false; } };
@Override public void close() throws IOException { Resource content = new Resource(toByteArray(), null); long lastModified = fs.updateResource(file, content); JavaFileObjectImpl.this.content = new Timestamped<Resource>(lastModified, content); JavaFileObjectImpl.this.writing = false; } };
@Override public void close() throws IOException { Resource content = new Resource(getBuffer()); long lastModified = fs.updateResource(file, content); JavaFileObjectImpl.this.content = new Timestamped<Resource>(lastModified, content); JavaFileObjectImpl.this.writing = false; } };
public void assertSave(String content) { try { sourcePath.updateResource(path, new Resource(content)); } catch (Exception e) { throw AbstractTestCase.failure(e); } }
public void assertSave(String content) { try { sourcePath.updateResource(path, new Resource(content)); } catch (Exception e) { throw AbstractTestCase.failure(e); } }
@Test public void testLastModified() throws IOException { RAMFileSystem fs = new RAMFileSystem(); String[] fooTxt = fs.makePath(fs.getRoot(), "foo.txt"); fs.updateResource(fooTxt, new Resource("abc")); long now = waitForOneMillis(); assertTrue(fs.getLastModified(fooTxt) < now); waitForOneMillis(); fs.updateResource(fooTxt, new Resource("def")); assertTrue(now < fs.getLastModified(fooTxt)); }
@Test public void testLastModified() throws IOException { RAMFileSystem fs = new RAMFileSystem(); String[] fooTxt = fs.makePath(fs.getRoot(), "foo.txt"); fs.updateResource(fooTxt, new Resource("abc")); long now = waitForOneMillis(); assertTrue(fs.getLastModified(fooTxt) < now); waitForOneMillis(); fs.updateResource(fooTxt, new Resource("def")); assertTrue(now < fs.getLastModified(fooTxt)); }
@Test public void testIgnoreHiddenFile() throws IOException { RAMFileSystem fs = new RAMFileSystem(); FileSystemScanner<String[]> scanner = FileSystemScanner.createTimestamped(fs); // Snapshot<String[]> snapshot = scanner.take(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); String[] foo = fs.makePath(fs.getRoot(), ".foo"); fs.updateResource(foo, new Resource("")); waitForOneMillis(); snapshot = snapshot.scan(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); }
@Test public void testIgnoreHiddenFile() throws IOException { RAMFileSystem fs = new RAMFileSystem(); FileSystemScanner<String[]> scanner = FileSystemScanner.createTimestamped(fs); // Snapshot<String[]> snapshot = scanner.take(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); String[] foo = fs.makePath(fs.getRoot(), ".foo"); fs.updateResource(foo, new Resource("")); waitForOneMillis(); snapshot = snapshot.scan(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); }
@Test public void testIgnoreHiddenDir() throws IOException { RAMFileSystem fs = new RAMFileSystem(); FileSystemScanner<String[]> scanner = FileSystemScanner.createTimestamped(fs); // Snapshot<String[]> snapshot = scanner.take(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); String[] bar = fs.makePath(fs.makePath(fs.getRoot(), ".foo"), "bar.txt"); fs.updateResource(bar, new Resource("")); waitForOneMillis(); snapshot = snapshot.scan(); assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges()); } }
@Test public void testLifeCycle() throws Exception { ReadWriteFileSystem<P> fs = create(); // The root exist P foo = fs.makePath(Collections.singleton("foo")); P bar = fs.makePath(foo, "bar"); assertEquals(1, fs.size(ReadFileSystem.PATH)); // Now create fs.updateResource(bar, new Resource("FOO")); // assertEquals(3, fs.size(ReadFileSystem.PATH)); assertEquals(2, fs.size(ReadFileSystem.DIR)); assertEquals(1, fs.size(ReadFileSystem.FILE)); } }
@Test public void testLifeCycle() throws Exception { ReadWriteFileSystem<P> fs = create(); // The root exist P foo = fs.makePath(Collections.singleton("foo")); P bar = fs.makePath(foo, "bar"); assertEquals(1, fs.size(ReadFileSystem.PATH)); // Now create fs.updateResource(bar, new Resource("FOO")); // assertEquals(3, fs.size(ReadFileSystem.PATH)); assertEquals(2, fs.size(ReadFileSystem.DIR)); assertEquals(1, fs.size(ReadFileSystem.FILE)); } }
@Test public void testIncremental() throws IOException, CompilationException { CompilerAssert<File, File> compiler = compiler(true, Name.parse("compiler.incremental"), ""). with(compilerProvider). with((Provider<? extends Processor>)null); compiler.assertCompile(); // ReadWriteFileSystem<File> classOutput = compiler.getClassOutput(); assertEquals(1, classOutput.size(ReadFileSystem.FILE)); // ReadWriteFileSystem<File> sourcePath = (ReadWriteFileSystem<File>)compiler.getSourcePath(); File b = sourcePath.makePath(sourcePath.getPath("compiler", "incremental"), "B.java"); sourcePath.updateResource(b, new Resource("package compiler.incremental; public class B extends A {}")); compiler.assertCompile(); assertEquals(2, classOutput.size(ReadFileSystem.FILE)); }