/** Factory method that creates an empty implementation of a filesystem that * completely resides in a memory. * <p>To specify the MIME type of a data file without using a MIME resolver, * set the {@code mimeType} file attribute. * <p>Since 7.42, a {@link URLMapper} is available for files (and folders) * in memory filesystems. These URLs are valid only so long as the filesystem * has not been garbage-collected, so hold the filesystem (or a file in it) * strongly for as long as you expect the URLs to be in play. * @return a blank writable filesystem * @since 4.43 */ public static FileSystem createMemoryFileSystem() { return new MemoryFileSystem(); }
@SuppressWarnings("deprecation") // need to set it for compat private void _setSystemName(String s) throws PropertyVetoException { setSystemName(s); }
/** Creates new MemoryFS */ public MemoryFileSystem() { attr = this; list = this; change = this; info = this; try { _setSystemName("MemoryFileSystem" + String.valueOf(id)); } catch (PropertyVetoException ex) { ex.printStackTrace(); } }
public Object readAttribute(String name, String attrName) { return isValidEntry(name) ? getOrCreateEntry(name).attrs.get(attrName) : null; }
/** finds whether there already is this name */ private boolean isValidEntry(String n, Boolean expectedResult) { boolean retval = (n.length() == 0) ? true : false; if ((n.length() > 0) && (n.charAt(0) == '/')) { n = n.substring(1); } Entry x = entries.get(n); FileObject fo = null; if (x != null) { Reference ref = findReference(n); if (ref != null) { fo = (FileObject)ref.get(); retval = (fo != null) ? fo.isValid() : true; } } if (ERR.isLoggable(Level.FINE) && expectedResult != null && retval != expectedResult.booleanValue()) { logMessage("entry: " + x + " isValidReference.fo: " + ((fo == null) ? "null" : //NOI18N (fo.isValid() ? "valid" : "invalid")));//NOI18N } return (retval); }
public java.util.Date lastModified(String name) { java.util.Date d = e (name).last; return d == null ? created : d; }
public java.util.Date lastModified(String name) { java.util.Date d = getOrCreateEntry(name).last; return (d == null) ? created : d; }
private boolean isValidEntry(String n) { return isValidEntry(n, null); }
public long size(String name) { byte[] d = e (name).data; return d == null ? 0 : d.length; }
public void createData(String name) throws IOException { if (isValidEntry(name, Boolean.FALSE)) { StringBuffer message = new StringBuffer(); message.append("File already exists: ").append(name); throw new IOException(message.toString());//NOI18N } getOrCreateEntry(name).data = new byte[0]; }
public long size(String name) { byte[] d = getOrCreateEntry(name).data; return (d == null) ? 0 : d.length; }
/** finds entry for given name */ private Entry getOrCreateEntry(String n) { if ((n.length() > 0) && (n.charAt(0) == '/')) { n = n.substring(1); } boolean isValidEntry = isValidEntry(n); synchronized(entries) { Entry x = entries.get(n); if (x == null || !isValidEntry) { x = new Entry(n); entries.put(n, x); } return x; } }
public java.util.Date lastModified(String name) { java.util.Date d = e (name).last; return d == null ? created : d; }
/** Creates new MemoryFS */ public MemoryFileSystem() { attr = this; list = this; change = this; info = this; try { setSystemName("MemoryFileSystem"); } catch (PropertyVetoException ex) { ex.printStackTrace(); } }
/** Factory method that creates an empty implementation of a filesystem that * completely resides in a memory. * @return a blank writeable filesystem * @since 4.43 */ public static FileSystem createMemoryFileSystem () { return new MemoryFileSystem (); }
public void createFolder(String name) throws java.io.IOException { if (isValidEntry(name, Boolean.FALSE)) { StringBuffer message = new StringBuffer(); message.append("Folder already exists: ").append(name); throw new IOException(message.toString());//NOI18N } getOrCreateEntry(name).data = null; }
public boolean folder(String name) { return getOrCreateEntry(name).data == null; }