Package java.io

Examples of java.io.PrintStream


         * Start capturing thread's output.
         */
        public static void setThread() {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            data.set(baos);
            streams.set(new PrintStream(baos));
        }
View Full Code Here


        /**
         * Find PrintStream to which the output must be written to.
         */
        protected PrintStream findStream() {
            PrintStream ps = (PrintStream) streams.get();
            if (ps == null) {
                ps = wrapped;
            }
            return ps;
        }
View Full Code Here

      String[] names = file.list();
      if (names == null) {
        res.sendError(HttpServletResponse.SC_FORBIDDEN, "Can't access " + req.getRequestURI());
        return;
      }
      PrintStream p = new PrintStream(new BufferedOutputStream(out), false, charSet); // 1.4
      p.println("<HTML><HEAD>");
      p.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" + charSet + "\">");
      p.println("<TITLE>Index of " + path + "</TITLE>");
      p.println("</HEAD><BODY " + Serve.BGCOLOR);
      p.println("><H2>Index of " + path + "</H2>");
      p.println("<PRE>");
      p.println("mode         bytes  last-changed    name");
      p.println("<HR>");
      // TODO consider not case sensetive search
      Arrays.sort(names);
      long total = 0;
      for (int i = 0; i < names.length; ++i) {
        File aFile = new File(file, names[i]);
        String aFileType;
        long aFileLen;
        if (aFile.isDirectory())
          aFileType = "d";
        else if (aFile.isFile())
          aFileType = "-";
        else
          aFileType = "?";
        String aFileRead = (aFile.canRead() ? "r" : "-");
        String aFileWrite = (aFile.canWrite() ? "w" : "-");
        String aFileExe = "-";
        if (canExecute != null)
          try {
            if (((Boolean) canExecute.invoke(aFile, Utils.EMPTY_OBJECTS)).booleanValue())
              aFileExe = "x";
          } catch (IllegalArgumentException e) {
          } catch (IllegalAccessException e) {
          } catch (InvocationTargetException e) {
          }
        String aFileSize = lengthftm.format(aFileLen = aFile.length());
        total += (aFileLen + 1023) / 1024; //
        while (aFileSize.length() < 12)
          aFileSize = " " + aFileSize;
        String aFileDate = Acme.Utils.lsDateStr(new Date(aFile.lastModified()));
        while (aFileDate.length() < 14)
          aFileDate += " ";
        String aFileDirsuf = (aFile.isDirectory() ? "/" : "");
        String aFileSuf = (aFile.isDirectory() ? "/" : "");
        p.println(aFileType + aFileRead + aFileWrite + aFileExe + "  " + aFileSize + "  " + aFileDate + "  "
            + "<A HREF=\"" + URLEncoder.encode(names[i], charSet) /* 1.4 */
            + aFileDirsuf + "\">" + names[i] + aFileSuf + "</A>");
      }
      if (total != 0)
        total += 3;
      p.println("total " + total);
      p.println("</PRE>");
      p.println("<HR>");
      p.print(Serve.Identification.serverIdHtml);
      p.println("</BODY></HTML>");
      p.flush();
    }
    out.close();
  }
View Full Code Here

        response.server = server;
        response.port = port;

        Socket connection = AsyncSocketFactory.createSocket(server, port, timeout);
        try {
            PrintStream out = new PrintStream(connection.getOutputStream());
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                try {
                    out.println(query);
                    StringBuffer sb = new StringBuffer();

                    String line;
                    while ((line = in.readLine()) != null) {
                        sb.append(line).append(lineSeparator);
                        line = line.trim();
                        if (! line.startsWith("%") && ! line.startsWith("#")) {
                            int fs = line.indexOf(":");
                            if (fs > 0) {
                                String name = line.substring(0, fs);
                                String value = line.substring(fs + 1).trim();
                                response.data.put(name, value);
                            }
                        }
                    }
                    response.summary = sb.toString();

                    Response newResponse = null;
                    String referral = (String) response.getData().get("ReferralServer");

                    if (referral != null) {
                        try {
                            URLParser url = new URLParser(referral);
                            if ("whois".equals(url.getProtocol())) {
                                newResponse = lookup(url.getHost(), url.getPort() == -1 ? 43 : url.getPort(), query,
                                        timeout, lineSeparator);
                            }
                        } catch (IOException e) {
                            System.out.println("Could not contact " + referral);
                        }
                    }
                    if (newResponse != null) {
                        response = newResponse;
                    }
                } finally {
                    in.close();
                }
            } finally {
                out.close();
            }
        } finally {
            connection.close();
        }
View Full Code Here

    }

    private void testConsole() throws Exception {
        String old = System.getProperty(SysProperties.H2_BROWSER);
        Console c = new Console();
        c.setOut(new PrintStream(new ByteArrayOutputStream()));
        try {

            // start including browser
            lastUrl = "-";
            System.setProperty(SysProperties.H2_BROWSER, "call:" + TestTools.class.getName() + ".openBrowser");
View Full Code Here

                getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
    }

    private String runServer(int exitCode, String... args) {
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(buff);
        server = new Server();
        server.setOut(ps);
        int result = 0;
        try {
            server.runTool(args);
        } catch (SQLException e) {
            result = 1;
            e.printStackTrace(ps);
        }
        assertEquals(exitCode, result);
        ps.flush();
        String s = new String(buff.toByteArray());
        return s;
    }
View Full Code Here

        conn.close();

        DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
        RunScript tool = new RunScript();
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        tool.setOut(new PrintStream(buff));
        tool.runTool("-url", url, "-user", user, "-password", password, "-script", fileName + ".txt",
                "-showResults");
        assertTrue(buff.toString().indexOf("Hello") >= 0);
    }
View Full Code Here

      BasicLevel.DEBUG = 200;

      level = BasicLevel.WARN;

      try {
        out = new PrintStream(new FileOutputStream("joram.log"), true);
      } catch (FileNotFoundException exc) {
        exc.printStackTrace();
        out = System.err;
      }
    }
View Full Code Here

    }

    private void testApp(String expected, Class<?> clazz, String... args) throws Exception {
        DeleteDbFiles.execute("data", "test", true);
        Method m = clazz.getMethod("main", String[].class);
        PrintStream oldOut = System.out, oldErr = System.err;
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(buff, false, "UTF-8");
        System.setOut(out);
        System.setErr(out);
        try {
            m.invoke(null, new Object[] { args });
        } catch (InvocationTargetException e) {
            TestBase.logError("error", e.getTargetException());
        } catch (Throwable e) {
            TestBase.logError("error", e);
        }
        out.flush();
        System.setOut(oldOut);
        System.setErr(oldErr);
        String s = new String(buff.toByteArray(), "UTF-8");
        s = StringUtils.replaceAll(s, "\r\n", "\n");
        s = s.trim();
View Full Code Here

        stat.execute("create index idx_e_id on e(id)");
        conn.close();

        Recover rec = new Recover();
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        rec.setOut(new PrintStream(buff));
        rec.runTool("-dir", getBaseDir(), "-db", "recovery", "-trace");
        String out = new String(buff.toByteArray());
        assertTrue(out.indexOf("Created file") >= 0);

        Connection conn2 = getConnection("recovery2");
View Full Code Here

TOP

Related Classes of java.io.PrintStream

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.