@Override public Reader getReader(String resourceName) { Path.Relative partialPath = (Path.Relative)Path.parse(resourceName); Timestamped<Resource> partial = context.resolveResource(partialPath); if (partial != null) { return new StringReader(partial.getObject().getCharSequence().toString()); } else { return null; } }
@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 InputStream getInputStream() throws IOException { return resource.getObject().getInputStream(); }
output.updateResource(foo, new Resource("foo_value")); assertEquals("new_foo_value", output.getResource(foo).getObject().getCharSequence(Charset.defaultCharset())); File juu = children.get("juu.txt"); assertEquals("juu_value", output.getResource(juu).getObject().getCharSequence(Charset.defaultCharset()).toString());
M templateAST; try { templateAST = provider.parse(new ParseContext(), resource.getObject().getCharSequence()); path, resource.getTime(), Tools.md5(resource.getObject().getBytes())); tmm.templateModel = templateModel; try {
output.updateResource(foo, new Resource("foo_value")); assertEquals("new_foo_value", output.getResource(foo).getObject().getCharSequence(Charset.defaultCharset())); File juu = children.get("juu.txt"); assertEquals("juu_value", output.getResource(juu).getObject().getCharSequence(Charset.defaultCharset()).toString());
M templateAST; try { templateAST = provider.parse(new ParseContext(), resource.getObject().getCharSequence()); path, resource.getTime(), Tools.md5(resource.getObject().getBytes())); tmm.templateModel = templateModel; try {
@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); } }
@Test public void testFoo() throws IOException { RAMFileSystem ramFS = new RAMFileSystem(); ramFS.updateResource(new String[]{"a", "b"}, new Resource("foo")); // CompositeFileSystem composite = new CompositeFileSystem(ramFS); Context root = composite.getRoot(); Context a = composite.getChild(root, "a"); assertNotNull(a); assertEquals(PathType.DIR, composite.typeOf(a)); // Context b = composite.getChild(a, "b"); assertNotNull(b); assertEquals(PathType.FILE, composite.typeOf(b)); assertEquals(Tools.list("a", "b"), composite.getNames(b)); // Timestamped<Resource> content = composite.getResource(b); assertNotNull(content); assertEquals("foo", content.getObject().getCharSequence().toString()); } }
@Override public Reader getReader(String resourceName) { Path.Relative partialPath = (Path.Relative)Path.parse(resourceName); Timestamped<Resource> partial = context.resolveResource(partialPath); if (partial != null) { return new StringReader(partial.getObject().getCharSequence().toString()); } else { return null; } }
@Override public InputStream getInputStream() throws IOException { return resource.getObject().getInputStream(); }
@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())); }
@Test public void testFoo() throws IOException { RAMFileSystem ramFS = new RAMFileSystem(); ramFS.updateResource(new String[]{"a", "b"}, new Resource("foo")); // CompositeFileSystem composite = new CompositeFileSystem(ramFS); Context root = composite.getRoot(); Context a = composite.getChild(root, "a"); assertNotNull(a); assertEquals(PathType.DIR, composite.typeOf(a)); // Context b = composite.getChild(a, "b"); assertNotNull(b); assertEquals(PathType.FILE, composite.typeOf(b)); assertEquals(Tools.list("a", "b"), composite.getNames(b)); // Timestamped<Resource> content = composite.getResource(b); assertNotNull(content); assertEquals("foo", content.getObject().getCharSequence().toString()); } }
public final CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return assertContent().getObject().getCharSequence(); }
@Override public long updateResource(File file, Resource resource) throws IOException { File parent = file.getParentFile(); if (parent != null) { if (!parent.exists()) { if (!parent.mkdirs()) { throw new IOException("Could not create parent directory " + parent.getCanonicalPath()); } } } InputStream in = resource.getInputStream(); FileOutputStream out = new FileOutputStream(file); try { Tools.copy(in, out); } finally { Tools.safeClose(out); } return file.lastModified(); }
@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())); }
public final CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return assertContent().getObject().getCharSequence(); }
@Override public long updateResource(File file, Resource resource) throws IOException { File parent = file.getParentFile(); if (parent != null) { if (!parent.exists()) { if (!parent.mkdirs()) { throw new IOException("Could not create parent directory " + parent.getCanonicalPath()); } } } InputStream in = resource.getInputStream(); FileOutputStream out = new FileOutputStream(file); try { Tools.copy(in, out); } finally { Tools.safeClose(out); } return file.lastModified(); }
@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())); }
public String assertContent() { try { Resource content = sourcePath.getResource(path).getObject(); return content.getCharSequence().toString(); } catch (Exception e) { throw AbstractTestCase.failure(e); } }