Esempio n. 1
0
  /** closeFile Close the current file, but keep its path so we can easily open it again. */
  public void closeFile() throws NexusException {
    try {
      if (m_nfFile != null) {
        m_nfFile.close();
        m_nfFile.finalize();
      }
      m_nfFile = null;

    } catch (Throwable t) {
      if (g_mutex.isLocked() && g_curFile.equals(m_sFilePath)) {
        if (g_mutex.getHoldCount() - 1 == 0) {
          g_curFile = "";
        }
        g_mutex.unlock();
      }
      if (t instanceof NexusException) {
        throw (NexusException) t;
      } else {
        t.printStackTrace();
        return;
      }
    }
    if (g_mutex.isLocked() && g_curFile.equals(m_sFilePath)) {
      if (g_mutex.getHoldCount() - 1 == 0) {
        g_curFile = "";
      }

      g_mutex.unlock();
    }
  }
Esempio n. 2
0
  protected void openFile(String sFilePath, int iAccessMode) throws NexusException {
    boolean openFile = false;
    // Try to open file
    m_sFilePath = sFilePath;
    g_mutex.lock();
    g_curFile = m_sFilePath;

    try {
      // No file yet opened
      if (null == m_nfFile) {
        openFile = true;
      } else {
        // Check file isn't opened yet
        String sCurFile = "";
        try {
          sCurFile = m_nfFile.inquirefile();
        } catch (NexusException ne) {
          openFile = true;
        }

        // Check file opened is the good one and have correct write
        // access
        if (!sFilePath.equals(sCurFile) || iAccessMode != m_iAccessMode) {
          m_nfFile.close();
          openFile = true;
        }
      }

      // open the file if needed
      if (openFile) {
        open(sFilePath, iAccessMode);
        m_iAccessMode = iAccessMode;
      }

    } catch (NexusException e) {
      m_nfFile = null;
      m_sFilePath = "";
      g_curFile = "";
      g_mutex.unlock();
      throw e;
    }
  }