Exemplo n.º 1
0
  public static void generate_preview_for_torrent(TOTorrent created, File file)
      throws TOTorrentException {

    logger.finer("generating preview..2.");
    try {
      File largestFile = null;
      long largest = 0;
      for (TOTorrentFile f : created.getFiles()) {
        if (f == null) {
          continue;
        }

        if (InOrderType.getType(f.getRelativePath()) == null) {
          continue;
        }
        if (f.getLength() > largest) {
          largest = f.getLength();
          if (file.isDirectory() == false) {
            largestFile = new File(file.getParent(), f.getRelativePath());
          } else {
            largestFile = new File(file, f.getRelativePath());
          }
        }
      }

      if (largestFile != null) {
        logger.finer("largest is: " + largestFile.getAbsolutePath());
      }

      try {
        FFMpegAsyncOperationManager.getInstance()
            .getPreviewImage(created.getHash(), largestFile, 10, TimeUnit.SECONDS);
      } catch (TorrentException e) {
        // this should never happen...
        e.printStackTrace();
      } catch (DataNotAvailableException e) {
        logger.finest("unable to create preview for file: " + largest);
      }
    } catch (NullPointerException e) {
      logger.warning("Preview generation null pointer: " + e.toString());
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  private void reserveAccess(String reason) throws FMFileManagerException {

    if (clone) {

      return;
    }

    try {
      file_map_mon.enter();

      // System.out.println( "FMFile::reserveAccess:" + canonical_path + "("+ owner.getName() + ")"
      // + " [" + (access_mode==FM_WRITE?"write":"read") + "]" + " - " +
      // Debug.getCompressedStackTrace());

      List owners = (List) file_map.get(canonical_path);

      Object[] my_entry = null;

      if (owners == null) {

        Debug.out("reserveAccess fail");

        throw (new FMFileManagerException(
            "File '"
                + canonical_path
                + "' has not been reserved (no entries), '"
                + owner.getName()
                + "'"));
      }

      for (Iterator it = owners.iterator(); it.hasNext(); ) {

        Object[] entry = (Object[]) it.next();

        String entry_name = ((FMFileOwner) entry[0]).getName();

        // System.out.println( "    existing entry: " + entry_name );

        if (owner.getName().equals(entry_name)) {

          my_entry = entry;
        }
      }

      if (my_entry == null) {

        Debug.out("reserveAccess fail");

        throw (new FMFileManagerException(
            "File '"
                + canonical_path
                + "' has not been reserved (not found), '"
                + owner.getName()
                + "'"));
      }

      my_entry[1] = new Boolean(access_mode == FM_WRITE);
      my_entry[2] = reason;

      int read_access = 0;
      int write_access = 0;
      int write_access_lax = 0;

      TOTorrentFile my_torrent_file = owner.getTorrentFile();

      StringBuilder users_sb = owners.size() == 1 ? null : new StringBuilder(128);

      for (Iterator it = owners.iterator(); it.hasNext(); ) {

        Object[] entry = (Object[]) it.next();

        FMFileOwner this_owner = (FMFileOwner) entry[0];

        if (((Boolean) entry[1]).booleanValue()) {

          write_access++;

          TOTorrentFile this_tf = this_owner.getTorrentFile();

          if (my_torrent_file != null
              && this_tf != null
              && my_torrent_file.getLength() == this_tf.getLength()) {

            write_access_lax++;
          }

          if (users_sb != null) {
            if (users_sb.length() > 0) {
              users_sb.append(",");
            }
            users_sb.append(this_owner.getName());
            users_sb.append(" [write]");
          }

        } else {

          read_access++;

          if (users_sb != null) {
            if (users_sb.length() > 0) {
              users_sb.append(",");
            }
            users_sb.append(this_owner.getName());
            users_sb.append(" [read]");
          }
        }
      }

      if (write_access > 1 || (write_access == 1 && read_access > 0)) {

        // relax locking if strict is disabled and torrent file is same size

        if (!COConfigurationManager.getBooleanParameter("File.strict.locking")) {

          if (write_access_lax == write_access) {

            return;
          }
        }

        Debug.out("reserveAccess fail");

        throw (new FMFileManagerException(
            "File '"
                + canonical_path
                + "' is in use by '"
                + (users_sb == null ? "eh?" : users_sb.toString())
                + "'"));
      }

    } finally {

      file_map_mon.exit();
    }
  }