/** Finalize this object. Calls {@link #releaseLock} to release the lock if the program * for some reason failed to. */ @Override public void finalize() { if(isValid()) { releaseLock(); boolean assertOn = false; assert assertOn = true; if (assertOn) { StreamPool.LOG.log(Level.SEVERE, "Not released lock for file: " + toString() + " (trapped in finalizer)", lockedBy); // NOI18N } } } }
@Override public void close() throws IOException { try { super.flush(); lock.releaseLock(); super.close(); } catch(IOException iex) { if (lock.isValid()) { lock.releaseLock(); } throw iex; } } };
if (lock.isValid()) { lock.releaseLock();
/** Tests whether the entry is locked. * @return <code>true</code> if so */ public boolean isLocked() { FileLock l = lock == null ? null : (FileLock)lock.get (); return l != null && l.isValid (); }
/** 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; }
/** Finalize this object. Calls {@link #releaseLock} to release the lock if the program * for some reason failed to. */ public void finalize () { assert (isValid ()) : assertMessageForInvalidLocks(); releaseLock (); }
/** Finalize this object. Calls {@link #releaseLock} to release the lock if the program * for some reason failed to. */ public void finalize () { assert (isValid ()) : assertMessageForInvalidLocks(); releaseLock (); }
/** A method to change the entry file to some else. * @param newFile */ final void changeFile (FileObject newFile) { if (newFile.equals (file)) { return; } newFile.setImportant (isImportant ()); this.file = newFile; // release lock for old file FileLock l = lock == null ? null : (FileLock)lock.get (); if (l != null && l.isValid ()) { l.releaseLock (); } lock = null; }
/** Reverse method that can be called to make the environment * unmodified. */ public void unmarkModified() { if (fileLock != null && fileLock.isValid()) { fileLock.releaseLock(); } this.getDataObject ().setModified (false); }
/** Obtains the output stream. * @exception IOException if an I/O error occures */ public OutputStream outputStream() throws IOException { if (fileLock == null || !fileLock.isValid()) { fileLock = takeLock (); } try { return getFileImpl ().getOutputStream (fileLock); } catch (IOException fse) { // [pnejedly] just retry once. // Ugly workaround for #40552 if (fileLock == null || !fileLock.isValid()) { fileLock = takeLock (); } return getFileImpl ().getOutputStream (fileLock); } }
/** First of all tries to lock the primary file and * if it succeeds it marks the data object modified. * <p><b>Note: There is a contract (better saying a curse) * that this method has to call {@link #takeLock} method * in order to keep working some special filesystem's feature. * See <a href="http://www.netbeans.org/issues/show_bug.cgi?id=28212">issue #28212</a></b>. * * @exception IOException if the environment cannot be marked modified * (for example when the file is readonly), when such exception * is the support should discard all previous changes * @see org.openide.filesystems.FileObject#isReadOnly */ public void markModified() throws java.io.IOException { // XXX This shouldn't be here. But it is due to the 'contract', // see javadoc to this method. if (fileLock == null || !fileLock.isValid()) { fileLock = takeLock (); } if(getFileImpl().isReadOnly()) { if(fileLock != null && fileLock.isValid()) { fileLock.releaseLock(); } throw new IOException("File " // NOI18N + getFileImpl().getNameExt() + " is read-only!"); // NOI18N } this.getDataObject ().setModified (true); }
if (is != null) try {is.close();} catch (IOException ioe) {} if (os != null) try {os.close();} catch (IOException ioe) {} if (fl != null && fl.isValid()) fl.releaseLock();