Package java.io

Examples of java.io.PrintStream$Static


    }

    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();
View Full Code Here


      PrintStream stream, out;
      String[] food;

      public OutputStreamFeeder(OutputStream stream, PrintStream out, String[] food)
      {
         this.stream = new PrintStream(stream);
         this.food = food;
         this.out = out;
         setDaemon(true);
      }
View Full Code Here

    public void run()
    {
      try {
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(_input));
        PrintStream out = new PrintStream(_output);
        out.println("** Anvil "+anvil.Version.getFullVersion());
        out.println("** Copyright (c) 1999-2002, Njet Communications ltd. All rights reserved.");
        out.println("** Type 'help' for help");
       
        _self = _server;
       
        while(true) {
          if (out.checkError()) {
            break;
          }
          out.print(prompt(_self));
          String line = reader.readLine();
          if (line == null) {
            break;
          }
          try {
View Full Code Here

      return;
    }
    try {
      _socket = new Socket(_address, _port);
      _input = new GenericInputStream(_socket.getInputStream());
      _output = new PrintStream(new BufferedOutputStream(_socket.getOutputStream()));
    } catch (IOException e) {
      closeConnection();
      throw new RuntimeException("Couldn't establish connection to remote session container: "+e);
    }
  }
View Full Code Here

  public void write(File config, Configurable conf) throws IOException
  {
    FileOutputStream out = null;
    try {
      out = new FileOutputStream(config);
      doWrite(new PrintStream(out), conf, new StringBuffer());
      out.close();
    } finally {
      if (out != null) {
        try {
          out.close();
View Full Code Here

     * as being in the roads vector.
     */
    protected void checkIntegrity() {
        // CharArrayWriter errorWriter = new CharArrayWriter();
        // PrintWriter errors = new PrintWriter(errorWriter);
        PrintStream errors = System.err;
        Hashtable otherIntersections = new Hashtable();
        Object bothIntersections = new Object();
        Object inRoadsVector = new Object();
        for (Enumeration e = intersections.elements(); e.hasMoreElements();) {
            Intersection intersection = (Intersection) e.nextElement();
            int nRoads = intersection.getRoadCount();
            if (nRoads == 0) {
                errors.println("Dangling intersection");
                errors.println("  Intersection = " + intersection);
                continue;
            }
            for (int i = 0; i < nRoads; i++) {
                Road road = intersection.getRoad(i);
                Object other = otherIntersections.get(road);
                if (other == null) {
                    otherIntersections.put(road,
                            road.getOtherIntersection(intersection));
                } else if (other == intersection) {
                    otherIntersections.put(road, bothIntersections);
                } else {
                    errors.println("Misconnected");
                    errors.println("          Road = " + road);
                    errors.println("    Road.Other = " + other);
                    errors.println("  Intersection = " + intersection);
                }
            }
        }

        for (Enumeration e = roads.elements(); e.hasMoreElements();) {
            Road road = (Road) e.nextElement();
            Object other = otherIntersections.get(road);
            if (other == null) {
                errors.println("Road not found in intersections");
                errors.println("          Road = " + road);
            } else if (other != bothIntersections) {
                errors.println("Road incompletely connected");
                errors.println("          Road = " + road);
                errors.println("    Road.Other = " + other);
            } else if (other == inRoadsVector) {
                errors.println("Road doubly listed");
                errors.println("          Road = " + road);
            }
            otherIntersections.put(road, inRoadsVector);
        }
        for (Enumeration e = otherIntersections.keys(); e.hasMoreElements();) {
            Road road = (Road) e.nextElement();
            Object other = otherIntersections.get(road);
            if (other != inRoadsVector) {
                errors.println("Road not listed");
                errors.println("          Road = " + road);
            }
        }
        // String errString = errorWriter.toString();
        // if (errString.equals(""))
        // return;
View Full Code Here

    * @return The Stack trace as a String.
    */
   public static String getStackTraceAsString(Throwable ex) {
      // this is just to send the stack trace to the log file (stderr does not go there)
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PrintStream pstr = new PrintStream(baos);
      if (ex == null)
         ex = new Exception();
      ex.printStackTrace(pstr);
      return new String(baos.toByteArray());
   }
View Full Code Here

    public void testMockConsoleOutputToConsoleWithException()
        throws Exception
    {
        final ByteArrayOutputStream arrayOutput = new ByteArrayOutputStream();
        final PrintStream output = new PrintStream( arrayOutput );
        final ConsoleLogger logger = new ConsoleLogger( MockConsoleLogger.LEVEL_ALL, output );
        logger.debug( "ignore me!", new Throwable( "Ignore me aswell!" ) );
        final String message = arrayOutput.toString();
        final String expectedMessage =
            "[DEBUG] ignore me!" + System.getProperty( "line.separator" );
View Full Code Here

     * @return The exit status of the target process.
     */

    private int waitForImpl() throws InterruptedException {
    in = new StreamPrinter( processInput,
          new PrintStream( process.getOutputStream() ) );
    in.setFlush( true );
    out = new StreamPrinter( process.getInputStream(), yourOutput );
    error = new StreamPrinter( process.getErrorStream(), yourError );
    in.start();
    out.start();
View Full Code Here

      fileWriter = new FileWriter(tempBib);
      fileWriter.write(t1BibtexString());
      fileWriter.close();

      ByteArrayOutputStream s = new ByteArrayOutputStream();
      PrintStream oldOut = System.out;
      System.setOut(new PrintStream(s));
      XMPUtil.main(new String[] { tempBib.getAbsolutePath() });
      System.setOut(oldOut);
      s.close();
      String xmp = s.toString();
View Full Code Here

TOP

Related Classes of java.io.PrintStream$Static

Copyright © 2018 www.massapicom. 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.