org.openide.filesystems.FileLock.isValid()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.openide.filesystems.FileLock.isValid()方法的一些代码示例,展示了FileLock.isValid()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.isValid()方法的具体详情如下:
包路径:org.openide.filesystems.FileLock
类名称:FileLock
方法名:isValid

FileLock.isValid介绍

[英]Test whether this lock is still active, or released.
[中]测试此锁是否仍处于激活状态或已释放状态。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/** 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
      }
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

@Override
  public void close() throws IOException {
    try {
      super.flush();
      lock.releaseLock();
      super.close();
    } catch(IOException iex) {
      if (lock.isValid()) {
        lock.releaseLock();
      }
      throw iex;
    }
  }
};

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

if (lock.isValid()) {
  lock.releaseLock();

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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 ();
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

/** 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 ();
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

/** 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 ();
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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);
  }        
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/** 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);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-cldcplatform

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();

相关文章