Example usage for java.io PrintWriter close

List of usage examples for java.io PrintWriter close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

From source file:fit.FitServer.java

private static byte[] readTable(Parse table) {
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
    OutputStreamWriter streamWriter;
    try {//from   w w w  .  jav a2s  . co  m
        streamWriter = new OutputStreamWriter(byteBuffer, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new ImpossibleException("UTF-8 is a supported encoding", e);
    }
    PrintWriter writer = new PrintWriter(streamWriter);
    Parse more = table.more;
    table.more = null;
    if (table.trailer == null)
        table.trailer = "";
    table.print(writer);
    table.more = more;
    writer.close();
    return byteBuffer.toByteArray();
}

From source file:com.twosigma.beaker.core.Main.java

private static void writePID(BeakerConfig bkConfig) throws FileNotFoundException {

    String name = ManagementFactory.getRuntimeMXBean().getName();
    int at = name.indexOf("@");
    if (at > 0) {
        String pid = name.substring(0, at);
        String dir = bkConfig.getNginxServDirectory();
        PrintWriter out = new PrintWriter(dir + "/pid");
        out.println(pid);//from   ww w.  ja v  a 2  s  .c o m
        out.close();
    } else {
        logger.warn("warning, could not determine PID");
    }
}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

private static File createFile(Repository repository, String filePath) {

    try {//  w  ww.ja va  2s. co  m
        // create the file

        File targetFile = new File(repository.getDirectory().getParent(), filePath);
        File parent = targetFile.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalStateException("Couldn't create dir: " + parent);
        }

        targetFile.createNewFile();

        PrintWriter pw = new PrintWriter(targetFile);
        pw.println("hello");
        pw.close();

        // run the add-call
        new Git(repository).add().addFilepattern(filePath).call();

        return targetFile;

    } catch (Exception ex) {
        throw new RuntimeException("Error while creating file!", ex);
    }
}

From source file:com.googlecode.logVisualizer.LogVisualizer.java

/**
 * Creates KoL data files if they do not already exist in the file system.
 *//*w w w . ja  v  a  2s  . c o  m*/
public static void writeDataFilesToFileSystem() {
    final List<File> kolDataFiles = Lists.newArrayList();
    kolDataFiles
            .add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "bbcodeAugmentations.txt"));
    kolDataFiles.add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "htmlAugmentations.txt"));
    kolDataFiles.add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "textAugmentations.txt"));

    for (final File f : kolDataFiles)
        if (!f.exists()) {
            String tmpLine;
            final BufferedReader br = DataUtilities.getReader(KOL_DATA_DIRECTORY, f.getName());

            try {
                f.createNewFile();
                final PrintWriter fileWriter = new PrintWriter(f);

                while ((tmpLine = br.readLine()) != null)
                    fileWriter.println(tmpLine);

                fileWriter.close();
                br.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
}

From source file:com.code.savemarks.utils.Utils.java

public static String stackTraceToString(Throwable e) {
    String retValue = null;/*from  w w  w  .j av  a  2 s.  c  o  m*/
    StringWriter sw = null;
    PrintWriter pw = null;
    try {
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        retValue = sw.toString();
    } finally {
        try {
            if (pw != null)
                pw.close();
            if (sw != null)
                sw.close();
        } catch (IOException ignore) {
        }
    }
    return retValue;
}

From source file:com.plugin.autoflox.invarscope.aji.executiontracer.JSExecutionTracer.java

/**
 * Retrieves the JavaScript instrumentation array from the webbrowser and
 * writes its contents in Daikon format to a file.
 * /*w  w  w. j ava  2 s  . c  o m*/
 * @param session
 *            The crawling session.
 * @param candidateElements
 *            The candidate clickable elements.
 */
public static void generateTrace(String state, String outputFolder) {

    currentState = state;

    String filename = outputFolder + EXECUTIONTRACEDIRECTORY + "jsexecutiontrace-";
    filename += state;

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date();
    filename += dateFormat.format(date) + ".dtrace";

    traceVector.addElement(filename);
    System.out.println("traceVector size: " + traceVector.size());

    try {

        /*
         * FIXME: Frank, hack to send last buffer items and wait for them to
         * arrive
         */
        //session.getBrowser().executeJavaScript("sendReally();");

        Trace trace = Trace.parse(points);

        PrintWriter file = new PrintWriter(filename);
        file.write(trace.getDeclaration());
        file.write('\n');
        file.write(trace.getData(points));
        file.close();

        System.out.println("Points before cleaned: \n" + points.toString());
        // Justin: We dont need empty points array now since we want to trace multiple errors
        //points = new JSONArray();

    } catch (Exception e) {
        e.printStackTrace();
    }

    /* FROLIN - TRY TO RETRIEVE DOM */
    /*
    try {
       NodeList nlist = session.getCurrentState().getDocument()
       .getElementsByTagName("*");
       System.out.println("State IDs");
       for (int i = 0; i < nlist.getLength(); i++) {
    Element e = (Element) nlist.item(i);
    if (e.hasAttribute("id")) {
       System.out.println(e.getAttribute("id"));
    }
       }
       System.out.println("\n");
    } catch (Exception ee) {
       System.out.println("Error: Exception when retrieving document");
       System.exit(-1);
    }
    */
    /* END TRY TO RETRIEVE DOM */
}

From source file:com.sat.common.CustomReport.java

/**
 * Generate html file./*from   w w w.jav  a 2 s  .  com*/
 *
 * @param msg the msg
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws FileNotFoundException the file not found exception
 */
private static void generateHtmlFile(String msg) throws IOException, FileNotFoundException {
    String htmlfname = "./customreport.html";
    String eol = System.getProperty("line.separator");
    msg = msg.replaceAll("<tr", eol + "<tr");
    msg = msg.replaceAll("</table>", eol + "</table>");
    msg = msg.replaceAll("<table", eol + "<table");
    new FileOutputStream(htmlfname).close();
    PrintWriter htmlfile = new PrintWriter(new BufferedWriter(new FileWriter(htmlfname, true)));
    htmlfile.print(msg);
    htmlfile.close();
}

From source file:Main.java

private static String createPKCS11ConfigFile(String pkcs11LibPath) {
    File f = null;/* ww  w .j ava2s.  c o m*/
    PrintWriter writer = null;
    try {
        f = File.createTempFile("pkcs11", ".cfg");
        f.deleteOnExit();
        writer = new PrintWriter(new FileOutputStream(f));
        writer.println("name = verinice");
        writer.println("description = verinice PKCS#11 configuration");
        writer.println("library = " + pkcs11LibPath);
        writer.close();
    } catch (IOException e) {
        return null;
    } finally {
        if (writer != null)
            writer.close();
    }

    return f.getAbsolutePath();
}

From source file:ca.uqac.dim.net.verify.NetworkChecker.java

/**
 * Show command line usage//from   w  ww .ja  v  a  2 s  . c  om
 * @param options
 */
private static void showUsage(Options options) {
    int screen_width = 80;
    String header = "", footer = "";
    int padding_l = 1, padding_r = 1;
    HelpFormatter hf = new HelpFormatter();
    PrintWriter pw = new PrintWriter(System.err);
    hf.printHelp(pw, screen_width, "verify [-f] [-h] -i <arg> [-s]", header, options, padding_l, padding_r,
            footer);
    pw.close();
}

From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java

private static void writePatterns(List<SparqlPattern> Patterns, Language language) {
    String prefix = "\\documentclass{scrartcl}\n" + "\\usepackage{mathtools}\n" + "\\usepackage{tikz}\n"
            + "\\usetikzlibrary{trees,positioning}\n" + "\n" + "\\begin{document}\n";

    String suffix = "\\end{document}";
    String output = "";
    System.out.println("Starting visualisation");
    for (SparqlPattern pattern : Patterns) {
        String tmp = doVisual(pattern.getQuery(), pattern.getID().replace("_", "\\_")) + "\n\n\n";
        String[] triple = pattern.getQuery().split("\n");
        for (String t : triple) {
            tmp = "%" + t + "\n" + tmp;
        }/*from w w  w  . j a  va 2  s  . c om*/
        if (tmp != null)
            output += tmp;
        else
            System.out.println(pattern.getID() + " could not be visualized");
    }

    PrintWriter writer;
    try {
        writer = new PrintWriter("sparql_tree_" + language.toString() + ".tex");
        writer.write(prefix + output + suffix);
        writer.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}