Examples of LineNumberReader


Examples of java.io.LineNumberReader

    private Profile() {
        FileReader reader = null;
        try {
            reader = new FileReader("profile.txt");
            LineNumberReader r = new LineNumberReader(reader);
            while (r.readLine() != null) {
                // nothing - just count lines
            }
            maxIndex = r.getLineNumber();
            count = new int[maxIndex];
            time = new int[maxIndex];
            lastTime = System.currentTimeMillis();
            Runtime.getRuntime().addShutdownHook(this);
        } catch (Exception e) {
View Full Code Here

Examples of java.io.LineNumberReader

        printLine('-');
        FileReader reader = null;
        FileWriter fileWriter = null;
        try {
            reader = new FileReader("profile.txt");
            LineNumberReader r = new LineNumberReader(reader);
            fileWriter = new FileWriter("notCovered.txt");
            BufferedWriter writer = new BufferedWriter(fileWriter);
            int unvisited = 0;
            int unvisitedThrow = 0;
            for (int i = 0; i < maxIndex; i++) {
                String line = r.readLine();
                if (count[i] == 0) {
                    if (!line.endsWith("throw")) {
                        writer.write(line + "\r\n");
                        if (LIST_UNVISITED) {
                            print(line + "\r\n");
View Full Code Here

Examples of java.io.LineNumberReader

            index[i] = bigIndex;
        }
        FileReader reader = null;
        try {
            reader = new FileReader("profile.txt");
            LineNumberReader r = new LineNumberReader(reader);
            for (int i = 0; i < maxIndex; i++) {
                String line = r.readLine();
                int k = list[i];
                if (k < 0) {
                    k = -(k + 1);
                    list[i] = k;
                    for (int j = 0; j < max; j++) {
View Full Code Here

Examples of java.io.LineNumberReader

        //  attach the render to the parser
        MusicStringIn.addParserListener(MusicXmlOut);
       
        //  read the song from the file
        BufferedReader brSrc = new BufferedReader(new FileReader(fileSrc));
        LineNumberReader lnrSrc = new LineNumberReader(brSrc);
       
        Pattern song = new Pattern();
        for (String s = lnrSrc.readLine(); s != null; s = lnrSrc.readLine())
        {  if (s.length() > 0)
            if (s.charAt(0) != '#')
              song.add(s);
        }
        lnrSrc.close();
       
        //  play the song
//        Player player = new Player();
//        player.play(song);
        System.out.println(song.toString());
View Full Code Here

Examples of java.io.LineNumberReader

            factory.useSchemeSpecificRules("*",true);
            if (i < args.length)
                for (; i < args.length; i++)
                    check(args[i]);
            else {
                LineNumberReader rdr = new LineNumberReader(
                        new InputStreamReader(in));
                while (true) {
                    String line = rdr.readLine();
                    if (line == null)
                        return;
                    check(line);
                }
            }
View Full Code Here

Examples of java.io.LineNumberReader

  /**
   * Read the image from the specified file.
   */
  private void readImage(InputStream is) {
    try {
      LineNumberReader reader = new LineNumberReader(
          new InputStreamReader(is));
      HashMap<String, Integer> colors = new HashMap<String, Integer>();

      format = parseFormat(nextLineOfInterest(reader));

View Full Code Here

Examples of java.io.LineNumberReader

        while (serverSocket != null) {
            Socket socket = null;
            try {
                socket = serverSocket.accept();
                socket.setSoLinger(false, 0);
                LineNumberReader lin = new LineNumberReader(new InputStreamReader(socket.getInputStream()));

                String key = lin.readLine();
                if (!this.key.equals(key)) {
                    continue;
                }
                String cmd = lin.readLine();
                if ("stop".equals(cmd)) {
                    try {
                        socket.close();
                    } catch (Exception e) {
                        LOGGER.debug("Exception when stopping server", e);
View Full Code Here

Examples of java.io.LineNumberReader

     * @param traceFileName
     * @param javaClassName
     * @throws IOException
     */
    private void convertFile(String traceFileName, String javaClassName, String script) throws IOException {
        LineNumberReader reader = new LineNumberReader(IOUtils.getBufferedReader(
                IOUtils.openFileInputStream(traceFileName)));
        PrintWriter javaWriter = new PrintWriter(IOUtils.getBufferedWriter(
                IOUtils.openFileOutputStream(javaClassName + ".java", false)));
        PrintWriter scriptWriter = new PrintWriter(IOUtils.getBufferedWriter(
                IOUtils.openFileOutputStream(script, false)));
        javaWriter.println("import java.io.*;");
        javaWriter.println("import java.sql.*;");
        javaWriter.println("import java.math.*;");
        javaWriter.println("import java.util.Calendar;");
        String cn = javaClassName.replace('\\', '/');
        int idx = cn.lastIndexOf('/');
        if (idx > 0) {
            cn = cn.substring(idx + 1);
        }
        javaWriter.println("public class " + cn + " {");
        javaWriter.println("    public static void main(String... args) throws Exception {");
        javaWriter.println("        Class.forName(\"org.h2.Driver\");");
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            if (line.startsWith("/**/")) {
                line = "        " + line.substring(4);
                javaWriter.println(line);
            } else if (line.startsWith("/*SQL")) {
                int end = line.indexOf("*/");
                String sql = line.substring(end + "*/".length());
                sql = StringUtils.javaDecode(sql);
                line = line.substring("/*SQL".length(), end);
                if (line.length() > 0) {
                    String statement = sql;
                    int count = 0;
                    int time = 0;
                    line = line.trim();
                    if (line.length() > 0) {
                        StringTokenizer tk = new StringTokenizer(line, " :");
                        while (tk.hasMoreElements()) {
                            String token = tk.nextToken();
                            if ("l".equals(token)) {
                                int len = Integer.parseInt(tk.nextToken());
                                statement = sql.substring(0, len) + ";";
                            } else if ("#".equals(token)) {
                                count = Integer.parseInt(tk.nextToken());
                            } else if ("t".equals(token)) {
                                time = Integer.parseInt(tk.nextToken());
                            }
                        }
                    }
                    addToStats(statement, count, time);
                }
                scriptWriter.println(sql);
            }
        }
        javaWriter.println("    }");
        javaWriter.println("}");
        reader.close();
        javaWriter.close();
        if (stats.size() > 0) {
            scriptWriter.println("-----------------------------------------");
            scriptWriter.println("-- SQL Statement Statistics");
            scriptWriter.println("-- time: total time in milliseconds (accumulated)");
View Full Code Here

Examples of java.io.LineNumberReader

    public synchronized void store(String fileName) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        store(out, null);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
        LineNumberReader r = new LineNumberReader(reader);
        Writer w;
        try {
            w = new OutputStreamWriter(IOUtils.openFileOutputStream(fileName, false));
        } catch (Exception e) {
            throw DbException.convertToIOException(e);
        }
        PrintWriter writer = new PrintWriter(new BufferedWriter(w));
        while (true) {
            String line = r.readLine();
            if (line == null) {
                break;
            }
            if (!line.startsWith("#")) {
                writer.print(line + "\n");
View Full Code Here

Examples of java.io.LineNumberReader

    }

    private static void runTests(String fName, String inType) {

        LineNumberReader lnr = null;
        PrintStream pos = null;
        String record = null;
        StringBuffer outStr1 = new StringBuffer();
        StringBuffer outStr2 = new StringBuffer();

        try {

            /*
             * File inFile = new File(fName + ".dat"); File outFile = new
             * File(fName + ".out"); FileInputStream fis = new
             * FileInputStream(inFile); FileOutputStream fos = new
             * FileOutputStream(outFile); BufferedInputStream bis = new
             * BufferedInputStream(fis);
             */
            pos = new PrintStream(new FileOutputStream(new File(fName + ".out")));
            lnr = new LineNumberReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(new File(fName)))));

            if (inType.equalsIgnoreCase("MGRS")) {
                outStr1.append("MGRS to LatLonPoint\n\tMGRS\t\tLatitude   Longitude\n");
                outStr2.append("MGRS to UTM\n\tMGRS\t\tZone Easting Northing\n");
            } else if (inType.equalsIgnoreCase("UTM")) {
                outStr1.append("UTM to LatLonPoint\n\tUTM\t\tLatitude   Longitude\n");
                outStr2.append("UTM to MGRS\n\tUTM\t\tMGRS\n");
            } else if (inType.equalsIgnoreCase("LatLon")) {
                outStr1.append("LatLonPoint to UTM\nLatitude   Longitude\t\tZone Easting Northing     \n");
                outStr2.append("LatLonPoint to MGRS\nLatitude   Longitude\t\tMGRS\n");
            }

            while ((record = lnr.readLine()) != null) {
                if (inType.equalsIgnoreCase("MGRS")) {
                    try {
                        MGRSPoint mgrsp = new MGRSPoint(record);
                        record.trim();
                        mgrsp.decode(record);

                        outStr1.append(record + " is " + mgrsp.toLatLonPoint()
                                + "\n");
                        outStr2.append(record + " to UTM: " + mgrsp.zone_number
                                + " " + mgrsp.easting + " " + mgrsp.northing
                                + "\n");
                    } catch (NumberFormatException nfe) {
                        Debug.error(nfe.getMessage());
                    }

                } else if (inType.equalsIgnoreCase("UTM")) {
                    MGRSPoint mgrsp;
                    UTMPoint utmp;
                    float e, n;
                    int z;
                    char zl;
                    String tmp;
                    record.trim();
                    tmp = record.substring(0, 2);
                    z = Integer.parseInt(tmp);
                    tmp = record.substring(5, 11);
                    e = Float.parseFloat(tmp);
                    tmp = record.substring(12, 19);
                    n = Float.parseFloat(tmp);
                    zl = record.charAt(3);
                    utmp = new UTMPoint(n, e, z, zl);
                    LatLonPoint llp = utmp.toLatLonPoint();
                    mgrsp = LLtoMGRS(llp);
                    outStr1.append(record + " is " + llp + " back to "
                            + LLtoUTM(llp) + "\n");
                    outStr2.append(record + " is " + mgrsp + "\n");
                } else if (inType.equalsIgnoreCase("LatLon")) {
                    float lat, lon;
                    int index;
                    String tmp;
                    record.trim();
                    index = record.indexOf("\040");
                    if (index < 0) {
                        index = record.indexOf("\011");
                    }
                    tmp = record.substring(0, index);
                    lat = Float.parseFloat(tmp);
                    tmp = record.substring(index);
                    lon = Float.parseFloat(tmp);
                    LatLonPoint llp = new LatLonPoint(lat, lon);
                    // UTMPoint utmp = LLtoUTM(llp);
                    MGRSPoint mgrsp = LLtoMGRS(llp);
                    outStr1.append(record + " to UTM: " + mgrsp.zone_number
                            + " " + mgrsp.easting + " " + mgrsp.northing + "\n");
                    outStr2.append(record + "    ->    " + mgrsp.mgrs + "\n");
                }

            }

        } catch (IOException e) {
            // catch io errors from FileInputStream or readLine()
            System.out.println("IO error: " + e.getMessage());

        } finally {
            if (pos != null) {
                pos.print(outStr1.toString());
                pos.print("\n");
                pos.print(outStr2.toString());
                pos.close();
            }
            // if the file opened okay, make sure we close it
            if (lnr != null) {
                try {
                    lnr.close();
                } catch (IOException ioe) {
                }
            }

        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.