Exemple #1
0
  /*enregistrement d un fichier dans une variable de classe*/
  private String readFile() {

    String myLine = "";

    try {
      // création des flux
      InputStreamReader in = new InputStreamReader(new FileInputStream(this.pCheminCible));

      LineNumberReader llog = new LineNumberReader(in);
      // copie du fichier

      while ((myLine = llog.readLine()) != null) {
        // --- Ajout de la ligne au contenu
        contenu += myLine;
      }

      // forcer l'ecriture du contenu du tampon dans le fichier
      setStatus(200);
      System.out.println(getStatus() + "le contenu " + contenu);

    } catch (FileNotFoundException e) {
      setStatus(404);
      System.out.println(e);
    } catch (Exception e) {
      setStatus(500);
      System.out.println(e);
    }
    return contenu;
  }
 /**
  * Show the description for a given project
  *
  * @param projectName The project name
  */
 private void generateGUIDescription(String projectName) {
   File proj =
       new File(
           Configuration.sourceDirPrefix
               + "/"
               + Configuration.projectDirInSourceFolder
               + "/"
               + projectName
               + "/"
               + Configuration.descriptionFileName);
   try {
     if (!proj.exists()) {
       descriptionText.setText("There is no description-file in the currently selected project.");
     } else {
       LineNumberReader r = new LineNumberReader(new FileReader(proj));
       String description = "";
       String tmp = null;
       while ((tmp = r.readLine()) != null) {
         description += tmp + "\n";
       }
       descriptionText.setText(description);
       descriptionText.setCaretPosition(0);
     }
   } catch (FileNotFoundException e) {
     descriptionText.setText("There is no description-file in the currently selected project.");
   } catch (IOException e) {
     Main.minorError(e);
     descriptionText.setText("There is no description-file in the currently selected project.");
   }
 }
  /**
   * Reads the file that specifies method calls that should be replaced by other method calls. The
   * file is of the form:
   *
   * <p>[regex] [orig-method-def] [new-method-name]
   *
   * <p>where the orig_method-def is of the form:
   *
   * <p>fully-qualified-method-name (args)
   *
   * <p>Blank lines and // comments are ignored. The orig-method-def is replaced by a call to
   * new-method-name with the same arguments in any classfile that matches the regular expressions.
   * All method names and argument types should be fully qualified.
   */
  public void read_map_file(File map_file) throws IOException {

    LineNumberReader lr = new LineNumberReader(new FileReader(map_file));
    MapFileError mfe = new MapFileError(lr, map_file);
    Pattern current_regex = null;
    Map<MethodDef, MethodInfo> map = new LinkedHashMap<MethodDef, MethodInfo>();
    for (String line = lr.readLine(); line != null; line = lr.readLine()) {
      line = line.replaceFirst("//.*$", "");
      if (line.trim().length() == 0) continue;
      if (line.startsWith(" ")) {
        if (current_regex == null)
          throw new IOException("No current class regex on line " + lr.getLineNumber());
        StrTok st = new StrTok(line, mfe);
        st.stok.wordChars('.', '.');
        MethodDef md = parse_method(st);
        String new_method = st.need_word();
        map.put(md, new MethodInfo(new_method));
      } else {
        if (current_regex != null) {
          MethodMapInfo mmi = new MethodMapInfo(current_regex, map);
          map_list.add(mmi);
          map = new LinkedHashMap<MethodDef, MethodInfo>();
        }
        current_regex = Pattern.compile(line);
      }
    }
    if (current_regex != null) {
      MethodMapInfo mmi = new MethodMapInfo(current_regex, map);
      map_list.add(mmi);
    }

    dump_map_list();
  }
 public VariationRegexTrieLexiconMembership(
     String name, Reader lexiconReader, boolean ignoreCase) {
   this.name = name;
   this.lexicon = new java.util.Vector();
   LineNumberReader reader = new LineNumberReader(lexiconReader);
   String line;
   while (true) {
     try {
       line = reader.readLine();
     } catch (IOException e) {
       throw new IllegalStateException();
     }
     if (line == null) {
       break;
     } else {
       StringTokenizer st = new StringTokenizer(line, " ");
       int numToks = st.countTokens();
       if (numToks > 0) {
         lexicon.add(new Pattern[numToks]);
         Pattern[] pats = (Pattern[]) lexicon.elementAt(lexicon.size() - 1);
         for (int i = 0; i < numToks; i++) {
           pats[i] = Pattern.compile(ignoreCase ? st.nextToken().toLowerCase() : st.nextToken());
         }
       }
     }
   }
   if (lexicon.size() == 0) throw new IllegalArgumentException("Empty lexicon");
 }
  public void open() throws IOException {

    paneCenter.getChildren().clear();

    String station = (String) cbStations.getValue();

    File f = new File("database\\" + station + "\\status.txt");
    FileReader fr1 = new FileReader(f);
    LineNumberReader ln = new LineNumberReader(fr1);
    int count = 0;
    while (ln.readLine() != null) {
      count++;
    }
    ln.close();
    fr1.close();

    FileReader fr2 = new FileReader(f);
    BufferedReader br = new BufferedReader(fr2);

    paneCenter.add(new Label("Last seen : " + (br.readLine())), 0, 0);

    for (int i = 1; i < count; i++) {
      paneCenter.add(new Label(br.readLine()), 0, i);
    }
    br.close();
    fr2.close();

    addQuantityToCB();
  }
  public static Set<String> retrievePeptides(File peptideFastaFile) {
    BufferedReader reader;

    Set<String> peptideSet = new TreeSet<String>();
    try {
      LineNumberReader lnr = new LineNumberReader(new FileReader(peptideFastaFile));
      lnr.skip(Long.MAX_VALUE);
      int nLines = lnr.getLineNumber();
      System.out.println(nLines);
      lnr.close();
      reader = new BufferedReader(new FileReader(peptideFastaFile));

      String nextLine;
      int lineCounter = 0;
      while ((nextLine = reader.readLine()) != null) {

        if (nextLine.length() > 0 && nextLine.charAt(0) != '>') {
          peptideSet.add(nextLine);
        }
        if (lineCounter % 1000000 == 0) {
          System.out.println(lineCounter + "/" + nLines);
        }
        lineCounter++;
      }
      reader.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return peptideSet;
  }
 private void test(String path) throws IOException {
   int count = 0;
   int ok = 0;
   int errors = 0;
   LineNumberReader lr =
       new LineNumberReader(new InputStreamReader(getClass().getResourceAsStream(path), "UTF-8"));
   String line;
   while ((line = lr.readLine()) != null) {
     if (line.trim().length() > 0 && !line.startsWith("#")) {
       try {
         int pos = line.indexOf('|');
         if (pos > 0) {
           validate(line.substring(0, pos), line.substring(pos + 1));
         } else {
           validate(line);
         }
         ok++;
       } catch (Exception e) {
         logger.warn(e.getMessage());
         errors++;
       }
       count++;
     }
   }
   lr.close();
   assertEquals(errors, 0);
   assertEquals(ok, count);
 }
 protected boolean returnPath() {
   File tmpDir = new File("/data/local/tmp");
   if (!tmpDir.exists()) {
     doExec(new String[] {"mkdir /data/local/tmp"});
   }
   try {
     InternalVariables.path = new HashSet<String>();
     // Try to read from the file.
     LineNumberReader lnr = null;
     doExec(
         new String[] {
           "dd if=/init.rc of=/data/local/tmp/init.rc", "chmod 0777 /data/local/tmp/init.rc"
         });
     lnr = new LineNumberReader(new FileReader("/data/local/tmp/init.rc"));
     String line;
     while ((line = lnr.readLine()) != null) {
       RootTools.log(line);
       if (line.contains("export PATH")) {
         int tmp = line.indexOf("/");
         InternalVariables.path =
             new HashSet<String>(Arrays.asList(line.substring(tmp).split(":")));
         return true;
       }
     }
     return false;
   } catch (Exception e) {
     if (RootTools.debugMode) {
       RootTools.log("Error: " + e.getMessage());
       e.printStackTrace();
     }
     return false;
   }
 }
  /** @tests java.io.LineNumberReader#read(char[], int, int) */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      method = "read",
      args = {char[].class, int.class, int.class})
  public void test_read$CII_Exception() throws IOException {
    lnr = new LineNumberReader(new StringReader(text));
    char[] c = new char[10];

    try {
      lnr.read(c, -1, 1);
      fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
      // Expected.
    }

    try {
      lnr.read(c, 0, -1);
      fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
      // Expected.
    }

    try {
      lnr.read(c, 10, 1);
      fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
      // Expected.
    }
  }
  private List<String> extractRoles(String t) throws IOException {
    /// logger.debug("\n" + t);
    List<String> list = new ArrayList<String>();
    LineNumberReader lr = new LineNumberReader(new StringReader(t));
    String line = null;

    String role = null;
    String annotation = null;
    while ((line = lr.readLine()) != null) {
      String[] s = line.split("\t");
      if (s[6].toLowerCase().startsWith("b-")) {
        logger.debug("a\t\t" + role);

        if (role != null && annotation != null) {

          list.add(role + "\t" + annotation);
          logger.warn("adding " + role + "\t" + annotation);
        }
        role = new String(s[2]);
        annotation = s[5] + "\t" + s[6];
      } else if (s[6].toLowerCase().startsWith("i-")) {
        if (role != null) {
          role += " " + s[2];
        }
      }
    }
    if (role != null && annotation != null) {
      list.add(role + "\t" + annotation);
      logger.warn("adding " + role + "\t" + annotation);
    }
    return list;
  }
Exemple #11
0
  public static String DNS(int n, boolean format) {
    String dns = null;
    Process process = null;
    LineNumberReader reader = null;
    try {
      final String CMD = "getprop net.dns" + (n <= 1 ? 1 : 2);

      process = Runtime.getRuntime().exec(CMD);
      reader = new LineNumberReader(new InputStreamReader(process.getInputStream()));

      String line = null;
      while ((line = reader.readLine()) != null) {
        dns = line.trim();
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (reader != null) reader.close();
        if (process != null) process.destroy(); // 测试发现,可能会抛异常
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return format ? (dns != null ? dns.replace('.', '_') : dns) : dns;
  }
  @Override
  public ArrayList<Department> handleResponse(HttpResponse response)
      throws ClientProtocolException, IOException {
    // parse the JSON and put the data in the arrayList
    HttpEntity httpEntity = response.getEntity();
    //			InputStream inputStream = httpEntity.getContent();

    String jsonStr = EntityUtils.toString(httpEntity);
    LineNumberReader lnr = new LineNumberReader(new StringReader(jsonStr));
    String currentString;
    while ((currentString = lnr.readLine()) != null) {
      // Log.v("TeamLeader", "httpResponse:" + currentString);
    }

    try {
      JSONArray jsonArray = new JSONArray(jsonStr);
      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jSonP = jsonArray.getJSONObject(i);
        Department department = new Department();
        department.setId(jSonP.getInt("id"));
        department.setName(jSonP.getString("name"));
        departments.add(department);
      }

    } catch (JSONException e) {
      if (e.getMessage().contains("No value for")) {}
      e.printStackTrace();
    }

    fillView.setList(departments);

    return departments;
  }
  public static ConnectionCosts build(String filename) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    InputStreamReader streamReader = new InputStreamReader(inputStream);
    LineNumberReader lineReader = new LineNumberReader(streamReader);

    String line = lineReader.readLine();
    String[] dimensions = line.split("\\s+");

    assert dimensions.length == 3;

    int forwardSize = Integer.parseInt(dimensions[0]);
    int backwardSize = Integer.parseInt(dimensions[1]);

    assert forwardSize > 0 && backwardSize > 0;

    ConnectionCosts costs = new ConnectionCosts(forwardSize, backwardSize);

    while ((line = lineReader.readLine()) != null) {
      String[] fields = line.split("\\s+");

      assert fields.length == 3;

      short forwardId = Short.parseShort(fields[0]);
      short backwardId = Short.parseShort(fields[1]);
      short cost = Short.parseShort(fields[2]);

      costs.add(forwardId, backwardId, cost);
    }
    return costs;
  }
  /**
   * Metodo que faz a leitura do arquivo e faz as validacoes iniciais
   *
   * @param nomeArquivoEntrada
   * @throws IOException
   */
  @SuppressWarnings("resource")
  public boolean lerArquivo(String nomeArquivoEntrada) throws IOException {
    BufferedReader buffRead = new BufferedReader(new FileReader(nomeArquivoEntrada));
    File arquivoleitura = new File(nomeArquivoEntrada);
    linhaLeitura = new LineNumberReader(new FileReader(nomeArquivoEntrada));
    // Ignora as linhas em branco
    linhaLeitura.skip(arquivoleitura.length());

    this.qtdLinhas = linhaLeitura.getLineNumber();
    // Verifica se o arquivo esta vazio ou nao
    if (this.qtdLinhas <= 1) {
      System.out.println("REJEITA - ARQUIVO DE ENTRADA VAZIO");
      return false;
    }
    // Inicia o vetor linhasArquivos com o total de linhas do arquivo
    this.linhasArquivo = new String[this.qtdLinhas];

    int i = 0;
    // Loop que recebe cada linha do arquivo entrada
    String linha;
    while ((linha = buffRead.readLine()) != null) {
      // Verifica se a linha esta vazia ou nao
      if (!linha.isEmpty()) {
        this.linhasArquivo[i] = linha;
        i++;
      }
    }
    buffRead.close();
    return true;
  }
Exemple #15
0
 private ArrayList<String> readLines(File todoFile) {
   ArrayList<String> lines = new ArrayList<String>();
   LineNumberReader reader = null;
   if (todoFile.exists()) {
     try {
       reader = new LineNumberReader(new BufferedReader(new FileReader(todoFile)));
       String line = null;
       while ((line = reader.readLine()) != null) {
         lines.add(line);
       }
     } catch (FileNotFoundException e) {
       Logger logger = Logger.getLogger(getPackageName());
       logger.log(Level.SEVERE, "Unable to read items from todo.txt", e);
     } catch (IOException e) {
       Logger logger = Logger.getLogger(getPackageName());
       logger.log(Level.SEVERE, "Unable to read items from todo.txt", e);
     } finally {
       if (reader != null) {
         try {
           reader.close();
         } catch (IOException e) {
           Logger logger = Logger.getLogger(getPackageName());
           logger.log(Level.SEVERE, "Unable to close todo.txt", e);
         }
       }
     }
   }
   return lines;
 }
  /** @tests java.io.LineNumberReader#skip(long) */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "skip",
      args = {long.class})
  public void test_skipJ() throws IOException {
    lnr = new LineNumberReader(new StringReader(text));
    char[] c = new char[100];
    long skipped = lnr.skip(80);
    assertEquals("Test 1: Incorrect number of characters skipped;", 80, skipped);
    lnr.read(c, 0, 100);
    assertTrue(
        "Test 2: Failed to skip to correct position.",
        text.substring(80, 180).equals(new String(c, 0, c.length)));

    try {
      lnr.skip(-1);
      fail("Test 3: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
      // Expected.
    }

    lnr.close();
    try {
      lnr.skip(1);
      fail("Test 4: IOException expected.");
    } catch (IOException e) {
      // Expected.
    }
  }
  /**
   * Importer with full settings.
   *
   * @param filename the file containing the data
   * @param sep the token which separates the values
   * @param labelPosition the position of the class label
   * @return the full list of TrainingSample
   * @throws IOException
   */
  public static List<TrainingSample<double[]>> importFromFile(
      String filename, String sep, int labelPosition) throws IOException {

    // the samples list
    List<TrainingSample<double[]>> list = new ArrayList<TrainingSample<double[]>>();

    LineNumberReader line = new LineNumberReader(new FileReader(filename));
    String l;
    // parse all lines
    while ((l = line.readLine()) != null) {

      String[] tok = l.split(",");
      double[] d = new double[tok.length - 1];
      int y = 0;

      if (labelPosition == -1) {
        // first n-1 fields are attributes
        for (int i = 0; i < d.length; i++) d[i] = Double.parseDouble(tok[i]);
        // last field is class
        y = Integer.parseInt(tok[tok.length - 1]);

      } else if (labelPosition < d.length) {
        for (int i = 0; i < labelPosition; i++) d[i] = Double.parseDouble(tok[i]);
        for (int i = labelPosition + 1; i < d.length; i++) d[i - 1] = Double.parseDouble(tok[i]);
        y = Integer.parseInt(tok[labelPosition]);
      }

      TrainingSample<double[]> t = new TrainingSample<double[]>(d, y);
      list.add(t);
    }

    line.close();
    return list;
  }
Exemple #18
0
  public static void main(String[] args) {
    if (args.length != 2) {
      throw new IllegalArgumentException("need char and file");
    }

    LineNumberReader in;
    try {
      FileReader fileIn = new FileReader(args[1]);
      in = new LineNumberReader(fileIn);
    } catch (FileNotFoundException e) {
      System.out.println("指定されたファイルが見つかりません。");
      return;
    }
    String str;
    try {
      while ((str = in.readLine()) != null) {
        if (str.contains(args[0])) {
          System.out.printf("%3d: %s%n", in.getLineNumber(), str);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        in.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemple #19
0
 private void init(File f) {
   try {
     f = new File(f.getCanonicalPath());
     LineNumberReader rdr = new LineNumberReader(new FileReader(f));
     String line;
     int mark;
     String msgCode;
     String msg;
     StringTokenizer toks;
     while (null != (line = rdr.readLine())) {
       if (0 <= (mark = line.indexOf("//"))) {
         line = line.substring(0, mark);
       }
       if (1 > line.length()) {
         continue;
       }
       line = line.trim();
       mark = line.indexOf(' ');
       msgCode = line.substring(0, mark);
       msg = line.substring(mark).trim();
       Util.invariant(null == m_msgs.put(msgCode, msg));
     }
   } catch (Exception ex) {
     Util.abnormalExit(ex);
   }
 }
  /** Read input to test and break down into blocks. See parser-tests/readme.txt */
  private Map readBlocks(Reader input) throws IOException {
    Map blocks = new HashMap();
    LineNumberReader reader = new LineNumberReader(input);
    String line;
    String blockName = null;
    StringBuffer blockContents = null;
    while ((line = reader.readLine()) != null) {
      if (line.startsWith("~~~ ") && line.endsWith(" ~~~")) {
        if (blockName != null) {
          blocks.put(blockName, blockContents.toString());
        }
        blockName = line.substring(4, line.length() - 4);
        blockContents = new StringBuffer();
      } else {
        if (blockName != null) {
          blockContents.append(line);
          blockContents.append('\n');
        }
      }
    }

    if (blockName != null) {
      blocks.put(blockName, blockContents.toString());
    }

    return blocks;
  }
  protected void readProblemLine() throws IOException, ParseFormatException {

    String line = in.readLine();

    if (line == null) {
      throw new ParseFormatException(
          "premature end of file: <p cnf ...> expected  on line " + in.getLineNumber());
    }
    StringTokenizer stk = new StringTokenizer(line);

    if (!(stk.hasMoreTokens()
        && stk.nextToken().equals("p")
        && stk.hasMoreTokens()
        && stk.nextToken().equals(formatString))) {
      throw new ParseFormatException(
          "problem line expected (p cnf ...) on line " + in.getLineNumber());
    }

    // reads the max var id
    nbOfVars = Integer.parseInt(stk.nextToken());
    assert nbOfVars > 0;

    // reads the number of clauses
    expectedNbOfConstr = Integer.parseInt(stk.nextToken());
    assert expectedNbOfConstr > 0;
  }
Exemple #22
0
  private static List<Mount> getMounts() {

    LineNumberReader lnr = null;

    try {
      lnr = new LineNumberReader(new FileReader(MOUNT_FILE));
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
      return null;
    }

    String line;
    ArrayList<Mount> mounts = new ArrayList<Mount>();
    try {
      while ((line = lnr.readLine()) != null) {
        String[] fields = line.split(" ");
        mounts.add(new Mount(new File(fields[0]), new File(fields[1]), fields[2], fields[3]));
      }
      lnr.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return mounts;
  }
Exemple #23
0
  public static String getKeyValueFromParFile(File file, String key) {
    try {
      LineNumberReader reader = new LineNumberReader(new FileReader(file));
      String line;
      line = reader.readLine();
      String[] option;
      ParamInfo pi;
      while (line != null) {
        if (line.indexOf("=") != -1) {
          option = line.split("=", 2);
          option[0] = option[0].trim();
          option[1] = option[1].trim();
          if (option[0].trim().equals(key)) {
            return option[1];
          }
        }
        line = reader.readLine();
      }
    } catch (FileNotFoundException fnfe) {

    } catch (IOException ioe) {

    }
    return null;
  }
  public void loadFromFile(File positionFile) throws java.io.IOException {
    logger.logComment("Loading position records from file: " + positionFile.getAbsolutePath());

    this.reset();

    Reader in = new FileReader(positionFile);
    LineNumberReader reader = new LineNumberReader(in);
    String nextLine = null;

    String currentInputRef = null;

    while ((nextLine = reader.readLine()) != null) {
      // logger.logComment("Parsing line: "+ nextLine);

      if (nextLine.endsWith(":")) {
        currentInputRef = nextLine.substring(0, nextLine.length() - 1);
        logger.logComment("currentInputRef: " + currentInputRef);
      } else {
        SingleElectricalInput input = new SingleElectricalInput(nextLine);
        this.addSingleInput(currentInputRef, input);
      }
    }
    in.close();

    logger.logComment("Finished loading cell info. Internal state: " + this.toString());
  }
  protected int countRows(RetailerSite retailerSite, DataFile dataFile) {
    File filePath = null;

    try {
      filePath = configurationService.getFileSystem().getDirectory(dataFile.getFilePath(), true);
      TableDefinition tableDefinition = this.getTableDefinition(retailerSite, dataFile);
      String encoding = getDataImportEncoding(tableDefinition, filePath);

      LineNumberReader lnr =
          new LineNumberReader(new InputStreamReader(new FileInputStream(filePath), encoding));
      lnr.readLine(); // Skip header
      int numRows = 0;
      while (lnr.readLine() != null) {
        numRows++;
      }
      lnr.close();

      return numRows;
    } catch (Exception e) {
      logger.error(String.format("Failed to reading %s data file", filePath), e);
      dataFile.setStatus(FileStatus.ERROR_READ);
      dataFileRepository.update(dataFile);

      return -1;
    }
  }
 private boolean compareLines(
     final String refText, final String text, final CompareStatistics statistics)
     throws IOException {
   log("running comparison");
   final LineNumberReader lnrRef = new LineNumberReader(new StringReader(refText));
   final LineNumberReader lnrOther = new LineNumberReader(new StringReader(text));
   String lineRef;
   String lineOther;
   while ((lineRef = lnrRef.readLine()) != null) {
     lineOther = lnrOther.readLine();
     if (lineOther == null) {
       statistics.failedRefIsLonger();
       return false;
     }
     if (!lineRef.equals(lineOther)) {
       statistics.failedDontMatch(lineRef, lineOther);
       return false;
     }
   }
   if (lnrOther.readLine() != null) {
     statistics.failedOtherIsLonger();
     return false;
   }
   return true;
 }
 /**
  * Extracts the custom-text from the config file, without the surrounding <custom></custom> flag
  *
  * @param aConfigFile The config file
  * @return The custom text, an empty string upon any failure
  */
 private String getCustomText(File aConfigFile) {
   LineNumberReader reader = null;
   try {
     reader = new LineNumberReader(new FileReader(aConfigFile));
   } catch (FileNotFoundException e) {
     return "";
   }
   String result = "";
   boolean inCustom = false;
   String line = null;
   try {
     line = reader.readLine();
     while (line != null) {
       if (!inCustom) {
         if (!line.contains("<Custom>")) {
           line = reader.readLine();
           continue;
         }
         int offset = line.indexOf("<Custom>");
         result = line.substring(offset + 8); // skip the tag <Custom>
         inCustom = true;
       } else {
         result += line + "\n";
       }
       line = reader.readLine();
     }
   } catch (IOException e) {
     return "";
   }
   int offset = result.lastIndexOf("</Custom>");
   if (offset >= 0) {
     result = result.substring(0, offset);
   }
   return result;
 }
  /**
   * Load lexer specification file. This text file contains lexical rules to tokenize a text
   *
   * @param lexersText the lexer text filename
   * @return a map
   */
  private Map<String, String> load(String lexersText) {
    try {
      // Read the specification text file line by line
      FileInputStream fis = new FileInputStream(lexersText);
      InputStreamReader isr = new InputStreamReader(fis);
      LineNumberReader lnr = new LineNumberReader(isr);

      // Pattern for parsing each line of specification file
      Pattern lxRule = Pattern.compile(lxRuleString);
      while (true) {
        String line = lnr.readLine();
        // read until file is exhausted
        if (line == null) break;
        Matcher matcher = lxRule.matcher(line);
        if (matcher.matches()) {
          // add rules to the list of rules
          String name = matcher.group(1);
          String regex = matcher.group(2);
          lexerMap.put(regex, name);
        } else {
          System.err.println("Syntax error in " + lexersText + " at line " + lnr.getLineNumber());
          System.exit(1);
        }
      }
      // close the file
      fis.close();
    } catch (IOException ioe) {
      System.err.println("IOException!");
    }
    return lexerMap;
  }
 private void determineNameMapping(JarFile paramJarFile, Set paramSet, Map paramMap)
     throws IOException {
   InputStream localInputStream =
       paramJarFile.getInputStream(paramJarFile.getEntry("META-INF/INDEX.JD"));
   if (localInputStream == null) handleException("jardiff.error.noindex", null);
   LineNumberReader localLineNumberReader =
       new LineNumberReader(new InputStreamReader(localInputStream, "UTF-8"));
   String str = localLineNumberReader.readLine();
   if ((str == null) || (!str.equals("version 1.0")))
     handleException("jardiff.error.badheader", str);
   while ((str = localLineNumberReader.readLine()) != null) {
     List localList;
     if (str.startsWith("remove")) {
       localList = getSubpaths(str.substring("remove".length()));
       if (localList.size() != 1) handleException("jardiff.error.badremove", str);
       paramSet.add(localList.get(0));
       continue;
     }
     if (str.startsWith("move")) {
       localList = getSubpaths(str.substring("move".length()));
       if (localList.size() != 2) handleException("jardiff.error.badmove", str);
       if (paramMap.put(localList.get(1), localList.get(0)) != null)
         handleException("jardiff.error.badmove", str);
       continue;
     }
     if (str.length() <= 0) continue;
     handleException("jardiff.error.badcommand", str);
   }
   localLineNumberReader.close();
   localInputStream.close();
 }
 /**
  * Convert the given Class to an HTML.
  *
  * @param configuration the configuration.
  * @param cd the class to convert.
  * @param outputdir the name of the directory to output to.
  */
 public static void convertClass(Configuration configuration, ClassDoc cd, String outputdir) {
   if (cd == null || outputdir == null) {
     return;
   }
   File file;
   SourcePosition sp = cd.position();
   if (sp == null || (file = sp.file()) == null) {
     return;
   }
   try {
     int lineno = 1;
     String line;
     StringBuffer output = new StringBuffer();
     LineNumberReader reader = new LineNumberReader(new FileReader(file));
     try {
       while ((line = reader.readLine()) != null) {
         output.append(formatLine(line, configuration.sourcetab, lineno));
         lineno++;
       }
     } finally {
       reader.close();
     }
     output = addLineNumbers(output.toString());
     output.insert(0, getHeader());
     output.append(getFooter());
     writeToFile(output.toString(), outputdir, cd.name(), configuration);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }