@Override protected FileObject createFile(final AbstractFileName name) throws Exception { return new RamFileObject(name, this); }
/** * Delete a file * * @param file * @throws FileSystemException */ void delete(final RamFileObject file) throws FileSystemException { // root is read only check FileSystemException.requireNonNull(file.getParent(), "unable to delete root"); // Remove reference from cache this.cache.remove(file.getName()); // Notify the parent final RamFileObject parent = (RamFileObject) this.resolveFile(file.getParent().getName()); parent.getData().removeChild(file.getData()); parent.close(); // Close the file file.getData().clear(); file.close(); }
@Override protected void doDelete() throws Exception { if (this.isContentOpen()) { throw new FileSystemException(this.getName() + " cannot be deleted while the file is openg"); } getAbstractFileSystem().delete(this); }
@Override protected String[] doListChildren() throws Exception { return this.getAbstractFileSystem().listChildren(this.getName()); }
@Override protected InputStream doGetInputStream() throws Exception { // VFS-210: ram allows to gather an input stream even from a directory. So we need to check the type anyway. if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } return new ByteArrayInputStream(this.data.getContent()); }
/** * @param name The name of the file. * @param fs The FileSystem. */ protected RamFileObject(final AbstractFileName name, final RamFileSystem fs) { super(name, fs); this.getAbstractFileSystem().attach(this); }
/** * @param newSize * @throws IOException if the new size exceeds the limit */ synchronized void resize(final long newSize) throws IOException { final RamFileSystem afs = getAbstractFileSystem(); final FileSystemOptions afsOptions = afs.getFileSystemOptions(); if (afsOptions != null) { final long maxSize = RamFileSystemConfigBuilder.getInstance().getLongMaxSize(afsOptions); if (afs.size() + newSize - this.size() > maxSize) { throw new IOException("FileSystem capacity (" + maxSize + ") exceeded."); } } this.data.resize(newSize); }
/** * @param from The original file. * @param to The new file. * @throws FileSystemException if an error occurs. */ void rename(final RamFileObject from, final RamFileObject to) throws FileSystemException { if (!this.cache.containsKey(from.getName())) { throw new FileSystemException("File does not exist: " + from.getName()); } // Copy data to.getData().setContent(from.getData().getContent()); to.getData().setLastModified(from.getData().getLastModified()); to.getData().setType(from.getData().getType()); this.save(to); this.delete(from); }
if (fo.getType().hasChildren()) { memFo.createFolder(); final InputStream is = fo.getContent().getInputStream(); try { final OutputStream os = new BufferedOutputStream(memFo.getOutputStream(), BUFFER_SIZE); int i; while ((i = is.read()) != -1) {
@Override public void close() throws IOException { if (closed) { return; } // Notify on close that there was an IOException while writing if (exception != null) { throw exception; } try { this.closed = true; // Close the this.file.endOutput(); } catch (final Exception e) { throw new FileSystemException(e); } }
this.buf = file.getData().getContent(); this.file = file;
@Override protected InputStream doGetInputStream() throws Exception { // VFS-210: ram allows to gather an input stream even from a directory. So we need to check the type anyway. if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } return new ByteArrayInputStream(this.data.getContent()); }
@Override protected void doAttach() throws Exception { this.getAbstractFileSystem().attach(this); }
@Override protected String[] doListChildren() throws Exception { return this.getAbstractFileSystem().listChildren(this.getName()); }
/** * @param newSize * @throws IOException if the new size exceeds the limit */ synchronized void resize(final long newSize) throws IOException { final RamFileSystem afs = getAbstractFileSystem(); final FileSystemOptions afsOptions = afs.getFileSystemOptions(); if (afsOptions != null) { final long maxSize = RamFileSystemConfigBuilder.getInstance().getLongMaxSize(afsOptions); if (afs.size() + newSize - this.size() > maxSize) { throw new IOException("FileSystem capacity (" + maxSize + ") exceeded."); } } this.data.resize(newSize); }
/** * @param from The original file. * @param to The new file. * @throws FileSystemException if an error occurs. */ void rename(final RamFileObject from, final RamFileObject to) throws FileSystemException { if (!this.cache.containsKey(from.getName())) { throw new FileSystemException("File does not exist: " + from.getName()); } // Copy data to.getData().setContent(from.getData().getContent()); to.getData().setLastModified(from.getData().getLastModified()); to.getData().setType(from.getData().getType()); this.save(to); this.delete(from); }