Ejemplo n.º 1
0
  /**
   * constructor
   *
   * @param r
   * @throws java.io.FileNotFoundException
   */
  public FileInputIterator(Reader r, String fileName, boolean reportProgress) throws IOException {
    this.fileName = fileName;

    if (fileName.startsWith(PREFIX_TO_INDICATE_TO_PARSE_FILENAME_STRING)) {
      reader = new BufferedReader(new StringReader(fileName.substring(3)));
      endOfLineBytes = 1;
      maxProgress = fileName.length() - PREFIX_TO_INDICATE_TO_PARSE_FILENAME_STRING.length();
    } else {
      reader = new BufferedReader(r, bufferSize);
      endOfLineBytes = Basic.getNumberOfNonSpaceCharacters(fileName);

      File file = new File(fileName);
      if (file.exists()) maxProgress = file.length();
      else maxProgress = 10000000; // unknown
    }

    setReportProgress(reportProgress);
  }
Ejemplo n.º 2
0
  /**
   * constructor
   *
   * @param fileName
   * @throws java.io.FileNotFoundException
   */
  public FileInputIterator(String fileName, boolean reportProgress) throws IOException {
    this.fileName = fileName;

    if (fileName.startsWith(PREFIX_TO_INDICATE_TO_PARSE_FILENAME_STRING)) {
      reader = new BufferedReader(new StringReader(fileName.substring(3)));
      endOfLineBytes = 1;
      maxProgress = fileName.length() - PREFIX_TO_INDICATE_TO_PARSE_FILENAME_STRING.length();
    } else {
      final File file = new File(fileName);
      if (Basic.isZIPorGZIPFile(file.getPath())) {
        reader =
            new BufferedReader(
                new InputStreamReader(Basic.getInputStreamPossiblyZIPorGZIP(file.getPath())));
        endOfLineBytes = 1;
        maxProgress = 5 * file.length(); // assuming compression factor of 5-to-1
      } else {
        reader = new BufferedReader(new FileReader(file), bufferSize);
        endOfLineBytes = Basic.getNumberOfNonSpaceCharacters(fileName);
        maxProgress = file.length();
      }
    }
    done = (maxProgress <= 0);
    setReportProgress(reportProgress);
  }