protected boolean folder(String name) { return getFile(name).isDirectory(); }
private OutputStream getOutputStreamForMac42624(final OutputStream originalStream, final String name) { final File f = getFile(name); final long lModified = f.lastModified(); OutputStream retVal = new FilterOutputStream(originalStream) { @Override public void close() throws IOException { super.close(); if ((f.length() == 0) && (f.lastModified() == lModified)) { f.setLastModified(System.currentTimeMillis()); } } }; return retVal; }
protected long size(String name) { return getFile(name).length(); }
protected String[] children(String name) { File f = getFile(name); if (f.isDirectory()) { return f.list(); } else { return null; } }
protected boolean readOnly(String name) { File f = getFile(name); return !f.canWrite() && f.exists(); }
protected java.util.Date lastModified(String name) { return new java.util.Date(getFile(name).lastModified()); }
protected InputStream inputStream(String name) throws java.io.FileNotFoundException { InputStream fis; File file = null; try { fis = new BufferedInputStream(new FileInputStream(file = getFile(name))); } catch (FileNotFoundException exc) { if ((file == null) || !file.exists()) { ExternalUtil.annotate(exc, NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", getFile(name))); } throw exc; } return fis; }
protected OutputStream outputStream(final String name) throws java.io.IOException { File f = getFile(name); if (!f.exists()) { f.getParentFile().mkdirs(); } OutputStream retVal = new BufferedOutputStream(new FileOutputStream(f)); // workaround for #42624 if (Utilities.isMac()) { retVal = getOutputStreamForMac42624(retVal, name); } return retVal; }
protected void lock(String name) throws IOException { File file = getFile(name); if ((!file.canWrite() && file.exists()) || isReadOnly()) { throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_CannotLock", null, null, file.getAbsolutePath())); } }
protected void createFolder(String name) throws java.io.IOException { File f = getFile(name); if (name.equals("")) { // NOI18N throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_CannotCreateF", f.getName(), getDisplayName(), f.getAbsolutePath())); } if (f.exists()) { throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_FolderAlreadyExist", f.getName(), getDisplayName(), f.getAbsolutePath())); } boolean b = createRecursiveFolder(f); if (!b) { throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_CannotCreateF", f.getName(), getDisplayName(), f.getAbsolutePath())); } }
protected void createData(String name) throws IOException { File f = getFile(name); boolean isError = true; IOException creationException = null; String annotationMsg = null; try { isError = f.createNewFile() ? false : true; isError = isError ? true : (!f.exists()); if (isError) { annotationMsg = NbBundle.getMessage(LocalFileSystem.class, "EXC_DataAlreadyExist", f.getName(), getDisplayName(), f.getAbsolutePath()); creationException = new SyncFailedException(annotationMsg); } } catch (IOException iex) { isError = true; creationException = iex; annotationMsg = iex.getLocalizedMessage(); } if (isError) { LOG.log(Level.INFO, "Trying to create new file {0}.", f.getPath()); ExternalUtil.annotate(creationException, annotationMsg); throw creationException; } }
protected void delete(String name) throws IOException { File file = getFile(name); if (deleteFile(file) != SUCCESS) { if (file.exists()) { throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_CannotDelete", name, getDisplayName(), file.getAbsolutePath())); } else { /** When file externaly deleted and fo.delete () is called before periodical refresh */ FileObject thisFo = findResource(name); if (thisFo != null) { if (thisFo.getParent() != null) { thisFo.getParent().refresh(); } thisFo.refresh(); if (thisFo.isValid()) { throw new FSException(NbBundle.getMessage(LocalFileSystem.class, "EXC_CannotDelete", name, getDisplayName(), file.getAbsolutePath())); } } } } }
protected String[] children (String name) { File f = getFile (name); if (f.isDirectory ()) { return f.list (); } else { return null; } }
protected String[] children (String name) { File f = getFile (name); if (f.isDirectory ()) { return f.list (); } else { return null; } }
protected void rename(String oldName, String newName) throws IOException { File of = getFile (oldName); File nf = getFile (newName); // #7086 - (nf.exists() && !nf.equals(of)) instead of nf.exists() - fix for Win32 if ((nf.exists() && !nf.equals(of)) || !of.renameTo (nf)) { FSException.io ("EXC_CannotRename", oldName, getDisplayName (), newName); // NOI18N } }
protected void rename(String oldName, String newName) throws IOException { File of = getFile (oldName); File nf = getFile (newName); // #7086 - (nf.exists() && !nf.equals(of)) instead of nf.exists() - fix for Win32 if ((nf.exists() && !nf.equals(of)) || !of.renameTo (nf)) { FSException.io ("EXC_CannotRename", oldName, getDisplayName (), newName); // NOI18N } }
protected InputStream inputStream (String name) throws java.io.FileNotFoundException { FileInputStream fis; File file = null; try { fis = new FileInputStream(file=getFile(name)); } catch(FileNotFoundException exc) { if (file == null || !file.exists()) ExternalUtil.annotate (exc, NbBundle.getMessage(LocalFileSystem.class,"EXC_FileOutsideModified")); throw exc; } return fis; }
protected OutputStream outputStream (final String name) throws java.io.IOException { OutputStream retVal = new FileOutputStream (getFile (name)); // workaround for #42624 if ((Utilities.getOperatingSystem () & Utilities.OS_MAC) != 0) { retVal = getOutputStreamForMac42624(retVal, name); } return retVal; }
protected void lock (String name) throws IOException { File file = getFile (name); if ((!file.canWrite () && file.exists ()) || isReadOnly()) { FSException.io ("EXC_CannotLock", name, getDisplayName (), file.getAbsolutePath ()); // NOI18N } }