Beispiel #1
0
  private int readFile(Section sl, String fileName, InputStream is, int limit) {
    int ret = READ_ALL;
    try {
      if (is == null) {
        // Check file size (only if not reading from stream)
        File f = new File(fileName);
        long size = f.length();
        is = new FileInputStream(f);
        if (size > limit) {
          // Need to seek to "end - limit"
          Util.skip(is, size - limit);
          Util.skipToEol(is);
          printErr(
              1,
              "File '"
                  + fileName
                  + "' is too long, loading only last "
                  + (limit / Util.MB)
                  + " megabyte(s)...");
          ret = READ_PARTS;
        }
      }

      LineReader br = new LineReader(is);

      String line = null;
      while (null != (line = br.readLine())) {
        sl.addLine(line);
      }
      br.close();
      is.close();
      return ret;
    } catch (IOException e) {
      printErr(1, "Error reading file '" + fileName + "' (it will be ignored): " + e);
      return READ_FAILED;
    }
  }