public FileLock lock() throws IOException { return fileObj.lock(); }
/** Adds another lock into this lock. * @param fo file object to keep the lock for * @exception IOException if the lock cannot be obtained */ public void addLock(FileObject fo) throws IOException { map.put(fo, fo.lock()); }
/** * Test if file is locked * @return true if file is locked * @since 7.3 */ public boolean isLocked() { FileLock fLock = null; try { fLock = lock(); } catch (FileAlreadyLockedException fax) { return true; } catch (IOException ex) { return false; } finally { if (fLock != null) { fLock.releaseLock(); } } return fLock == null; }
/** * @param leader leader file object * @param delegates all delegates for this file object * @param systems a set of filesystems we should create lock on * @exception IOException if the lock cannot be obtained */ public MfLock(FileObject leader, Enumeration<FileObject> delegates, Set<? extends FileSystem> systems) throws IOException { while (delegates.hasMoreElements()) { FileObject fo = delegates.nextElement(); if (systems.contains(fo.getFileSystem())) { FileLock l = fo.lock(); map.put(fo, l); } } /* JST: Commented out because cause problems when locking a file that is only of filesystems that are readonly (for example when file is only on shared installation and locks are allowed only on local => then there is nothing to lock. if (map.isEmpty()) { // trouble, the filesystem returned wrong set of systems to lock // on => warn about possibly wrong implementation // to correct the problem override appropriatelly createLocksOn // method of MultiFileSystem throw new IOException ("Writable file is not on filesystem from createLocksOn"); // NOI18N } */ }
/** Delete this file. If the file is a folder and it is not empty then * all of its contents are also recursively deleted. FileObject is locked * before delete and finally is this lock released. * * @exception IOException if the file could not be deleted or * FileAlreadyLockedException if the file is already locked {@link #lock} * @since 1.15 */ public final void delete() throws IOException { FileLock lock = lock(); try { delete(lock); } finally { lock.releaseLock(); } }
/** Deletes a file object that will mask the given file. * @param fs filesystem to work on * @param res resource name of the file * @exception IOException if it fails */ void unmaskFile(FileSystem fs, String res) throws IOException { FileObject fo = findResourceOn(fs, res + MASK); if (fo != null) { FileLock lock = fo.lock(); try { fo.delete(lock); } finally { lock.releaseLock(); } } }
/** Moves file to the selected folder. * This implementation uses a copy-and-delete mechanism, and automatically uses the necessary lock. * @param source source file object * @param destFolder destination folder * @param newName file name (without extension) of destination file * @return new file object * @exception IOException if either the {@link #copyFile copy} or {@link FileObject#delete delete} failed */ public static FileObject moveFile(FileObject source, FileObject destFolder, String newName) throws IOException { FileLock lock = null; try { lock = source.lock(); return source.move(lock, destFolder, newName, source.getExt()); } finally { if (lock != null) { lock.releaseLock(); } } }
FileLock lock = fd.lock();
public OutputStream getOutputStream() throws IOException, UnknownServiceException { connect(); if (fo.isFolder()) { throw new UnknownServiceException(); } if (oStream == null) { FileLock flock = fo.lock(); oStream = new LockOS(fo.getOutputStream(flock), flock); } return oStream; }
final FileLock lock = lock(); final OutputStream os; try {
lock = dest.lock(); bufIn = source.getInputStream();
final public void delete(FileLock lock) throws IOException { if (isFolder()) { FileObject[] fos = this.getChildren(); for (int i = 0; i < fos.length; i++) { FileObject fo = fos[i]; FileLock foLock = fo.lock(); try { fo.delete(foLock); } catch (IOException iex) { String message = NbBundle.getMessage(AbstractFolder.class, "EXC_CannotDelete", // XXX use FileUtil.getFileDisplayName instead? getPath(), fo.getFileSystem().getDisplayName() ); ExternalUtil.annotate(iex, message); //NOI18N throw iex; } finally { foLock.releaseLock(); } } } handleDelete(lock); }
/** Adds another lock into this lock. * @param fo file object to keep the lock for * @exception IOException if the lock cannot be obtained */ public void addLock (FileObject fo) throws IOException { map.put (fo, fo.lock ()); }
/** Obtains lock for primary file. * * @return the lock * @exception IOException if taking the lock fails */ protected FileLock takePrimaryFileLock () throws IOException { return getPrimaryFile ().lock (); }
public static void createFile(FileObject target, String content, String encoding) throws IOException{ FileLock lock = target.lock(); try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(target.getOutputStream(lock), encoding)); bw.write(content); bw.close(); } finally { lock.releaseLock(); } }
public static void createFile(FileObject target, String content, String encoding) throws IOException{ FileLock lock = target.lock(); try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(target.getOutputStream(lock), encoding)); bw.write(content); bw.close(); } finally { lock.releaseLock(); } }
/** Try to lock this file entry. * @return the lock if the operation was successful; otherwise <code>null</code> * @throws IOException if the lock could not be taken */ public FileLock takeLock() throws IOException { FileLock l = lock == null ? null : (FileLock)lock.get (); if (l == null || !l.isValid ()){ l = getFile ().lock (); lock = new WeakReference (l); } return l; }
public LckStream (final FileObject fo) throws IOException { assert fo != null; this.lock = fo.lock(); try { this.delegate = fo.getOutputStream (this.lock); } finally { if (this.delegate == null) { this.lock.releaseLock(); } } }
public void write(org.openide.filesystems.FileObject fo) throws java.io.IOException { org.openide.filesystems.FileLock lock = fo.lock(); try { java.io.OutputStream out = fo.getOutputStream(lock); write(out); out.close(); } finally { lock.releaseLock(); } }
public void run() throws IOException { FileObject fo = FileUtil.createData(rootFo, fullPath); FileLock lock = fo.lock(); try { OutputStream os = fo.getOutputStream(lock); writer.writeTo(os); } finally { lock.releaseLock(); } } } );