Example usage for java.io PrintStream print

List of usage examples for java.io PrintStream print

Introduction

In this page you can find the example usage for java.io PrintStream print.

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:com.github.nukesparrow.htmlunit.DebuggingWebConnection.java

public void writeHtml(PrintStream out) {
    int i = TEMPLATE.indexOf(TEMPLATE_MARK);

    if (i == -1) {
        throw new IllegalStateException();
    }/*from ww w  .j a  va  2s  .  c  o m*/

    out.print(TEMPLATE.substring(0, i));

    for (final Object element : events.toArray()) {
        synchronized (element) {
            String content = JSONValue.toJSONString(element);
            String encoding = null;

            String cc = content.toLowerCase();
            if (cc.contains("</script>") || cc.contains("<!--")) {
                encoding = "base64";
                try {
                    content = Base64.encodeBase64String(content.getBytes("UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    throw new RuntimeException(ex);
                }
            }

            out.append("<script type=\"text/x-event-json\""
                    + (encoding == null ? "" : " encoding=\"" + encoding + "\"") + ">" + content
                    + "</script>\n");
        }
    }

    out.print(TEMPLATE.substring(i + TEMPLATE_MARK.length()));
}

From source file:org.apache.maven.dotnet.UnPackMojo.java

/**
 * Launches the MOJO action. <br/>
 * This method downloads pom.xml and packages dependencies and build AssemblySearchPaths file
 * /*from w  w w  .  ja v  a  2s  .  c o m*/
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    dllDirs.clear();

    if (StringUtils.isEmpty(unPackRoot)) {
        unPackRoot = localRepository.getBasedir() + File.separator + DOTNET_DIR_NAME + File.separator
                + LOCAL_DIR_NAME;
    }

    if (offset == null) {
        offset = "";
    }

    Iterator<Artifact> it = this.project.getArtifacts().iterator();
    while (it.hasNext()) {
        Artifact artifact = it.next();

        File packagePath = new File(unPackRoot + File.separator + localRepository.pathOf(artifact));
        if (!packagePath.getParentFile().exists()) {
            unZipPackage(artifact, localRepository.pathOf(artifact));
        } else {
            getLog().info("UpToDate " + packagePath.getParentFile().getPath());

            WatchedDirectoryWalkListener watchedDirectoryWalkListener = new WatchedDirectoryWalkListener(
                    dllDirs, offset);

            DirectoryWalker dw = new DirectoryWalker();
            dw.setBaseDir(new File(packagePath.getParentFile().getPath()));
            dw.addDirectoryWalkListener(watchedDirectoryWalkListener);

            try {
                dw.scan();
            } catch (IllegalStateException e) {
                throw new MojoExecutionException(packagePath.getParentFile().getPath() + " : " + e.getMessage(),
                        e);
            }
        }
    }

    if (csprojvars != null) {
        getLog().info("writing variables into file " + csprojvars);

        ByteArrayOutputStream baOut = new ByteArrayOutputStream();
        PrintStream psOut = new PrintStream(baOut);

        psOut.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        psOut.println(
                "  <Project ToolsVersion=\"3.5\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
        psOut.println("  <!-- Generated by DOTNET PLUGIN !-->");
        psOut.println("  <PropertyGroup>");
        psOut.println("  <AssemblySearchPaths>");
        psOut.print("  $(AssemblySearchPaths)");

        Iterator<String> iter = dllDirs.iterator();
        while (iter.hasNext()) {
            psOut.println(";");
            psOut.print("  " + iter.next());
        }
        psOut.println("");
        psOut.println("  </AssemblySearchPaths>");
        psOut.println("  </PropertyGroup>");
        psOut.println("</Project>");

        FileOutputStream fileOutputStreamOrder = null;
        try {
            fileOutputStreamOrder = new FileOutputStream(new File(csprojvars));
            fileOutputStreamOrder.write(baOut.toByteArray());
        } catch (FileNotFoundException e) {
            throw new MojoExecutionException("Troubles during writing variables", e);
        } catch (IOException e) {
            throw new MojoExecutionException("Troubles during writing variables", e);
        } finally {
            if (fileOutputStreamOrder != null) {
                try {
                    fileOutputStreamOrder.close();
                } catch (IOException e) {
                    getLog().info(e);
                }
            }
        }
    }
}

From source file:com.bigdata.dastor.tools.DastorAdminCli.java

public void printThreadPoolStats(PrintStream outs) {
    outs.print(String.format("%-25s", "Pool Name"));
    outs.print(String.format("%10s", "Active"));
    outs.print(String.format("%10s", "Pending"));
    outs.print(String.format("%15s", "Completed"));
    outs.println();//from ww  w . j av  a 2s. c o m

    Iterator<Map.Entry<String, IExecutorMBean>> threads = probe.getThreadPoolMBeanProxies();

    for (; threads.hasNext();) {
        Map.Entry<String, IExecutorMBean> thread = threads.next();
        String poolName = thread.getKey();
        IExecutorMBean threadPoolProxy = thread.getValue();
        outs.print(String.format("%-25s", poolName));
        outs.print(String.format("%10d", threadPoolProxy.getActiveCount()));
        outs.print(String.format("%10d", threadPoolProxy.getPendingTasks()));
        outs.print(String.format("%15d", threadPoolProxy.getCompletedTasks()));
        outs.println();
    }
}

From source file:edu.illinois.cs.cogcomp.core.datastructures.Lexicon.java

public void writeIntegerToFeatureStringFormat(PrintStream out) throws IOException {
    if (null == this.featureNames)
        throw new IllegalStateException("Error: Lexicon has not been configured to store feature names.");

    TreeMap<Integer, String> idToFeat = new TreeMap();

    for (String feat : this.featureNames) {
        int id = lookupId(feat);
        idToFeat.put(id, feat);/*  ww w.  ja va  2  s  .c om*/
    }

    for (Integer id : idToFeat.keySet()) {
        out.print(id);
        out.print("\t");
        out.print(idToFeat.get(id));
    }
    out.flush();
}

From source file:org.apache.jackrabbit.jcr2spi.ItemManagerImpl.java

/**
 * @see Dumpable#dump(PrintStream)/*from  ww  w  .j ava2s. c o  m*/
 */
public void dump(PrintStream ps) {
    ps.println("ItemManager (" + this + ")");
    ps.println();
    ps.println("Items in cache:");
    ps.println();
    Iterator iter = itemCache.keySet().iterator();
    while (iter.hasNext()) {
        ItemState state = (ItemState) iter.next();
        Item item = (Item) itemCache.get(state);
        if (item.isNode()) {
            ps.print("Node: ");
        } else {
            ps.print("Property: ");
        }
        if (item.isNew()) {
            ps.print("new ");
        } else if (item.isModified()) {
            ps.print("modified ");
        } else {
            ps.print("- ");
        }
        ps.println(state + "\t" + LogUtil.safeGetJCRPath(state, session.getPathResolver()) + " (" + item + ")");
    }
}

From source file:de.juwimm.cms.model.EditionHbmDaoImpl.java

@Override
protected void handleSiteToXml(Integer siteId, PrintStream out, EditionHbm edition) throws Exception {
    try {/*from  w  ww.java  2s  .  com*/
        SiteHbm site = getSiteHbmDao().load(siteId);
        out.print(site.toXML(0));
    } catch (Exception exe) {
        log.error("Error occured", exe);
    }
}

From source file:com.gemstone.gemfire.test.dunit.standalone.ProcessManager.java

private void linkStreams(final int vmNum, final ProcessHolder holder, final InputStream in,
        final PrintStream out) {
    Thread ioTransport = new Thread() {
        public void run() {
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String vmName = (vmNum == -2) ? "[locator]" : "[vm_" + vmNum + "]";
            try {
                String line = reader.readLine();
                while (line != null) {
                    if (line.length() == 0) {
                        out.println();// ww w  .  ja  v a  2 s  .c  o  m
                    } else {
                        out.print(vmName);
                        out.println(line);
                    }
                    line = reader.readLine();
                }
            } catch (Exception e) {
                if (!holder.isKilled()) {
                    out.println("Error transporting IO from child process");
                    e.printStackTrace(out);
                }
            }
        }
    };

    ioTransport.setDaemon(true);
    ioTransport.start();
}

From source file:org.exjello.mail.Exchange2003Connection.java

public static Exchange2003Connection createConnection(String protocol, Session session, String host, int port,
        String username, String password) throws Exception {
    String prefix = "mail." + protocol.toLowerCase() + ".";
    boolean debugPassword = Boolean.parseBoolean(session.getProperty(DEBUG_PASSWORD_PROPERTY));
    String pwd = (password == null) ? null : debugPassword ? password : "<password>";
    if (host == null || username == null || password == null) {
        if (session.getDebug()) {
            session.getDebugOut().println("Missing parameter; host=\"" + host + "\",username=\"" + username
                    + "\",password=\"" + pwd + "\"");
        }/* w  ww  . j a va 2s.co  m*/
        throw new IllegalStateException("Host, username, and password must be specified.");
    }
    boolean unfiltered = Boolean.parseBoolean(session.getProperty(UNFILTERED_PROPERTY));
    /* Mirco */
    String filterLastCheck = session.getProperty(ExchangeConstants.FILTER_LAST_CHECK);
    String filterFrom = session.getProperty(ExchangeConstants.FILTER_FROM_PROPERTY);
    String filterNotFrom = session.getProperty(ExchangeConstants.FILTER_NOT_FROM_PROPERTY);
    String filterTo = session.getProperty(ExchangeConstants.FILTER_TO_PROPERTY);
    boolean delete = Boolean.parseBoolean(session.getProperty(DELETE_PROPERTY));
    boolean secure = Boolean.parseBoolean(session.getProperty(prefix + SSL_PROPERTY));
    int limit = -1;
    String limitString = session.getProperty(LIMIT_PROPERTY);
    if (limitString != null) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid limit specified: " + limitString);
        }
    }
    try {
        URL url = new URL(host);
        // if parsing succeeded, then strip out the components and use
        secure = "https".equalsIgnoreCase(url.getProtocol());
        host = url.getHost();
        int specifiedPort = url.getPort();
        if (specifiedPort != -1)
            port = specifiedPort;
    } catch (MalformedURLException ex) {
        if (session.getDebug()) {
            session.getDebugOut().println("Not parsing " + host + " as a URL; using explicit options for "
                    + "secure, host, and port.");
        }
    }
    if (port == -1) {
        try {
            port = Integer.parseInt(session.getProperty(prefix + PORT_PROPERTY));
        } catch (Exception ignore) {
        }
        if (port == -1)
            port = secure ? HTTPS_PORT : HTTP_PORT;
    }
    String server = (secure ? "https://" : "http://") + host;
    if (secure ? (port != HTTPS_PORT) : (port != HTTP_PORT)) {
        server += ":" + port;
    }
    String mailbox = session.getProperty(MAILBOX_PROPERTY);
    if (mailbox == null) {
        mailbox = session.getProperty(prefix + FROM_PROPERTY);
        if (mailbox == null) {
            mailbox = InternetAddress.getLocalAddress(session).getAddress();
        }
    }

    int index = username.indexOf(':');
    if (index != -1) {
        mailbox = username.substring(index + 1);
        username = username.substring(0, index);
        String mailboxOptions = null;
        index = mailbox.indexOf('[');
        if (index != -1) {
            mailboxOptions = mailbox.substring(index + 1);
            mailboxOptions = mailboxOptions.substring(0, mailboxOptions.indexOf(']'));
            mailbox = mailbox.substring(0, index);
        }
        if (mailboxOptions != null) {
            Properties props = null;
            try {
                props = parseOptions(mailboxOptions);
            } catch (Exception ex) {
                throw new IllegalArgumentException("Unable to parse mailbox options: " + ex.getMessage(), ex);
            }
            String value = props.getProperty("unfiltered");
            if (value != null)
                unfiltered = Boolean.parseBoolean(value);

            /* Mirco */
            value = props.getProperty("filterLastCheck");
            if (value != null)
                filterLastCheck = value;
            value = props.getProperty("filterTo");
            if (value != null)
                filterTo = value;
            value = props.getProperty("filterFrom");
            if (value != null)
                filterFrom = value;
            value = props.getProperty("filterNotFrom");
            if (value != null)
                filterNotFrom = value;

            value = props.getProperty("delete");
            if (value != null)
                delete = Boolean.parseBoolean(value);
            value = props.getProperty("limit");
            if (value != null) {
                try {
                    limit = Integer.parseInt(value);
                } catch (NumberFormatException ex) {
                    throw new NumberFormatException("Invalid limit specified: " + value);
                }
            }
        } else if (session.getDebug()) {
            session.getDebugOut().println(
                    "No mailbox options specified; " + "using explicit limit, unfiltered, and delete.");
        }
    } else if (session.getDebug()) {
        session.getDebugOut().println("No mailbox specified in username; "
                + "using explicit mailbox, limit, unfiltered, and delete.");
    }
    int timeout = -1;
    String timeoutString = session.getProperty(prefix + TIMEOUT_PROPERTY);
    if (timeoutString != null) {
        try {
            timeout = Integer.parseInt(timeoutString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid timeout value: " + timeoutString);
        }
    }
    int connectionTimeout = -1;
    timeoutString = session.getProperty(prefix + CONNECTION_TIMEOUT_PROPERTY);
    if (timeoutString != null) {
        try {
            connectionTimeout = Integer.parseInt(timeoutString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid connection timeout value: " + timeoutString);
        }
    }
    InetAddress localAddress = null;
    String localAddressString = session.getProperty(prefix + LOCAL_ADDRESS_PROPERTY);
    if (localAddressString != null) {
        try {
            localAddress = InetAddress.getByName(localAddressString);
        } catch (Exception ex) {
            throw new UnknownHostException("Invalid local address specified: " + localAddressString);
        }
    }
    if (mailbox == null) {
        throw new IllegalStateException("No mailbox specified.");
    }
    if (session.getDebug()) {
        PrintStream debugStream = session.getDebugOut();
        debugStream.println("Server:\t" + server);
        debugStream.println("Username:\t" + username);
        debugStream.println("Password:\t" + pwd);
        debugStream.println("Mailbox:\t" + mailbox);
        debugStream.print("Options:\t");
        debugStream.print((limit > 0) ? "Message Limit = " + limit : "Unlimited Messages");
        debugStream.print(unfiltered ? "; Unfiltered" : "; Filtered to Unread");
        debugStream.print(filterLastCheck == null || "".equals(filterLastCheck) ? "; NO filterLastCheck"
                : "; Filtered after " + filterLastCheck);
        debugStream.print(filterFrom == null || "".equals(filterFrom) ? "; NO filterFromDomain"
                : "; Filtered from " + filterFrom);
        debugStream.print(filterNotFrom == null || "".equals(filterNotFrom) ? "; NO filterNotFrom"
                : "; Filtered not from " + filterNotFrom);
        debugStream.print(
                filterTo == null || "".equals(filterTo) ? "; NO filterToEmail" : "; Filtered to " + filterTo);
        debugStream.println(delete ? "; Delete Messages on Delete" : "; Mark as Read on Delete");
        if (timeout > 0) {
            debugStream.println("Read timeout:\t" + timeout + " ms");
        }
        if (connectionTimeout > 0) {
            debugStream.println("Connection timeout:\t" + connectionTimeout + " ms");
        }
    }
    return new Exchange2003Connection(session, server, mailbox, username, password, timeout, connectionTimeout,
            localAddress, unfiltered, delete, limit, filterLastCheck, filterFrom, filterNotFrom, filterTo);
}

From source file:org.exjello.mail.ExchangeConnection.java

public static ExchangeConnection createConnection(String protocol, Session session, String host, int port,
        String username, String password) throws Exception {
    String prefix = "mail." + protocol.toLowerCase() + ".";
    boolean debugPassword = Boolean.parseBoolean(session.getProperty(DEBUG_PASSWORD_PROPERTY));
    String pwd = (password == null) ? null : debugPassword ? password : "<password>";
    if (host == null || username == null || password == null) {
        if (session.getDebug()) {
            session.getDebugOut().println("Missing parameter; host=\"" + host + "\",username=\"" + username
                    + "\",password=\"" + pwd + "\"");
        }//from   w  w  w . ja va  2s . c o  m
        throw new IllegalStateException("Host, username, and password must be specified.");
    }
    boolean unfiltered = Boolean.parseBoolean(session.getProperty(UNFILTERED_PROPERTY));
    /* Mirco */
    String filterLastCheck = session.getProperty(ExchangeConstants.FILTER_LAST_CHECK);
    String filterFrom = session.getProperty(ExchangeConstants.FILTER_FROM_PROPERTY);
    String filterNotFrom = session.getProperty(ExchangeConstants.FILTER_NOT_FROM_PROPERTY);
    String filterTo = session.getProperty(ExchangeConstants.FILTER_TO_PROPERTY);
    boolean delete = Boolean.parseBoolean(session.getProperty(DELETE_PROPERTY));
    boolean secure = Boolean.parseBoolean(session.getProperty(prefix + SSL_PROPERTY));
    int limit = -1;
    String limitString = session.getProperty(LIMIT_PROPERTY);
    if (limitString != null) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid limit specified: " + limitString);
        }
    }
    try {
        URL url = new URL(host);
        // if parsing succeeded, then strip out the components and use
        secure = "https".equalsIgnoreCase(url.getProtocol());
        host = url.getHost();
        int specifiedPort = url.getPort();
        if (specifiedPort != -1)
            port = specifiedPort;
    } catch (MalformedURLException ex) {
        if (session.getDebug()) {
            session.getDebugOut().println("Not parsing " + host + " as a URL; using explicit options for "
                    + "secure, host, and port.");
        }
    }
    if (port == -1) {
        try {
            port = Integer.parseInt(session.getProperty(prefix + PORT_PROPERTY));
        } catch (Exception ignore) {
        }
        if (port == -1)
            port = secure ? HTTPS_PORT : HTTP_PORT;
    }
    String server = (secure ? "https://" : "http://") + host;
    if (secure ? (port != HTTPS_PORT) : (port != HTTP_PORT)) {
        server += ":" + port;
    }
    String mailbox = session.getProperty(MAILBOX_PROPERTY);
    if (mailbox == null) {
        mailbox = session.getProperty(prefix + FROM_PROPERTY);
        if (mailbox == null) {
            mailbox = InternetAddress.getLocalAddress(session).getAddress();
        }
    }

    int index = username.indexOf(':');
    if (index != -1) {
        mailbox = username.substring(index + 1);
        username = username.substring(0, index);
        String mailboxOptions = null;
        index = mailbox.indexOf('[');
        if (index != -1) {
            mailboxOptions = mailbox.substring(index + 1);
            mailboxOptions = mailboxOptions.substring(0, mailboxOptions.indexOf(']'));
            mailbox = mailbox.substring(0, index);
        }
        if (mailboxOptions != null) {
            Properties props = null;
            try {
                props = parseOptions(mailboxOptions);
            } catch (Exception ex) {
                throw new IllegalArgumentException("Unable to parse mailbox options: " + ex.getMessage(), ex);
            }
            String value = props.getProperty("unfiltered");
            if (value != null)
                unfiltered = Boolean.parseBoolean(value);

            /* Mirco */
            value = props.getProperty("filterLastCheck");
            if (value != null)
                filterLastCheck = value;
            value = props.getProperty("filterTo");
            if (value != null)
                filterTo = value;
            value = props.getProperty("filterFrom");
            if (value != null)
                filterFrom = value;
            value = props.getProperty("filterNotFrom");
            if (value != null)
                filterNotFrom = value;

            value = props.getProperty("delete");
            if (value != null)
                delete = Boolean.parseBoolean(value);
            value = props.getProperty("limit");
            if (value != null) {
                try {
                    limit = Integer.parseInt(value);
                } catch (NumberFormatException ex) {
                    throw new NumberFormatException("Invalid limit specified: " + value);
                }
            }
        } else if (session.getDebug()) {
            session.getDebugOut().println(
                    "No mailbox options specified; " + "using explicit limit, unfiltered, and delete.");
        }
    } else if (session.getDebug()) {
        session.getDebugOut().println("No mailbox specified in username; "
                + "using explicit mailbox, limit, unfiltered, and delete.");
    }
    int timeout = -1;
    String timeoutString = session.getProperty(prefix + TIMEOUT_PROPERTY);
    if (timeoutString != null) {
        try {
            timeout = Integer.parseInt(timeoutString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid timeout value: " + timeoutString);
        }
    }
    int connectionTimeout = -1;
    timeoutString = session.getProperty(prefix + CONNECTION_TIMEOUT_PROPERTY);
    if (timeoutString != null) {
        try {
            connectionTimeout = Integer.parseInt(timeoutString);
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Invalid connection timeout value: " + timeoutString);
        }
    }
    InetAddress localAddress = null;
    String localAddressString = session.getProperty(prefix + LOCAL_ADDRESS_PROPERTY);
    if (localAddressString != null) {
        try {
            localAddress = InetAddress.getByName(localAddressString);
        } catch (Exception ex) {
            throw new UnknownHostException("Invalid local address specified: " + localAddressString);
        }
    }
    if (mailbox == null) {
        throw new IllegalStateException("No mailbox specified.");
    }
    if (session.getDebug()) {
        PrintStream debugStream = session.getDebugOut();
        debugStream.println("Server:\t" + server);
        debugStream.println("Username:\t" + username);
        debugStream.println("Password:\t" + pwd);
        debugStream.println("Mailbox:\t" + mailbox);
        debugStream.print("Options:\t");
        debugStream.print((limit > 0) ? "Message Limit = " + limit : "Unlimited Messages");
        debugStream.print(unfiltered ? "; Unfiltered" : "; Filtered to Unread");
        debugStream.print(filterLastCheck == null || "".equals(filterLastCheck) ? "; NO filterLastCheck"
                : "; Filtered after " + filterLastCheck);
        debugStream.print(filterFrom == null || "".equals(filterFrom) ? "; NO filterFromDomain"
                : "; Filtered from " + filterFrom);
        debugStream.print(filterNotFrom == null || "".equals(filterNotFrom) ? "; NO filterNotFrom"
                : "; Filtered not from " + filterNotFrom);
        debugStream.print(
                filterTo == null || "".equals(filterTo) ? "; NO filterToEmail" : "; Filtered to " + filterTo);
        debugStream.println(delete ? "; Delete Messages on Delete" : "; Mark as Read on Delete");
        if (timeout > 0) {
            debugStream.println("Read timeout:\t" + timeout + " ms");
        }
        if (connectionTimeout > 0) {
            debugStream.println("Connection timeout:\t" + connectionTimeout + " ms");
        }
    }
    return new ExchangeConnection(session, server, mailbox, username, password, timeout, connectionTimeout,
            localAddress, unfiltered, delete, limit, filterLastCheck, filterFrom, filterNotFrom, filterTo);
}

From source file:org.apache.ode.jacob.vpu.ExecutionQueueImpl.java

public void dumpState(PrintStream ps) {
    ps.print(this.toString());
    ps.println(" state dump:");
    ps.println("-- GENERAL INFO");
    ps.println("   Current Cycle          : " + _currentCycle);
    ps.println("   Num. Reactions  : " + _reactions.size());
    _statistics.printStatistics(ps);//w  w  w  .j  av a2  s .  co m
    if (!_reactions.isEmpty()) {
        ps.println("-- REACTIONS");
        int cnt = 0;
        for (Iterator i = _reactions.iterator(); i.hasNext();) {
            Continuation continuation = (Continuation) i.next();
            ps.println("   #" + (++cnt) + ":  " + continuation.toString());
        }
    }
}