Esempio n. 1
0
  protected void reopen(FMFileManagerException cause) throws Throwable {

    if (!cause.isRecoverable()) {

      throw (cause);
    }

    if (raf != null) {

      try {

        raf.close();

      } catch (Throwable e) {

        // ignore any close failure as can't do much
      }

      // don't clear down raf here as we want to leave things looking as they were
      // if the subsequent open fails
    }

    file_access.aboutToOpen();

    raf =
        new RandomAccessFile(
            linked_file, access_mode == FM_READ ? READ_ACCESS_MODE : WRITE_ACCESS_MODE);

    Debug.outNoStack("Recovered connection to " + getName() + " after access failure");
  }
Esempio n. 2
0
  protected void openSupport(String reason) throws FMFileManagerException {

    if (raf != null) {

      throw (new FMFileManagerException("file already open"));
    }

    reserveAccess(reason);

    try {
      file_access.aboutToOpen();

      raf =
          new RandomAccessFile(
              linked_file, access_mode == FM_READ ? READ_ACCESS_MODE : WRITE_ACCESS_MODE);

    } catch (FileNotFoundException e) {

      int st = file_access.getStorageType();

      boolean ok = false;

      // edge case here when switching one file from dnd -> download and the compact files at edge
      // boundaries not
      // yet allocated - attempt to create the file on demand

      try {
        linked_file.getParentFile().mkdirs();

        linked_file.createNewFile();

        raf =
            new RandomAccessFile(
                linked_file, access_mode == FM_READ ? READ_ACCESS_MODE : WRITE_ACCESS_MODE);

        ok = true;

      } catch (Throwable f) {
      }

      if (!ok) {

        Debug.printStackTrace(e);

        throw (new FMFileManagerException("open fails", e));
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      throw (new FMFileManagerException("open fails", e));
    }
  }