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.newrelic.agent.Deployments.java

static int recordDeployment(CommandLine cmd, AgentConfig config)/*  37:    */ throws Exception
/*  38:    */ {//from ww  w . j a  v a 2 s.  c om
    /*  39: 35 */ String appName = config.getApplicationName();
    /*  40: 36 */ if (cmd.hasOption("appname")) {
        /*  41: 37 */ appName = cmd.getOptionValue("appname");
        /*  42:    */ }
    /*  43: 39 */ if (appName == null) {
        /*  44: 40 */ throw new IllegalArgumentException(
                "A deployment must be associated with an application.  Set app_name in newrelic.yml or specify the application name with the -appname switch.");
        /*  45:    */ }
    /*  46: 43 */ System.out.println("Recording a deployment for application " + appName);
    /*  47:    */
    /*  48: 45 */ String uri = "/deployments.xml";
    /*  49: 46 */ String payload = getDeploymentPayload(appName, cmd);
    /*  50: 47 */ String protocol = "http" + (config.isSSL() ? "s" : "");
    /*  51: 48 */ URL url = new URL(protocol, config.getApiHost(), config.getApiPort(), uri);
    /*  52:    */
    /*  53: 50 */ System.out.println(MessageFormat.format("Opening connection to {0}:{1}",
            new Object[] { config.getApiHost(), Integer.toString(config.getApiPort()) }));
    /*  54:    */
    /*  55:    */
    /*  56: 53 */ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    /*  57: 54 */ conn.setRequestProperty("x-license-key", config.getLicenseKey());
    /*  58:    */
    /*  59: 56 */ conn.setRequestMethod("POST");
    /*  60: 57 */ conn.setConnectTimeout(10000);
    /*  61: 58 */ conn.setReadTimeout(10000);
    /*  62: 59 */ conn.setDoOutput(true);
    /*  63: 60 */ conn.setDoInput(true);
    /*  64:    */
    /*  65: 62 */ conn.setRequestProperty("Content-Length", Integer.toString(payload.length()));
    /*  66: 63 */ conn.setFixedLengthStreamingMode(payload.length());
    /*  67: 64 */ conn.getOutputStream().write(payload.getBytes());
    /*  68:    */
    /*  69: 66 */ int responseCode = conn.getResponseCode();
    /*  70: 67 */ if (responseCode < 300)
    /*  71:    */ {
        /*  72: 68 */ System.out.println("Deployment successfully recorded");
        /*  73:    */ }
    /*  74: 69 */ else if (responseCode == 401)
    /*  75:    */ {
        /*  76: 70 */ System.out.println(
                "Unable to notify New Relic of the deployment because of an authorization error.  Check your license key.");
        /*  77: 71 */ System.out.println("Response message: " + conn.getResponseMessage());
        /*  78:    */ }
    /*  79:    */ else
    /*  80:    */ {
        /*  81: 73 */ System.out.println("Unable to notify New Relic of the deployment");
        /*  82: 74 */ System.out.println("Response message: " + conn.getResponseMessage());
        /*  83:    */ }
    /*  84: 76 */ boolean isError = responseCode >= 300;
    /*  85: 77 */ if ((isError) || (config.isDebugEnabled()))
    /*  86:    */ {
        /*  87: 78 */ System.out.println("Response code: " + responseCode);
        /*  88: 79 */ InputStream inStream = isError ? conn.getErrorStream() : conn.getInputStream();
        /*  89: 81 */ if (inStream != null)
        /*  90:    */ {
            /*  91: 82 */ ByteArrayOutputStream output = new ByteArrayOutputStream();
            /*  92: 83 */ Streams.copy(inStream, output);
            /*  93:    */
            /*  94: 85 */ PrintStream out = isError ? System.err : System.out;
            /*  95:    */
            /*  96: 87 */ out.println(output);
            /*  97:    */ }
        /*  98:    */ }
    /*  99: 90 */ return responseCode;
    /* 100:    */ }

From source file:fr.ign.cogit.geoxygene.appli.render.stats.RenderingStatistics.java

public static void printStatistics(OutputStream out) {
    if (!on) {/*from  w  w w . j  a  v  a2  s . c om*/
        return;
    }
    PrintStream pos = new PrintStream(out);
    pos.println("------------------------------------------------------");
    pos.println(getUserMessage());
    pos.println("Rendering time = " + (renderingEnd - renderingStart) + "ms (overlay included)");
    pos.println("overlay time = " + (overlayEnd - overlayStart) + "ms");
    pos.println("nb program switch = " + nbProgramSwitch);
    pos.println("nb draw call = " + nbDrawCall);
    pos.println("nb gl complex = " + nbGLComplex);
    pos.println("nb meshes = " + meshCount);
    pos.println("nb vertices = " + vertexCount);
    pos.println("nb triangles (approx) = " + triangleCount);
    pos.println("nb couple feature/symbolizer renderered = " + nbCoupleFeatureSymbolizer);
    pos.println("nb different features = " + features.size());
    pos.println("nb different symbolizers = " + symbolizers.size());
    for (Map.Entry<GeoxygeneGLRenderer, RendererStatistics> entry : renderers.entrySet()) {
        // GeoxComplexRenderer renderer = entry.getKey();
        RendererStatistics stats = entry.getValue();
        ByteArrayOutputStream statsOut = new ByteArrayOutputStream();
        stats.printStatistics(statsOut);
        pos.println(statsOut.toString());
    }
}

From source file:gaffer.accumulo.utils.IngestUtils.java

/**
 * Given some split points, write a Base64 encoded splits file.
 * //from w  w w .  ja v a 2s  .c  o m
 * @param splits  The split points
 * @param fs  The FileSystem in which to create the splits file
 * @param splitsFile  The location of the output splits file
 * @throws IOException
 */
public static void writeSplitsFile(Collection<Text> splits, FileSystem fs, Path splitsFile) throws IOException {
    PrintStream out = null;
    try {
        out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true)));
        for (Text split : splits) {
            out.println(new String(Base64.encodeBase64(split.getBytes())));
        }
    } finally {
        IOUtils.closeStream(out);
    }
}

From source file:com.azaptree.services.spring.application.SpringApplicationService.java

private static void logEnvironment(final Logger log) {
    if (log.isDebugEnabled()) {
        final TreeMap<String, String> sysProps = new TreeMap<>(System.getenv());
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(bos);
        for (final Map.Entry<String, String> entry : sysProps.entrySet()) {
            ps.print(entry.getKey());//from  www. j a  va2s  . c om
            ps.print('=');
            ps.println(entry.getValue());
        }
        log.debug("Environment:\n{}", bos);
    }
}

From source file:com.azaptree.services.spring.application.SpringApplicationService.java

private static void logDebugSystemProperties(final Logger log) {
    Assert.notNull(log);/* w  w w .java 2 s.  c o  m*/
    if (log.isDebugEnabled()) {
        final TreeMap<String, String> sysProps = new TreeMap<>();
        for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
            sysProps.put(entry.getKey().toString(), entry.getValue().toString());
        }
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(bos);
        for (final Map.Entry<String, String> entry : sysProps.entrySet()) {
            ps.print(entry.getKey());
            ps.print('=');
            ps.println(entry.getValue());
        }
        log.debug("System Properties:\n{}", bos);
    }
}

From source file:edu.msu.cme.rdp.framebot.stat.TaxonAbundance.java

public static void mapAbundance(File framebotResult, File lineagefile, String outfile,
        HashMap<String, Double> coveragetMap, double identity) throws IOException {
    HashMap<String, String> lineageMap = GetFrameBotStatMain.readDesc(lineagefile);
    HashMap<String, Double> rankMatchMap = new HashMap<String, Double>(); // taxon rank, 
    HashMap<String, Double> matchMap = new HashMap<String, Double>(); // match name

    double totalCount = 0.0;
    File[] files;//from  www.  j  av  a2 s .  c  o m
    if (framebotResult.isDirectory()) {
        files = framebotResult.listFiles();
    } else {
        files = new File[1];
        files[0] = framebotResult;
    }
    String line;
    BufferedReader reader;
    for (File f : files) {
        reader = new BufferedReader(new FileReader(f));
        while ((line = reader.readLine()) != null) {
            if (!line.startsWith("STAT"))
                continue;
            String[] tokens = line.trim().split("\\t");
            double thisIdentity = Double.parseDouble(tokens[5]);
            if (thisIdentity < identity) {
                continue;
            }

            String match = tokens[1];

            String[] lineage = lineageMap.get(match).split(";");
            String taxonname = lineage[0].trim();
            if (lineage.length > 1) {
                taxonname = lineage[1];
                if (lineage[1].equalsIgnoreCase("Proteobacteria")) {// || lineage[1].equalsIgnoreCase("Bacteroidetes")){
                    taxonname = lineage[2].trim();
                }
            }
            if (taxonname.equals("")) {
                taxonname = "NA";
            }

            double count = 1.0;
            if (coveragetMap != null) {
                count = coveragetMap.get(tokens[2]);
            }
            Double prevCount = rankMatchMap.get(taxonname);
            if (prevCount != null) {
                rankMatchMap.put(taxonname, count + prevCount);
            } else {
                rankMatchMap.put(taxonname, count);
            }
            Double prevMatchCount = matchMap.get(match);
            if (prevMatchCount != null) {
                matchMap.put(match, count + prevMatchCount);
            } else {
                matchMap.put(match, count);
            }
            totalCount += count;
        }
        reader.close();
    }

    PrintStream out = new PrintStream(new File(outfile));
    // print out abundance group by phylum or class (within Proteobacteria)
    out.println("Taxon\tAbundance\tFraction Abundance");
    for (String taxonname : rankMatchMap.keySet()) {
        out.println(taxonname + "\t" + rankMatchMap.get(taxonname) + "\t"
                + String.format(dformat, rankMatchMap.get(taxonname) / totalCount));
    }

    // print out abundance by closest match   
    out.println("\n\nLineage\tMatchName\tAbundance\tFraction Abundance");
    for (String match : matchMap.keySet()) {
        String lineage = lineageMap.get(match);
        if (lineage.equals("")) {
            lineage = "NA";
        }
        out.println(lineage + "\t" + match + "\t" + matchMap.get(match) + "\t"
                + String.format(dformat, matchMap.get(match) / totalCount));
    }

    out.close();
}

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * ??/*w  w w .ja  v a 2  s. co m*/
 * @param req
 * @param out
 */
public static void dumpHeaders(HttpServletRequest req, PrintStream out) {
    Enumeration hds = req.getHeaderNames();
    out.println("=============== HEADERS ===============");
    while (hds.hasMoreElements()) {
        String name = (String) hds.nextElement();
        out.println(name + "=" + req.getHeader(name));
    }
}

From source file:com.ibm.devops.notification.MessageHandler.java

public static void postToWebhook(String webhook, boolean deployableMessage, JSONObject message,
        PrintStream printStream) {
    //check webhook
    if (Util.isNullOrEmpty(webhook)) {
        printStream.println("[IBM Cloud DevOps] IBM_CLOUD_DEVOPS_WEBHOOK_URL not set.");
        printStream.println("[IBM Cloud DevOps] Error: Failed to notify OTC.");
    } else {//w  w w  . j a va2 s. com
        // set a 5 seconds timeout
        RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(5000)
                .setConnectTimeout(5000).setConnectionRequestTimeout(5000).build();
        CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig)
                .build();
        HttpPost postMethod = new HttpPost(webhook);
        try {
            StringEntity data = new StringEntity(message.toString());
            postMethod.setEntity(data);
            postMethod = Proxy.addProxyInformation(postMethod);
            postMethod.addHeader("Content-Type", "application/json");

            if (deployableMessage) {
                postMethod.addHeader("x-create-connection", "true");
                printStream.println("[IBM Cloud DevOps] Sending Deployable Mapping message to webhook:");
                printStream.println(message);
            }

            CloseableHttpResponse response = httpClient.execute(postMethod);

            if (response.getStatusLine().toString().matches(".*2([0-9]{2}).*")) {
                printStream.println("[IBM Cloud DevOps] Message successfully posted to webhook.");
            } else {
                printStream.println(
                        "[IBM Cloud DevOps] Message failed, response status: " + response.getStatusLine());
            }
        } catch (IOException e) {
            printStream.println("[IBM Cloud DevOps] IOException, could not post to webhook:");
            e.printStackTrace(printStream);
        }
    }
}

From source file:Main.java

private static List<Integer> getAllRelatedPids(final int pid) {
    List<Integer> result = new ArrayList<Integer>(Arrays.asList(pid));
    // use 'ps' to get this pid and all pids that are related to it (e.g.
    // spawned by it)
    try {/*from w  w  w . j a va 2 s . c o m*/

        final Process suProcess = Runtime.getRuntime().exec("su");

        new Thread(new Runnable() {

            @Override
            public void run() {
                PrintStream outputStream = null;
                try {
                    outputStream = new PrintStream(new BufferedOutputStream(suProcess.getOutputStream(), 8192));
                    outputStream.println("ps");
                    outputStream.println("exit");
                    outputStream.flush();
                } finally {
                    if (outputStream != null) {
                        outputStream.close();
                    }
                }

            }
        }).run();

        if (suProcess != null) {
            try {
                suProcess.waitFor();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(suProcess.getInputStream()), 8192);
            while (bufferedReader.ready()) {
                String[] line = SPACES_PATTERN.split(bufferedReader.readLine());
                if (line.length >= 3) {
                    try {
                        if (pid == Integer.parseInt(line[2])) {
                            result.add(Integer.parseInt(line[1]));
                        }
                    } catch (NumberFormatException ignore) {
                    }
                }
            }
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    return result;
}

From source file:com.splunk.shuttl.testutil.TUtilsFile.java

/**
 * Writes random alphanumeric content to specified file.
 * //from   w  w  w.j a  va2s.  c  om
 * @param file
 */
public static void populateFileWithRandomContent(File file) {
    PrintStream printStream = null;
    try {
        printStream = new PrintStream(file);
        printStream.println(RandomStringUtils.randomAlphanumeric(1000));
        printStream.flush();
    } catch (FileNotFoundException e) {
        TUtilsTestNG.failForException("Failed to write random content", e);
    } finally {
        IOUtils.closeQuietly(printStream);
    }
}