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:com.github.lindenb.jvarkit.tools.misc.FindAllCoverageAtPosition.java

@Override
public void printOptions(PrintStream out) {
    out.println(" -p chrom:pos . Add this chrom/position. Required");
    super.printOptions(out);
}

From source file:net.gbmb.collector.example.SimpleLogPush.java

private String storeArchive(Collection collection) throws IOException {
    String cid = collection.getId();
    java.util.Collection<CollectionRecord> records = collectionRecords.get(cid);

    // index// w  w w  .ja v  a 2  s.c  o  m
    ByteArrayOutputStream indexStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
    PrintStream output = new PrintStream(indexStream);
    // zip
    ByteArrayOutputStream archiveStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
    ZipOutputStream zos = new ZipOutputStream(archiveStream);
    output.println("Serialize collection: " + collection.getId());
    output.println("  creation date: " + collection.getCreationDate());
    output.println("  end date:      " + collection.getEndDate());
    for (CollectionRecord cr : records) {
        output.print(cr.getRecordDate());
        output.print(" ");
        output.println(cr.getContent());
        if (cr.getAttachment() != null) {
            String attName = cr.getAttachment();
            output.println("  > " + attName);
            ZipEntry entry = new ZipEntry(cr.getAttachment());
            zos.putNextEntry(entry);
            InputStream content = temporaryStorage.get(cid, attName);
            IOUtils.copy(content, zos);
        }
    }
    // add the index file
    output.close();
    ZipEntry index = new ZipEntry("index");
    zos.putNextEntry(index);
    IOUtils.write(indexStream.toByteArray(), zos);
    // close zip
    zos.close();
    ByteArrayInputStream content = new ByteArrayInputStream(archiveStream.toByteArray());

    // send to final storage
    return finalStorage.store(cid, content);
}

From source file:jp.ikedam.jenkins.plugins.jobcopy_builder.AdditionalFileset.java

/**
 * Copy the additional files and apply additional operations.
 * // www  .j a va 2  s  .co m
 * @param toJob
 * @param fromJob
 * @param logger
 * @return whether the work succeeded.
 */
public boolean perform(TopLevelItem toJob, TopLevelItem fromJob, EnvVars env, PrintStream logger) {
    if (StringUtils.isBlank(getIncludeFile())) {
        logger.println("includeFile is not configured");
        return false;
    }

    boolean ret = true;

    for (String filename : getFilesToCopy(fromJob.getRootDir())) {
        logger.println(String.format("Copy %s", filename));
        File srcFile = new File(fromJob.getRootDir(), filename);
        File dstFile = new File(toJob.getRootDir(), filename);
        if (!performToFile(dstFile, srcFile, env, logger)) {
            ret = false;
        }
    }

    return ret;
}

From source file:edu.msu.cme.rdp.kmer.cli.KmerCoverage.java

private synchronized void writeSeq(Sequence seq, PrintStream outStream) {
    outStream.println(">" + seq.getSeqName() + "\n" + seq.getSeqString());
}

From source file:org.jsnap.request.HttpRequest.java

protected void processException(JSnapException ex) {
    ex.log();/*  w w w .j  av  a 2s. c om*/
    int statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; // HTTP.500
    if (ex instanceof MalformedRequestException)
        statusCode = HttpStatus.SC_BAD_REQUEST; // HTTP.400
    else if (ex instanceof LoginFailedException || ex instanceof AccessDeniedException)
        statusCode = HttpStatus.SC_UNAUTHORIZED; // HTTP.401
    PrintStream ps = new PrintStream(servlet.response.out);
    ps.println("HTTP " + statusCode + " " + HttpStatus.getStatusText(statusCode));
    ps.println();
    ex.printStackTrace(ps);
    servlet.response.contentType = Formatter.PLAIN;
    servlet.response.characterSet = Formatter.DEFAULT;
    servlet.response.statusCode = statusCode;
}

From source file:hu.bme.mit.sette.GeneratorUI.java

public void run(BufferedReader in, PrintStream out) throws Exception {
    // directories
    File snippetProjectDir = generator.getSnippetProjectSettings().getBaseDirectory();
    File runnerProjectDir = generator.getRunnerProjectSettings().getBaseDirectory();

    out.println("Snippet project: " + snippetProjectDir);
    out.println("Runner project: " + runnerProjectDir);

    // backup output directory if it exists
    if (runnerProjectDir.exists()) {
        out.print(/* w  w w  .ja va 2 s.c  o m*/
                "The output directory exists. It will be deleted before generation. Would you like to make a backup? [yes] ");

        String line = in.readLine();

        if (line == null) {
            out.println("EOF detected, exiting");
            return;
        }

        if (!line.trim().equalsIgnoreCase("no")) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH;mm;ss");

            File backup = new File(runnerProjectDir.getParentFile(),
                    runnerProjectDir.getName() + "-backup-" + dateFormat.format(new Date())).getCanonicalFile();

            if (runnerProjectDir.renameTo(backup)) {
                out.println("Backup location: " + backup);
            } else {
                out.println("Backup failed, exiting");
                return;
            }
        }
    }

    try {
        // generate runner project
        out.println("Starting generation");
        FileUtils.deleteDirectory(runnerProjectDir);
        generator.generate();
        out.println("Generation successful");
    } catch (Exception e) {
        out.println("Generation failed: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.exquance.jenkins.plugins.HarbormasterTrigger.java

/**
 * Called when a POST is made.//  ww w.j a va 2  s .  com
 */
public void onPost(String triggeredByUser) {
    final String pushBy = triggeredByUser;
    getDescriptor().queue.execute(new Runnable() {
        private boolean runPolling() {
            try {
                StreamTaskListener listener = new StreamTaskListener(getLogFile());
                try {
                    PrintStream logger = listener.getLogger();
                    long start = System.currentTimeMillis();
                    logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date()));
                    boolean result = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job).poll(listener)
                            .hasChanges();
                    logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start));
                    if (result)
                        logger.println("Changes found");
                    else
                        logger.println("No changes");
                    return result;
                } catch (Error e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } catch (RuntimeException e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } finally {
                    listener.close();
                }
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
            }
            return false;
        }

        public void run() {
            if (runPolling()) {
                String name = " #" + job.getNextBuildNumber();
                HarbormasterPushCause cause;
                try {
                    cause = new HarbormasterPushCause(getLogFile(), pushBy);
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, "Failed to parse the polling log", e);
                    cause = new HarbormasterPushCause(pushBy);
                }
                ParameterizedJobMixIn pJob = new ParameterizedJobMixIn() {
                    @Override
                    protected Job asJob() {
                        return job;
                    }
                };
                if (pJob.scheduleBuild(cause)) {
                    LOGGER.info("SCM changes detected in " + job.getName() + ". Triggering " + name);
                } else {
                    LOGGER.info("SCM changes detected in " + job.getName() + ". Job is already in the queue");
                }
            }
        }

    });
}

From source file:hudson.os.windows.ManagedWindowsServiceLauncher.java

public void launch(final SlaveComputer computer, final TaskListener listener)
        throws IOException, InterruptedException {
    try {//from   w  ww  .j  av a  2  s.c  o  m
        PrintStream logger = listener.getLogger();

        logger.println(Messages.ManagedWindowsServiceLauncher_ConnectingTo(computer.getName()));
        JIDefaultAuthInfoImpl auth = createAuth();
        JISession session = JISession.createSession(auth);
        session.setGlobalSocketTimeout(60000);
        SWbemServices services = WMI.connect(session, computer.getName());

        String path = computer.getNode().getRemoteFS();
        SmbFile remoteRoot = new SmbFile(
                "smb://" + computer.getName() + "/" + path.replace('\\', '/').replace(':', '$') + "/",
                createSmbAuth());

        Win32Service slaveService = services.getService("hudsonslave");
        if (slaveService == null) {
            logger.println(Messages.ManagedWindowsServiceLauncher_InstallingSlaveService());
            if (!DotNet.isInstalled(2, 0, computer.getName(), auth)) {
                // abort the launch
                logger.println(Messages.ManagedWindowsServiceLauncher_DotNetRequired());
                return;
            }

            if (!remoteRoot.exists())
                remoteRoot.mkdirs();

            // copy exe
            logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveExe());
            copyAndClose(getClass().getResource("/windows-service/hudson.exe").openStream(),
                    new SmbFile(remoteRoot, "hudson-slave.exe").getOutputStream());

            copySlaveJar(logger, remoteRoot);

            // copy hudson-slave.xml
            logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveXml());
            String xml = WindowsSlaveInstaller.generateSlaveXml("javaw.exe", "-tcp %BASE%\\port.txt");
            copyAndClose(new ByteArrayInputStream(xml.getBytes("UTF-8")),
                    new SmbFile(remoteRoot, "hudson-slave.xml").getOutputStream());

            // install it as a service
            logger.println(Messages.ManagedWindowsServiceLauncher_RegisteringService());
            Document dom = new SAXReader().read(new StringReader(xml));
            Win32Service svc = services.Get("Win32_Service").cast(Win32Service.class);
            int r = svc.Create(dom.selectSingleNode("/service/id").getText(),
                    dom.selectSingleNode("/service/name").getText(), path + "\\hudson-slave.exe",
                    Win32OwnProcess, 0, "Manual", true);
            if (r != 0) {
                listener.error("Failed to create a service: " + svc.getErrorMessage(r));
                return;
            }
            slaveService = services.getService("hudsonslave");
        } else {
            copySlaveJar(logger, remoteRoot);
        }

        logger.println(Messages.ManagedWindowsServiceLauncher_StartingService());
        slaveService.start();

        // wait until we see the port.txt, but don't do so forever
        logger.println(Messages.ManagedWindowsServiceLauncher_WaitingForService());
        SmbFile portFile = new SmbFile(remoteRoot, "port.txt");
        for (int i = 0; !portFile.exists(); i++) {
            if (i >= 30) {
                listener.error(Messages.ManagedWindowsServiceLauncher_ServiceDidntRespond());
                return;
            }
            Thread.sleep(1000);
        }
        int p = readSmbFile(portFile);

        // connect
        logger.println(Messages.ManagedWindowsServiceLauncher_ConnectingToPort(p));
        final Socket s = new Socket(computer.getName(), p);

        // ready
        computer.setChannel(new BufferedInputStream(new SocketInputStream(s)),
                new BufferedOutputStream(new SocketOutputStream(s)), listener.getLogger(), new Listener() {
                    public void onClosed(Channel channel, IOException cause) {
                        afterDisconnect(computer, listener);
                    }
                });
    } catch (SmbException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (JIException e) {
        if (e.getErrorCode() == 5)
            // access denied error
            e.printStackTrace(listener.error(Messages.ManagedWindowsServiceLauncher_AccessDenied()));
        else
            e.printStackTrace(listener.error(e.getMessage()));
    } catch (DocumentException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    }
}

From source file:net.jperf.LogParserTest.java

public void testLogParserMain() throws Exception {
    PrintStream realOut = System.out;
    ByteArrayOutputStream fakeOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(fakeOut, true));
    try {/*from www  .j  a va2  s  .c o m*/
        //usage
        realOut.println("-- Usage Test --");
        LogParser.runMain(new String[] { "--help" });
        realOut.println(fakeOut.toString());
        assertTrue(fakeOut.toString().indexOf("Usage") >= 0);
        fakeOut.reset();

        //log on std in, write to std out
        InputStream realIn = System.in;
        ByteArrayInputStream fakeIn = new ByteArrayInputStream(testLog.getBytes());
        System.setIn(fakeIn);
        try {
            realOut.println("-- Std in -> Std out Test --");
            LogParser.runMain(new String[0]);
            realOut.println(fakeOut.toString());
            assertTrue(fakeOut.toString().indexOf("tag") >= 0 && fakeOut.toString().indexOf("tag2") >= 0
                    && fakeOut.toString().indexOf("tag3") >= 0);
            fakeOut.reset();
        } finally {
            System.setIn(realIn);
        }

        //Log from a file
        FileUtils.writeStringToFile(new File("./target/logParserTest.log"), testLog);

        //log from file, write to std out
        realOut.println("-- File in -> Std out Test --");
        LogParser.runMain(new String[] { "./target/logParserTest.log" });
        realOut.println(fakeOut.toString());
        assertTrue(fakeOut.toString().indexOf("tag") >= 0 && fakeOut.toString().indexOf("tag2") >= 0
                && fakeOut.toString().indexOf("tag3") >= 0);
        fakeOut.reset();

        //CSV format test
        realOut.println("-- File in -> Std out Test with CSV --");
        LogParser.runMain(new String[] { "-f", "csv", "./target/logParserTest.log" });
        realOut.println(fakeOut.toString());
        assertTrue(fakeOut.toString().indexOf("\"tag\",") >= 0 && fakeOut.toString().indexOf("\"tag2\",") >= 0
                && fakeOut.toString().indexOf("\"tag3\",") >= 0);
        fakeOut.reset();

        //log from file, write to file
        realOut.println("-- File in -> File out Test --");
        LogParser.runMain(new String[] { "-o", "./target/statistics.out", "./target/logParserTest.log" });
        String statsOut = FileUtils.readFileToString(new File("./target/statistics.out"));
        realOut.println(statsOut);
        assertTrue(
                statsOut.indexOf("tag") >= 0 && statsOut.indexOf("tag2") >= 0 && statsOut.indexOf("tag3") >= 0);

        //log from file, write to file, different timeslice
        realOut.println("-- File in -> File out with different timeslice Test --");
        LogParser.runMain(new String[] { "-o", "./target/statistics.out", "--timeslice", "120000",
                "./target/logParserTest.log" });
        statsOut = FileUtils.readFileToString(new File("./target/statistics.out"));
        realOut.println(statsOut);
        assertTrue(
                statsOut.indexOf("tag") >= 0 && statsOut.indexOf("tag2") >= 0 && statsOut.indexOf("tag3") >= 0);

        //missing param test
        realOut.println("-- Missing param test --");
        assertEquals(1, LogParser.runMain(new String[] { "./target/logParserTest.log", "-o" }));

        //unknown arg test
        realOut.println("-- Unknown arg test --");
        assertEquals(1, LogParser.runMain(new String[] { "./target/logParserTest.log", "--foo" }));
        realOut.println(fakeOut);
        assertTrue(fakeOut.toString().indexOf("Unknown") >= 0);

        //graphing test
        realOut.println("-- File in -> File out with graphing --");
        LogParser.runMain(new String[] { "-o", "./target/statistics.out", "-g", "./target/perfGraphs.out",
                "./src/test/resources/net/jperf/dummyLog.txt" });
        statsOut = FileUtils.readFileToString(new File("./target/statistics.out"));
        realOut.println(statsOut);
        String graphsOut = FileUtils.readFileToString(new File("./target/perfGraphs.out"));
        realOut.println(graphsOut);
        assertTrue(graphsOut.indexOf("chtt=TPS") > 0 && graphsOut.indexOf("chtt=Mean") > 0);
    } finally {
        System.setOut(realOut);
    }
}

From source file:com.buildml.main.commands.CliCommandShowPkg.java

/**
 * A helper function for displaying a package folder hierarchy. This method is called
 * recursively to display the package tree.
 * /*from   w w  w  .  j  a  v a 2  s . c o  m*/
 * @param out       The PrintStream on which the tree should be displayed.
 * @param pkgMgr   The PackageMgr that owns the packages.
 * @param thisId   The current package/folder ID (at this level of the tree).
 * @param indent   The indent level.
 */
private void invokeHelper(PrintStream out, IPackageMgr pkgMgr, int thisId, int indent) {

    String name = pkgMgr.getName(thisId);
    boolean isFolder = pkgMgr.isFolder(thisId);

    PrintUtils.indent(out, indent);

    if (isFolder) {
        out.println(name + "/");

        Integer children[] = pkgMgr.getFolderChildren(thisId);
        for (int i = 0; i < children.length; i++) {
            invokeHelper(out, pkgMgr, children[i], indent + 2);
        }

    } else {
        out.println(name);
    }
}