Esempio n. 1
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));
    }
  }
Esempio n. 2
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. 3
0
  public void setStorageType(int new_type) throws FMFileManagerException {

    try {
      this_mon.enter();

      boolean was_open = isOpen();

      if (was_open) {

        closeSupport(false);
      }

      try {
        file_access.setStorageType(new_type);

      } finally {

        if (was_open) {

          openSupport("Re-open after storage type change");
        }
      }

    } finally {

      this_mon.exit();
    }
  }
Esempio n. 4
0
 protected String getString() {
   File cPath = new File(canonical_path);
   String sPaths;
   if (cPath.equals(linked_file)) sPaths = "can/link=" + Debug.secretFileName(canonical_path);
   else
     sPaths =
         "can="
             + Debug.secretFileName(canonical_path)
             + ",link="
             + Debug.secretFileName(linked_file.toString());
   return sPaths + ",raf=" + raf + ",acc=" + access_mode + ",ctrl = " + file_access.getString();
 }
Esempio n. 5
0
  protected void setLengthSupport(long length) throws FMFileManagerException {

    try {
      file_access.setLength(raf, length);

    } catch (FMFileManagerException e) {

      if (OUTPUT_REOPEN_RELATED_ERRORS) {
        Debug.printStackTrace(e);
      }

      try {
        reopen(e);

        file_access.setLength(raf, length);

      } catch (Throwable e2) {

        throw (e);
      }
    }
  }
Esempio n. 6
0
  protected long getLengthSupport() throws FMFileManagerException {

    try {
      return (file_access.getLength(raf));

    } catch (FMFileManagerException e) {

      if (OUTPUT_REOPEN_RELATED_ERRORS) {
        Debug.printStackTrace(e);
      }

      try {
        reopen(e);

        return (file_access.getLength(raf));

      } catch (Throwable e2) {

        throw (e);
      }
    }
  }
Esempio n. 7
0
  protected void writeSupport(DirectByteBuffer[] buffers, long position)
      throws FMFileManagerException {
    try {

      file_access.write(raf, buffers, position);

    } catch (FMFileManagerException e) {

      if (OUTPUT_REOPEN_RELATED_ERRORS) {
        Debug.printStackTrace(e);
      }

      try {
        reopen(e);

        file_access.write(raf, buffers, position);

      } catch (Throwable e2) {

        throw (e);
      }
    }
  }
Esempio n. 8
0
 protected void setPieceCompleteSupport(int piece_number, DirectByteBuffer piece_data)
     throws FMFileManagerException {
   file_access.setPieceComplete(raf, piece_number, piece_data);
 }
Esempio n. 9
0
 protected boolean isPieceCompleteProcessingNeeded(int piece_number)
     throws FMFileManagerException {
   return (file_access.isPieceCompleteProcessingNeeded(piece_number));
 }
Esempio n. 10
0
  public void flush() throws FMFileManagerException {

    file_access.flush();
  }
Esempio n. 11
0
 public int getStorageType() {
   return (file_access.getStorageType());
 }