Example usage for java.io PrintStream println

List of usage examples for java.io PrintStream println

Introduction

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

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminate the line.

Usage

From source file:it.unipr.ce.dsg.s2p.peer.PeerListManager.java

/**
 * Write list to OutputStream (es. file). The format is JSON.
 * //from ww w  . ja  v  a  2s. com
 * @param ostream OutputStream
 * @return boolean return true if the OutputStream has been write
 */
synchronized public boolean writeList(OutputStream ostream) {

    try {
        JSONObject peerList = new JSONObject(this);

        //File newFile = new File(filePath+"cachelist.json");
        PrintStream printList = new PrintStream(ostream);
        printList.println(peerList.toString());
        printList.close();

    } catch (Exception e) {
        new RuntimeException(e);
        return false;
    }

    return true;
}

From source file:jp.ikedam.jenkins.plugins.viewcopy_builder.SetRegexOperation.java

/**
 * @param doc//from   w  w  w  .j ava2s  .c o  m
 * @param env
 * @param logger
 * @return
 * @see jp.ikedam.jenkins.plugins.viewcopy_builder.ViewcopyOperation#perform(org.w3c.dom.Document, hudson.EnvVars, java.io.PrintStream)
 */
@Override
public Document perform(Document doc, EnvVars env, PrintStream logger) {
    if (StringUtils.isEmpty(getRegex())) {
        logger.println("Regular expression is not specified.");
        return null;
    }

    String expandedRegex = StringUtils.trim(env.expand(getRegex()));
    if (StringUtils.isEmpty(expandedRegex)) {
        logger.println("Regular expression got to empty.");
        return null;
    }

    try {
        Pattern.compile(expandedRegex);
    } catch (PatternSyntaxException e) {
        e.printStackTrace(logger);
        return null;
    }

    Node regexNode;
    try {
        regexNode = getNode(doc, "/*/includeRegex");
    } catch (XPathExpressionException e) {
        e.printStackTrace(logger);
        return null;
    }

    if (regexNode == null) {
        // includeRegex is not exist.
        // create new one.
        regexNode = doc.createElement("includeRegex");
        doc.getDocumentElement().appendChild(regexNode);
    }

    regexNode.setTextContent(expandedRegex);
    logger.println(String.format("Set includeRegex to %s", expandedRegex));

    return doc;
}

From source file:net.morphbank.mbsvc3.webservices.RestServiceExcelUpload.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // //from ww  w .j a  va2s. co m
    String method = request.getParameter(RequestParams.PARAM_METHOD);
    if ("remoteupdate".equals(method)) {
        UpdateRemote.update(request, response);
    } else {
        // TODO turn over to processrequest
        response.setContentType("text/xml");
        PrintStream out = new PrintStream(response.getOutputStream());
        out.println("<html><body>Here I am</body></html>");
        out.close();
    }
}

From source file:com.liferay.arquillian.container.LiferayContainer.java

private void checkErrors(HttpResponse response) throws IOException, DeploymentException {

    StatusLine statusLine = response.getStatusLine();

    int statusCode = statusLine.getStatusCode();

    if (statusCode != HttpStatus.SC_OK) {
        final String stackTrace = getBodyAsString(response);

        throw new DeploymentException(stackTrace) {

            @Override// w  ww.jav  a2 s  . co m
            public void printStackTrace(PrintWriter printWriter) {
                printWriter.println("REMOTE: " + stackTrace);
            }

            @Override
            public void printStackTrace(PrintStream printStream) {
                printStream.println("REMOTE: " + stackTrace);
            }

            @Override
            public void printStackTrace() {
                System.out.println("REMOTE: " + stackTrace);
            }

            @Override
            public synchronized Throwable fillInStackTrace() {
                return this;
            }
        };
    }
}

From source file:GuitarManufacturerList.java

/**
 * <p>Test iterating over an object that extends List</p>
 *//*  w  ww  .  j  av a2  s  . c  o m*/
public void testListExtension(PrintStream out) throws IOException {
    // Add some items for good measure
    manufacturers.add("Epiphone Guitars");
    manufacturers.add("Gibson Guitars");

    // Iterate with for/in
    for (String manufacturer : manufacturers) {
        out.println(manufacturer);
    }
}

From source file:de.tsystems.mms.apm.performancesignature.dynatrace.PerfSigActivateConfiguration.java

@Override
public void perform(@Nonnull final Run<?, ?> run, @Nonnull final FilePath workspace,
        @Nonnull final Launcher launcher, @Nonnull final TaskListener listener)
        throws InterruptedException, IOException {
    PrintStream logger = listener.getLogger();
    DTServerConnection connection = PerfSigUtils.createDTServerConnection(dynatraceProfile);

    logger.println(Messages.PerfSigActivateConfiguration_ActivatingProfileConfiguration());
    boolean result = connection.activateConfiguration(configuration);
    if (!result) {
        throw new CommandExecutionException(Messages.PerfSigActivateConfiguration_InternalError());
    }/*from  ww  w  .  j  av a  2 s. c o  m*/
    logger.println(Messages
            .PerfSigActivateConfiguration_SuccessfullyActivated(connection.getCredProfilePair().getProfile()));

    for (Agent agent : connection.getAgents()) {
        if (agent.getSystemProfile().equalsIgnoreCase(connection.getCredProfilePair().getProfile())) {
            boolean hotSensorPlacement = connection.hotSensorPlacement(agent.getAgentId());
            if (hotSensorPlacement) {
                logger.println(Messages.PerfSigActivateConfiguration_HotSensorPlacementDone(agent.getName()));
            } else {
                logger.println(Messages.PerfSigActivateConfiguration_FailureActivation(agent.getName()));
            }
        }
    }
}

From source file:eu.stratosphere.myriad.driver.MyriadDriverFrontend.java

private void printErrors(PrintStream out, ParsedOptions parsedOptions) {
    for (String message : parsedOptions.getErrorMessages()) {
        out.println("Error: " + message);
    }//from  w ww. j  ava 2s.c o  m
    out.println();
}

From source file:com.norconex.collector.core.AbstractCollectorLauncher.java

public void launch(String[] args) {
    CommandLine cmd = parseCommandLineArguments(args);
    String action = cmd.getOptionValue(ARG_ACTION);
    File configFile = new File(cmd.getOptionValue(ARG_CONFIG));
    File varFile = null;/*  w w  w .  ja  v a 2 s  .  c  o m*/
    if (cmd.hasOption(ARG_VARIABLES)) {
        varFile = new File(cmd.getOptionValue(ARG_VARIABLES));
    }

    try {
        if (!configFile.isFile()) {
            System.err.println("Invalid configuration file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }
        if (varFile != null && !varFile.isFile()) {
            System.err.println("Invalid variable file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }

        ICollectorConfig config = new CollectorConfigLoader(getCollectorConfigClass())
                .loadCollectorConfig(configFile, varFile);
        ICollector collector = createCollector(config);
        if (ARG_ACTION_START.equalsIgnoreCase(action)) {
            collector.start(false);
        } else if (ARG_ACTION_RESUME.equalsIgnoreCase(action)) {
            collector.start(true);
        } else if (ARG_ACTION_STOP.equalsIgnoreCase(action)) {
            collector.stop();
        }
    } catch (Exception e) {
        PrintStream err = System.err;
        File errorFile = new File("./error-" + System.currentTimeMillis() + ".log");
        err.println("\n\nAn ERROR occured:\n\n" + e.getLocalizedMessage());
        err.println("\n\nDetails of the error has been stored at: " + errorFile.getAbsolutePath() + "\n\n");
        try {
            PrintWriter w = new PrintWriter(errorFile, CharEncoding.UTF_8);
            e.printStackTrace(w);
            w.flush();
            w.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e1) {
            err.println("\n\nCannot write error file. " + e1.getLocalizedMessage());
        }
        System.exit(-1);
    }
}

From source file:com.bennavetta.appsite.processing.ProcessingController.java

public void handle(Request request, Response response, InputStream requestBody, OutputStream responseBody)
        throws Exception {
    for (RewriteRule rule : rewriteRules.get()) {
        if (rule.matches(request.getURI())) {
            URI rewritten = rule.rewrite(request.getURI());
            log.info("Rewriting {} to {}", request.getURI(), rewritten);
            handle(new RedirectedRequest(rewritten, request), response, requestBody, responseBody);
        }/*from  www.j a  va 2  s  .  com*/
    }

    Resource resource = Resource.get(request.getURI());

    // index pages
    if (resource == null) {
        for (String indexPage : indexPages) {
            String indexUri = URI.create(request.getURI()).relativize(URI.create(indexPage)).toString();
            resource = Resource.get(indexUri);
            if (resource != null) {
                break;
            }
        }
    }

    if (resource == null) {
        resource = Resource.get(error.notFound()); //TODO: put requested page in attributes
        response.setStatus(HttpStatus.NOT_FOUND);
    }

    if (resource != null) {
        try {
            log.info("Serving resource {}", resource.getPath());
            sendResource(resource, request, response, requestBody, responseBody);
        } catch (Exception e) {
            log.error("Exception serving request", e);
            resource = Resource.get(error.exception()); //TODO: put exception in attributes
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
            sendResource(resource, request, response, requestBody, responseBody);
        }
    } else {
        log.warn("No content found: {}", request.getURI());
        // send something to avoid a blank response
        response.setStatus(HttpStatus.NOT_FOUND);
        response.setContentType(MediaType.HTML_UTF_8);
        PrintStream ps = new PrintStream(responseBody);
        ps.println("<html>");
        ps.println("\t<head>");
        ps.println("\t\t<title>Page not found</title>");
        ps.println("\t</head>");
        ps.println("\t<body>");
        ps.println("\t\t<h1>Page not found</h1>");
        ps.println("\t\t<p>Page " + request.getURI() + " not found</p>");
        ps.println("\t</body>");
        ps.println("</html>");
    }
}

From source file:com.kixeye.chassis.bootstrap.configuration.file.PropertiesFileConfigurationWriter.java

private void dump(Map<String, ?> configuration, Filter filter, PrintStream printStream) {
    for (Map.Entry<String, ?> entry : configuration.entrySet()) {
        if (filter != null && filter.excludeProperty(entry.getKey(), entry.getValue())) {
            continue;
        }//from   ww w . ja  va  2 s.  c o m
        printStream.println(entry.getKey() + "=" + entry.getValue());
    }
}