RAMFile(RAMDir parent, String name, Resource resource) { super(parent, name); // this.resource = new Timestamped<Resource>(System.currentTimeMillis(), resource); }
public Timestamped<T> touch() { return new Timestamped<T>(System.currentTimeMillis(), object); }
RAMFile(RAMDir parent, String name, Resource resource) { super(parent, name); // this.resource = new Timestamped<Resource>(System.currentTimeMillis(), resource); }
public Timestamped<T> touch() { return new Timestamped<T>(System.currentTimeMillis(), object); }
@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(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(String file) throws IOException { URL url = getResourceURL(file); if (url != null) { URLConnection conn = url.openConnection(); long lastModified = conn.getLastModified(); InputStream in = conn.getInputStream(); 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>(lastModified, new Resource(resource.toByteArray(), Charset.defaultCharset())); } finally { Tools.safeClose(in); } } else { throw new UnsupportedOperationException("handle me gracefully"); } }
@Override public Timestamped<Resource> getResource(String file) throws IOException { URL url = getResourceURL(file); if (url != null) { URLConnection conn = url.openConnection(); long lastModified = conn.getLastModified(); InputStream in = conn.getInputStream(); 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>(lastModified, new Resource(resource.toByteArray(), Charset.defaultCharset())); } finally { Tools.safeClose(in); } } else { throw new UnsupportedOperationException("handle me gracefully"); } }
next.parent = current; } else if (next instanceof RAMFile) { ((RAMFile)next).resource = new Timestamped<Resource>(lastModified, resource); } else { throw new IOException("A file already exist");
next.parent = current; } else if (next instanceof RAMFile) { ((RAMFile)next).resource = new Timestamped<Resource>(lastModified, resource); } else { throw new IOException("A file already exist");
@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; } };
@Override public Timestamped<Resource> resolveResource(Path.Absolute path) { FileObject resource = owner.application.resolveResource(path); if (resource != null) { try { byte[] bytes = Tools.bytes(resource.openInputStream()); long lastModified = resource.getLastModified(); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); } catch (Exception e) { env.info("Could not get resource content " + path.getCanonical(), e); } } return null; }
@Override public Timestamped<Resource> resolveResource(Path.Absolute path) { FileObject resource = owner.application.resolveResource(path); if (resource != null) { try { byte[] bytes = Tools.bytes(resource.openInputStream()); long lastModified = resource.getLastModified(); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); } catch (Exception e) { env.info("Could not get resource content " + path.getCanonical(), e); } } return null; }