Package java.io

Examples of java.io.PrintStream$Static


      BibtexEntry e = t1BibtexEntry();

      XMPUtil.writeXMP(pdfFile, e, null);

      ByteArrayOutputStream s = new ByteArrayOutputStream();
      PrintStream oldOut = System.out;
      System.setOut(new PrintStream(s));
      XMPUtil.main(new String[] { pdfFile.getAbsolutePath() });
      System.setOut(oldOut);
      s.close();
      String bibtex = s.toString();

      ParserResult result = BibtexParser.parse(new StringReader(bibtex));
      Collection<BibtexEntry> c = result.getDatabase().getEntries();
      assertEquals(1, c.size());
      BibtexEntry x = c.iterator().next();

      assertEquals(e, x);
    }
    {
      // Write XMP to file
      BibtexEntry e = t1BibtexEntry();

      XMPUtil.writeXMP(pdfFile, e, null);

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


      fileWriter.write(t2BibtexString());
      fileWriter.close();

      { // First try canh05
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        PrintStream oldOut = System.out;
        System.setOut(new PrintStream(s));
        XMPUtil.main(new String[] { "canh05",
            tempBib.getAbsolutePath(), pdfFile.getAbsolutePath() });
        System.setOut(oldOut);
        s.close();

        // PDF should be annotated:
        List<BibtexEntry> l = XMPUtil.readXMP(pdfFile);
        assertEquals(1, l.size());
        assertEquals(t1BibtexEntry(), l.get(0));
      }
      { // Now try OezbekC06
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        PrintStream oldOut = System.out;
        System.setOut(new PrintStream(s));
        XMPUtil.main(new String[] { "OezbekC06",
            tempBib.getAbsolutePath(), pdfFile.getAbsolutePath() });
        System.setOut(oldOut);
        s.close();
        // PDF should be annotated:
View Full Code Here

      fileWriter.write(t1BibtexString());
      fileWriter.write(t3BibtexString());
      fileWriter.close();

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

    //System.out.println(now.toString() + " ... Start of Grib1Dump");

    // Reading of Grib files must be inside a try-catch block
    calendar = Calendar.getInstance();
    calendar.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    PrintStream ps = System.out;
    try {
      RandomAccessFile raf = null;
      if (args.length == 3) {  // input file, output file, get data for dump
        raf = new RandomAccessFile(args[0], "r");
        ps = new PrintStream(
                new BufferedOutputStream(
                        new FileOutputStream(args[1], false)));
        displayData = args[2].equalsIgnoreCase("true");
      } else if (args.length == 2) {  // input file and output file for dump
        raf = new RandomAccessFile(args[0], "r");
        if (args[1].equalsIgnoreCase("true")
                || args[1].equalsIgnoreCase("false")) {
          displayData = args[1].equalsIgnoreCase("true");
        } else {
          ps = new PrintStream(
                  new BufferedOutputStream(
                          new FileOutputStream(args[1], false)));
        }
      } else if (args.length == 1) {
        raf = new RandomAccessFile(args[0], "r");
      } else {
        System.exit(0);
      }
      // test for a user defined parameter table read
      //GribPDSParamTable.addParameterUserLookup( "/local/robb/trunk20081229/grib/resources/resources/grib/tables/userlookup.lst");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      // Create Grib1Input instance
      Grib1Input g1i = new Grib1Input(raf);
      // boolean params getProducts, oneRecord
      g1i.scan(false, false);
      // record contains objects for all 5 Grib1 sections
      ArrayList records = g1i.getRecords();
      for (int i = 0; i < records.size(); i++) {
        Grib1Record record = (Grib1Record) records.get(i);
        Grib1IndicatorSection is = record.getIs();
        Grib1ProductDefinitionSection pds = record.getPDS();
        Grib1GridDefinitionSection gds = record.getGDS();

        // create dump output here
        ps.println(
                "--------------------------------------------------------------------");
        ps.println("                        Header : "
                + record.getHeader());
        printIS(is, ps);
        printPDS(pds, ps);
        printGDS(gds, pds, ps);
        ps.println();

        if (displayData) {
          float[] data = null;
          ps.println(
                  "--------------------------------------------------------------------");
          Grib1Data gd = new Grib1Data(raf);
          // TODO: pds vars needed
          data = gd.getData(record.getDataOffset(),
                  pds.getDecimalScale(), pds.bmsExists());
          if (data != null) {
            for (int j = 0; j < data.length; j++) {
              ps.println("data[ " + j + " ]=" + data[j]);
            }
          }
          break// only display data for 1st record
        }
      }
      raf.close();    // done reading

      // Catch thrown errors from GribFile
    } catch (FileNotFoundException noFileError) {
      System.err.println("FileNotFoundException : " + noFileError);
    } catch (IOException ioError) {
      System.err.println("IOException : " + ioError);
    } catch (NoValidGribException noGrib) {
      System.err.println("NoValidGribException : " + noGrib);
    } finally {
      ps.close();     // done writing
    }

    // Goodbye message
    now = Calendar.getInstance().getTime();
    //System.out.println(now.toString() + " ... End of Grib1Dump!");
View Full Code Here

    // parent override to render in the pbuffer, not the canvas
    public void renderDebug(RenderFrame frame, String logfile) {

        try {
            debugStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(logfile)));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        debugFrame = true;
View Full Code Here

     * @throws IOException
     */
    private void indentFile(String inputFile, String ouputFile) throws IOException {
        //Just have to open the file.
        fis = new FileInputStream(inputFile);
        out = new PrintStream(new FileOutputStream(ouputFile));
        indentLevel = 0;
        parse();
    }
View Full Code Here

    throws Exception
  {
    // Write the page to a buffer first
    // If an exception should be thrown the user gets a clear error message
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(stream, false, SIMPLE_TAG_ENCODING);

    PageRequest request = new SimplePageRequest(req);
    PageResponse response = new SimplePageResponse(this, req, resp, printStream, SIMPLE_TAG_ENCODING);

    // Add the error to the page attributes
    if (error != null) {
      request.setContextAttribute("page.exception", error);
    }
   
    try {
      executer.execute(request, response);
    }
    catch (RedirectException exc) {
      // Send a redirect
      resp.set("Location", exc.getUrl());
      handle(req, resp, 303);
      return;
    }
    catch (Exception exc) {
      mLog.error("Processing page failed", exc);
      if (error == null) {
        // This is the normal page -> Show the error page
        try {
          Executer errorExecuter = loadErrorPage();
          process(req, resp, errorExecuter, exc);
        }
        catch (RegainException loadingExc) {
          mLog.error("Processing error page failed", loadingExc);
         
          // Throw the original error, so a simple error page is shown
          throw exc;
        }
      } else {
        // This already is the error page -> Show a simple error
        throw exc;
      }
    }
    finally {
      printStream.close();
      stream.close();
    }
   
    // The page has been generated without exception -> Send it to the user
    resp.set("Content-Type", "text/html; charset=" + SIMPLE_TAG_ENCODING);
    PrintStream pageStream = resp.getPrintStream();
    try {
      stream.writeTo(pageStream);
    }
    finally {
      pageStream.close();
    }
  }
View Full Code Here

  {
    FileOutputStream stream = null;
    try {
      stream = new FileOutputStream(xmlFile);
      String encoding = "UTF-8";
      PrintStream out = new PrintStream(stream, true, encoding);
     
      out.println("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>");
      out.println();
      out.println("<!DOCTYPE entities [");
      out.println("  <!ENTITY minus \"&#45;\">");
      out.println("  <!ENTITY lt \"&#60;\">");
      out.println("  <!ENTITY gt \"&#62;\">");
      out.println("]>");
      out.println();
     
      Element root = doc.getDocumentElement();
     
      printNode(out, "", root);

      out.close();
    }
    catch (Exception exc) {
      throw new RegainException("Saving XML file failed: "
                                + xmlFile.getAbsolutePath(), exc);
    }
View Full Code Here

  private void processDirectory(Request req, Response resp, File dir)
    throws Exception
  {
    resp.set("Content-Type", "text/html");
   
    PrintStream out = resp.getPrintStream();
    out.print("<html><head><title>" + dir.getName() + "</title></head><body>");
    String[] childArr = dir.list();
    for (int i = 0; i < childArr.length; i++) {
      out.print("<a href=\"" + childArr[i] + "\">" + childArr[i] + "</a><br>");
    }
    out.print("</body></html>");
    out.close();
  }
View Full Code Here

      // Nothing to do
      return;
    }

    FileOutputStream stream = null;
    PrintStream printer = null;
    try {
      stream = new FileOutputStream(file);
      printer = new PrintStream(stream);

      for (int i = 0; i < wordList.length; i++) {
        printer.println(wordList[i]);
      }
    } catch (IOException exc) {
      throw new RegainException("Writing word list to " + file.getAbsolutePath()
              + " failed", exc);
    } finally {
      if (printer != null) {
        printer.close();
      }
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException exc) {
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.