There are 8 code examples for java.io.LineNumberReader.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: randoop Package: cov

Source Code: Coverage.java (Click to view .java file)

Method Code:
vote
like

/** 
 * @param clsThe class whose source lines are of interest.
 * @param startLineThe first line of interest. Must be >= 1.
 * @param endLineThe last line of interest. Must be >= startLine. If endLine is
 * greater than the number of lines in the source file, the method
 * returns lines up to the last line in the file.
 * @return Returns null if lineNumber is greater than lines in source file.
 */
public static List<String> getSourceLines(Class<?> cls,int startLine,int endLine){
  if (cls == null)   throw new IllegalArgumentException("cls cannot be null.");
  if (!isInstrumented(cls))   throw new IllegalArgumentException("cls is not coverage-instrumented: " + cls.getName());
  if (startLine <= 0)   throw new IllegalArgumentException("startLine must be >0: " + startLine);
  if (endLine <= 0)   throw new IllegalArgumentException("endLine must be >0: " + endLine);
  if (startLine > endLine)   throw new IllegalArgumentException("startLine must be <= endLine.");
  String sourceFileName=getSourceFileName(cls) + ".orig";
  InputStream fileStream=cls.getResourceAsStream(sourceFileName);
  List<String> lines=new ArrayList<String>();
  try {
    LineNumberReader reader=new LineNumberReader(new InputStreamReader(fileStream));
    String line=reader.readLine();
    while (line != null && reader.getLineNumber() <= endLine) {
      int lineNumber=reader.getLineNumber();
      if (lineNumber >= startLine)       lines.add(line);
      line=reader.readLine();
    }
  }
 catch (  Exception e) {
    throw new RuntimeException("Error in coverage instrumenter: " + e.getMessage());
  }
  return lines;
}
 

Project Name: randoop Package: randoop.instrument

Source Code: Instrument.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Reads the file that specifies method calls that should be replaced
 * by other method calls.  The file is of the form:
 * [regex]
 * [orig-method-def]
 * [new-method-name]
 * where the orig_method-def is of the form:
 * fully-qualified-method-name (args)
 * 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();
}
 

Project Name: randoop Package: randoop.util

Source Code: Files.java (Click to view .java file)

Method Code:
vote
like

public static LineNumberReader getFileReader(File fileName){
  LineNumberReader reader;
  try {
    reader=new LineNumberReader(new BufferedReader(new FileReader(fileName)));
  }
 catch (  FileNotFoundException e1) {
    throw new IllegalStateException("File was not found " + fileName + " "+ e1.getMessage());
  }
  return reader;
}
 

Project Name: weka Package: weka.core.matrix

Source Code: Matrix.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Reads a matrix from a reader. The first line in the file should
 * contain the number of rows and columns. Subsequent lines
 * contain elements of the matrix.
 * (FracPete: taken from old weka.core.Matrix class)
 * @param r the reader containing the matrix
 * @throws Exception if an error occurs
 * @see #write(Writer)
 */
public Matrix(Reader r) throws Exception {
  LineNumberReader lnr=new LineNumberReader(r);
  String line;
  int currentRow=-1;
  while ((line=lnr.readLine()) != null) {
    if (line.startsWith("%"))     continue;
    StringTokenizer st=new StringTokenizer(line);
    if (!st.hasMoreTokens())     continue;
    if (currentRow < 0) {
      int rows=Integer.parseInt(st.nextToken());
      if (!st.hasMoreTokens())       throw new Exception("Line " + lnr.getLineNumber() + ": expected number of columns");
      int cols=Integer.parseInt(st.nextToken());
      A=new double[rows][cols];
      m=rows;
      n=cols;
      currentRow++;
      continue;
    }
 else {
      if (currentRow == getRowDimension())       throw new Exception("Line " + lnr.getLineNumber() + ": too many rows provided");
      for (int i=0; i < getColumnDimension(); i++) {
        if (!st.hasMoreTokens())         throw new Exception("Line " + lnr.getLineNumber() + ": too few matrix elements provided");
        set(currentRow,i,Double.valueOf(st.nextToken()).doubleValue());
      }
      currentRow++;
    }
  }
  if (currentRow == -1)   throw new Exception("Line " + lnr.getLineNumber() + ": expected number of rows");
 else   if (currentRow != getRowDimension())   throw new Exception("Line " + lnr.getLineNumber() + ": too few rows provided");
}
 

Project Name: weka Package: weka.experiment

Source Code: Stats.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Tests the paired stats object from the command line.
 * reads line from stdin, expecting two values per line.
 * @param args ignored.
 */
public static void main(String[] args){
  try {
    Stats ps=new Stats();
    java.io.LineNumberReader r=new java.io.LineNumberReader(new java.io.InputStreamReader(System.in));
    String line;
    while ((line=r.readLine()) != null) {
      line=line.trim();
      if (line.equals("") || line.startsWith("@") || line.startsWith("%")) {
        continue;
      }
      java.util.StringTokenizer s=new java.util.StringTokenizer(line," ,\t\n\r\f");
      int count=0;
      double v1=0;
      while (s.hasMoreTokens()) {
        double val=(new Double(s.nextToken())).doubleValue();
        if (count == 0) {
          v1=val;
        }
 else {
          System.err.println("MSG: Too many values in line \"" + line + "\", skipped.");
          break;
        }
        count++;
      }
      if (count == 1) {
        ps.add(v1);
      }
    }
    ps.calculateDerived();
    System.err.println(ps);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    System.err.println(ex.getMessage());
  }
}
 

Project Name: weka Package: weka.experiment

Source Code: PairedStats.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Tests the paired stats object from the command line.
 * reads line from stdin, expecting two values per line.
 * @param args ignored.
 */
public static void main(String[] args){
  try {
    PairedStats ps=new PairedStats(0.05);
    java.io.LineNumberReader r=new java.io.LineNumberReader(new java.io.InputStreamReader(System.in));
    String line;
    while ((line=r.readLine()) != null) {
      line=line.trim();
      if (line.equals("") || line.startsWith("@") || line.startsWith("%")) {
        continue;
      }
      java.util.StringTokenizer s=new java.util.StringTokenizer(line," ,\t\n\r\f");
      int count=0;
      double v1=0, v2=0;
      while (s.hasMoreTokens()) {
        double val=(new Double(s.nextToken())).doubleValue();
        if (count == 0) {
          v1=val;
        }
 else         if (count == 1) {
          v2=val;
        }
 else {
          System.err.println("MSG: Too many values in line \"" + line + "\", skipped.");
          break;
        }
        count++;
      }
      if (count == 2) {
        ps.add(v1,v2);
      }
    }
    ps.calculateDerived();
    System.err.println(ps);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    System.err.println(ex.getMessage());
  }
}
 

Project Name: weka Package: weka.gui

Source Code: ReaderToTextPane.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Sit here listening for lines of input and appending them straight
 * to the text component.
 */
public void run(){
  while (true) {
    try {
      StyledDocument doc=m_Output.getStyledDocument();
      doc.insertString(doc.getLength(),m_Input.readLine() + '\n',doc.getStyle(getStyleName()));
      m_Output.setCaretPosition(doc.getLength());
    }
 catch (    Exception ex) {
      try {
        sleep(100);
      }
 catch (      Exception e) {
      }
    }
  }
}
 

Project Name: weka Package: weka.gui.beans

Source Code: KnowledgeFlowApp.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Pop up a help window
 */
private void popupHelp(){
  final JButton tempB=m_helpB;
  try {
    tempB.setEnabled(false);
    InputStream inR=this.getClass().getClassLoader().getResourceAsStream("weka/gui/beans/README_KnowledgeFlow");
    StringBuffer helpHolder=new StringBuffer();
    LineNumberReader lnr=new LineNumberReader(new InputStreamReader(inR));
    String line;
    while ((line=lnr.readLine()) != null) {
      helpHolder.append(line + "\n");
    }
    lnr.close();
    final javax.swing.JFrame jf=new javax.swing.JFrame();
    jf.getContentPane().setLayout(new java.awt.BorderLayout());
    final JTextArea ta=new JTextArea(helpHolder.toString());
    ta.setFont(new Font("Monospaced",Font.PLAIN,12));
    ta.setEditable(false);
    final JScrollPane sp=new JScrollPane(ta);
    jf.getContentPane().add(sp,java.awt.BorderLayout.CENTER);
    jf.addWindowListener(new java.awt.event.WindowAdapter(){
      public void windowClosing(      java.awt.event.WindowEvent e){
        tempB.setEnabled(true);
        jf.dispose();
      }
    }
);
    jf.setSize(600,600);
    jf.setVisible(true);
  }
 catch (  Exception ex) {
    tempB.setEnabled(true);
  }
}