Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

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

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:bide.simulation.Simulation.java

private static void generateGelFile(String fName, String simDir, double limDet, double spotSd,
        Hashtable<String, double[]> setupTable) {

    double[] setupMean = setupTable.get("setupMean");
    double[] setupDelta = setupTable.get("setupDelta");
    double[] setupPi = setupTable.get("setupPi");
    double[] setupRho = setupTable.get("setupRho");

    try {//from w ww  .j ava 2 s . c  o  m
        StringBuilder sb = new StringBuilder(System.getProperty("user.dir")).append(FILE_SEP).append(simDir)
                .append(FILE_SEP).append(fName).append(FILE_SEP);

        System.out.println(sb.toString());
        checkDir(sb, false);

        sb.append(fName);
        String simLog = sb.toString() + ".log";
        PrintWriter outLog = new PrintWriter(new BufferedWriter(new FileWriter(simLog)));

        String simFile = sb.toString() + ".csv";
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(simFile)));

        GelSetting g = new GelSetting(noSpotPerGroup);
        out.println(g.createLabel());

        for (int i = 0; i < totalSpot; i++) {
            String info = i + "\t" + setupMean[i] + "\t" + setupDelta[i] + "\t"
                    + Transformation.invLogit(setupPi[i]) + "\t"
                    + Transformation.invLogit(setupPi[i] + setupRho[i]);
            System.out.println(info);
            outLog.println(info);
            g = new GelSetting(noSpotPerGroup, setupMean[i], setupDelta[i], setupPi[i], setupRho[i], spotSd);

            g.setLimDet(limDet);
            out.println(GelSetting.printGel(i, g.generateSpot()));

        }
        out.close();
        outLog.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("END");
}

From source file:griffon.util.GriffonUtil.java

public static void printSanitizedStackTrace(Throwable t, PrintWriter p) {
    t = sanitize(t);//from   www. j av a 2 s .  co m

    StackTraceElement[] trace = t.getStackTrace();
    for (int i = 0; i < trace.length; i++) {
        StackTraceElement stackTraceElement = trace[i];
        p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":"
                + stackTraceElement.getLineNumber() + ")");
    }
}

From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java

public static void deleteActivityTemplates(Object caller) throws IOException, InterruptedException {
    String[] cmd = null;/*from w ww.j av  a 2 s  . co m*/

    String templatePath = URLDecoder
            .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8");
    templatePath = templatePath.replace("/", File.separator);
    templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib"));
    templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator;
    templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities"
            + File.separator;

    String[] env = null;

    String tmpdir = getTempLocation();
    BufferedInputStream bufferedInputStream = new BufferedInputStream(
            ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip"));
    unZip(bufferedInputStream, tmpdir);

    if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
        try {
            VirtualFile mobileTemplate = LocalFileSystem.getInstance()
                    .findFileByIoFile(new File(templatePath + mobileServicesTemplateName));
            VirtualFile officeTemplate = LocalFileSystem.getInstance()
                    .findFileByIoFile(new File(templatePath + officeTemplateName));

            if (mobileTemplate != null)
                mobileTemplate.delete(caller);

            if (officeTemplate != null)
                officeTemplate.delete(caller);
        } catch (IOException ex) {
            PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat");
            printWriter.println("@echo off");
            printWriter.println("del \"" + templatePath + mobileServicesTemplateName + "\" /Q /S");
            printWriter.println("del \"" + templatePath + officeTemplateName + "\" /Q /S");
            printWriter.flush();
            printWriter.close();

            String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" };

            cmd = tmpcmd;

            ArrayList<String> tempenvlist = new ArrayList<String>();
            for (String envval : System.getenv().keySet())
                tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval)));

            tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1");
            env = new String[tempenvlist.size()];
            tempenvlist.toArray(env);

            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(cmd, env, new File(tmpdir));
            proc.waitFor();
        }
    } else if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
        VirtualFile mobileTemplate = LocalFileSystem.getInstance()
                .findFileByIoFile(new File(templatePath + mobileServicesTemplateName));
        VirtualFile officeTemplate = LocalFileSystem.getInstance()
                .findFileByIoFile(new File(templatePath + officeTemplateName));

        if (mobileTemplate != null && officeTemplate != null) {
            exec(new String[] { "osascript", "-e",
                    "do shell script \"rm -r \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"",
                    "-e", "do shell script \"rm -r \\\"/" + templatePath + officeTemplateName + "\\\"\"" },
                    tmpdir);
        }
    } else {
        try {
            VirtualFile mobileTemplate = LocalFileSystem.getInstance()
                    .findFileByIoFile(new File(templatePath + mobileServicesTemplateName));
            VirtualFile officeTemplate = LocalFileSystem.getInstance()
                    .findFileByIoFile(new File(templatePath + officeTemplateName));

            mobileTemplate.delete(caller);
            officeTemplate.delete(caller);
        } catch (IOException ex) {

            JPasswordField pf = new JPasswordField();
            int okCxl = JOptionPane.showConfirmDialog(null, pf,
                    "To copy Microsoft Services templates, the plugin needs your password:",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

            if (okCxl == JOptionPane.OK_OPTION) {
                String password = new String(pf.getPassword());

                exec(new String[] { "echo", password, "|", "sudo", "-S", "rm", "-r",
                        tmpdir + mobileServicesTemplateName, templatePath + mobileServicesTemplateName },
                        tmpdir);

                exec(new String[] { "echo", password, "|", "sudo", "-S", "rm", "-r",
                        tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir);
            }
        }
    }
}

From source file:de.instantouch.model.io.SnakeJSONWriter.java

public static String beautify(String jsonString, boolean appendNewline) {

    String beautyString = appendNewline ? newliner(jsonString) : jsonString;

    String delim = String.valueOf("\r\n");
    StringTokenizer tokenizer = new StringTokenizer(beautyString, delim);

    StringWriter beautyWriter = new StringWriter();
    PrintWriter beautyPrinter = new PrintWriter(beautyWriter);

    int tabs = 0;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.contains("}") || token.contains("]")) {
            tabs--;//  w  w w .j  av  a 2s  .  c om
        }

        beautyPrinter.println(printtabs(beautyPrinter, tabs) + token);
        if (token.contains("{") || token.contains("[")) {
            tabs++;
        }
    }

    return beautyWriter.toString();
}

From source file:com.jaeksoft.searchlib.crawler.web.database.pattern.PatternManager.java

public static String getStringPatternList(List<PatternItem> patternList) {
    StringWriter sw = null;//  w w  w .j  a  va  2  s .co m
    PrintWriter pw = null;
    try {
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        for (PatternItem item : patternList)
            pw.println(item.getPattern());
        return sw.toString();
    } finally {
        if (pw != null)
            IOUtils.closeQuietly(pw);
        if (sw != null)
            IOUtils.closeQuietly(sw);
    }
}

From source file:com.mgmtp.perfload.loadprofiles.util.PlotFileCreator.java

/**
 * Create a plot in .csv-format of the given x and y values, starting with a headerline
 * containing the given xText and yText.
 *//*from w w w  .java2 s.c om*/
private static void createPlot(final File file, final double[] x, final double[] y, final String xText,
        final String yText) throws IOException {

    PrintWriter pw = null;
    try {
        forceMkdir(file.getParentFile());
        pw = new PrintWriter(file, "UTF-8");

        Format format = NumberFormat.getNumberInstance();
        pw.println(xText + "; " + yText);
        for (int iLine = 0; iLine < x.length; iLine++) {
            pw.println(format.format(x[iLine]) + "; " + format.format(y[iLine]));
        }
    } finally {
        IOUtils.closeQuietly(pw);
    }
}

From source file:com.mgmtp.perfload.loadprofiles.generation.EventDistributor.java

/**
 * Write the List of load test events for a perfLoadClient The list contains following values: -
 * start time of the operation in milliseconds since start of the load test - name of the
 * operation (i.e. UStVA) - name of the host on which this operation is triggered - port of the
 * host over which the operation is triggered - number of daemon executing this test
 * (=identifier of operation) - number of the process of the daemon (here always 1) The format
 * of the file is one load test event per line, arguments separated by the given eventSeparator.
 * //from   w  w w  .  j ava 2s  .c  o  m
 * @param file
 *            The events file
 * @param eventList
 *            List of load test events
 */
public static void writeEventListForPerfLoadClientsToFile(final File file, final String headerLines,
        final List<? extends BaseLoadProfileEvent> eventList) throws IOException {
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(file, "UTF-8");
        pw.println(headerLines);

        for (BaseLoadProfileEvent event : eventList) {
            if (event instanceof LoadEvent) {
                LoadEvent loadEvent = (LoadEvent) event;
                // convert time from hours to milliseconds
                long t = Math.round(loadEvent.getTime() * 60. * 60. * 1000.);
                String operation = loadEvent.getOperation().getName();
                String target = loadEvent.getTarget().getName();
                int daemonId = loadEvent.getDaemonId();
                int processId = loadEvent.getProcessId() + 1;
                pw.println(t + eventSeparator + operation + eventSeparator + target + eventSeparator + daemonId
                        + eventSeparator + processId);
            } else if (event instanceof MarkerEvent) {
                MarkerEvent marker = (MarkerEvent) event;
                long t = Math.round(marker.getTime() * 60. * 60. * 1000.);
                pw.println(t + eventSeparator + "[[marker]]" + eventSeparator + marker.getName()
                        + eventSeparator + marker.getType() + eventSeparator);
            }
        }
    } finally {
        IOUtils.closeQuietly(pw);
    }
}

From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java

public static void newActivityTemplateManager() throws IOException, InterruptedException {
    String[] cmd = null;//from  w w  w . j a va 2 s .c o  m

    String templatePath = URLDecoder
            .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8");
    templatePath = templatePath.replace("/", File.separator);
    templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib"));
    templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator;
    templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities"
            + File.separator;

    String[] env = null;

    if (!new File(templatePath + mobileServicesTemplateName).exists()) {
        String tmpdir = getTempLocation();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(
                ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip"));
        unZip(bufferedInputStream, tmpdir);

        if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
            try {
                copyFolder(new File(tmpdir + mobileServicesTemplateName),
                        new File(templatePath + mobileServicesTemplateName));
                copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName));
            } catch (IOException ex) {
                PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat");
                printWriter.println("@echo off");
                printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\"");
                printWriter.println("md \"" + templatePath + officeTemplateName + "\"");
                printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath
                        + mobileServicesTemplateName + "\" /s /i /Y");
                printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath
                        + officeTemplateName + "\" /s /i /Y");
                printWriter.flush();
                printWriter.close();

                String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" };

                cmd = tmpcmd;

                ArrayList<String> tempenvlist = new ArrayList<String>();
                for (String envval : System.getenv().keySet())
                    tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval)));

                tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1");
                env = new String[tempenvlist.size()];
                tempenvlist.toArray(env);

                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(cmd, env, new File(tmpdir));
                proc.waitFor();

                //wait for elevate command to finish
                Thread.sleep(3000);

                if (!new File(templatePath + mobileServicesTemplateName).exists())
                    UIHelper.showException(
                            "Error copying template files. Please refer to documentation to copy manually.",
                            new Exception());
            }
        } else {
            if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {

                String[] strings = { "osascript",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"",
                        "-e",
                        "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"",
                        "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"" };

                exec(strings, tmpdir);
            } else {
                try {

                    copyFolder(new File(tmpdir + mobileServicesTemplateName),
                            new File(templatePath + mobileServicesTemplateName));
                    copyFolder(new File(tmpdir + officeTemplateName),
                            new File(templatePath + officeTemplateName));

                } catch (IOException ex) {

                    JPasswordField pf = new JPasswordField();
                    int okCxl = JOptionPane.showConfirmDialog(null, pf,
                            "To copy Microsoft Services templates, the plugin needs your password:",
                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

                    if (okCxl == JOptionPane.OK_OPTION) {
                        String password = new String(pf.getPassword());

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + mobileServicesTemplateName,
                                templatePath + mobileServicesTemplateName }, tmpdir);

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir);
                    }
                }
            }
        }
    }
}

From source file:com.zimbra.common.util.TemplateCompiler.java

private static void printBufferLine(PrintWriter out, String... ss) {
    out.print("\tbuffer[_i++] = ");
    for (String s : ss) {
        out.print(s);/*from w ww .  ja  va  2  s. c o m*/
    }
    out.println(";");
}

From source file:Main.java

public static void hexaDump(OutputStream outStream, byte[] data, int len) {

    //if (desc.compareToIgnoreCase("outflow")==0) return ;

    PrintWriter out = new PrintWriter(outStream, true);
    char[] tmpStrBuf = new char[16];
    int index = 0;

    for (int i = 0; i < len; i++) {

        index = (i + 1) % 16;// w ww. j  a  v  a2s.c  o m

        out.print(byteToHexa(data[i]) + " ");

        if ((data[i] >= ' ') && (data[i] <= 'z'))
            tmpStrBuf[i % 16] = (char) data[i];
        else
            tmpStrBuf[i % 16] = '.';

        if (index == 0) {
            out.println("          " + new String(tmpStrBuf, 0, 16));
            for (int j = 0; j < 16; j++)
                tmpStrBuf[j] = (char) 0x00;
        }

    }

    if (index != 0) {
        for (int i = 0; i < 16 - index; i++)
            out.print("  " + " ");
        out.println("          " + new String(tmpStrBuf, 0, index));
    }
}