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:org.codehaus.cargo.sample.testdata.jdbc.TestServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();

    def.setName("cargotest");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txManager.getTransaction(def);
    try {//  w  ww . j  a  v a 2s.com
        dao.create("Adrian", "Cole");

    } catch (RuntimeException ex) {
        txManager.rollback(status);
        throw ex;
    }
    txManager.commit(status);
    if (dao.selectAll().size() != 1)
        throw new RuntimeException("Commit didn't work");
    PrintWriter out = response.getWriter();
    out.print("all good!");
    out.close();
}

From source file:cn.vlabs.umt.ui.servlet.UMTPublicKeyServiceServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    UMTCredential cred = (UMTCredential) factory.getBean("UMTCredUtil");
    PublicKeyEnvelope opublickey = new PublicKeyEnvelope();
    opublickey.setAppId(cred.getUMTId());
    Date month = DateUtils.addMonths(new Date(cred.getCreateTime()), 1);
    opublickey.setValidTime(DateFormatUtils.format(month, "yyyy-MM-dd hh:mm:ss"));
    opublickey.setPublicKey(HexUtil.toHexString(cred.getUMTKey().getRSAPublic().getEncoded()));
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.write(opublickey.toXML());/*from  ww w .j  a  v a 2s  . c  o m*/
    out.flush();
    out.close();

}

From source file:be.fedict.eid.dss.sp.servlet.PkiServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOG.debug("doGet");
    String pemCertificate;//from  w w w  .  j a va 2s . c  o  m
    try {
        pemCertificate = toPem(getPrivateKeyEntry().getCertificate());
    } catch (Exception e) {
        LOG.error(e);
        return;
    }

    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    out.print(pemCertificate);
    out.close();
}

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  w  w  .  j a va  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:io.stallion.services.LogFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();
    SimpleDateFormat df = new SimpleDateFormat("MMM dd HH:mm:ss");

    String dateString = df.format(new Date(record.getMillis()));
    String classAndMethod = record.getSourceClassName() + "." + record.getSourceMethodName() + " ";
    classAndMethod = StringUtils.rightPad(classAndMethod, 50);
    sb.append(dateString).append(" ").append(record.getLevel().getLocalizedName()).append(" ")
            .append(classAndMethod).append(formatMessage(record)).append(LINE_SEPARATOR);

    if (record.getThrown() != null) {
        try {/*  ww  w  .ja v a 2s.  co  m*/
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        } catch (Exception ex) {
            // ignore
        }
    }

    return sb.toString();
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

public static void log(DoCommand dc, String message) {
    Log.i("SUTAgentAndroid", message);

    if (SUTAgentAndroid.LogCommands == false) {
        return;/*from  w  w  w .  j  av  a2 s  . c om*/
    }

    if (message == null) {
        Log.e("SUTAgentAndroid", "bad arguments in log()!");
        return;
    }
    String fileDateStr = "00";
    String testRoot = dc.GetTestRoot();
    String datestamp = dc.GetSystemTime();
    if (testRoot == null || datestamp == null) {
        Log.e("SUTAgentAndroid", "Unable to get testRoot or datestamp in log!");
        return;
    }

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
        Date dateStr = sdf.parse(datestamp);
        SimpleDateFormat sdf_file = new SimpleDateFormat("yyyy-MM-dd");
        fileDateStr = sdf_file.format(dateStr);
    } catch (ParseException pe) {
    }
    String logFile = testRoot + "/" + fileDateStr + "-sutcommands.txt";
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(new FileWriter(logFile, true));
        pw.println(datestamp + " : " + message);
    } catch (IOException ioe) {
        Log.e("SUTAgentAndroid", "exception with file writer on: " + logFile);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }

}

From source file:forge.card.CardScriptInfo.java

public boolean trySetText(String text0) {
    if (file == null) {
        return false;
    }/*from w  ww .  j  a v a 2 s  . c o m*/

    try {
        PrintWriter p = new PrintWriter(file);
        p.print(text0);
        p.close();

        text = text0;
        return true;
    } catch (final Exception ex) {
        System.err.println("Problem writing file - " + file);
        ex.printStackTrace();
        return false;
    }
}

From source file:com.google.android.gcm.demo.server.RegisterServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String regId = getParameter(req, PARAMETER_REG_ID);
    /* BEGIN MINE */
    String conType = getParameter(req, PARAMETER_CON_TYPE, "");
    if (conType.equals(PUSH)) {
        Datastore.toPush(getParameter(req, PARAMETER_OLD_ID), regId);
        PrintWriter out = resp.getWriter();
        JSONValue.writeJSONString(Datastore.getList(regId), out);
        out.close();
        return;/*from ww w.  j ava 2s  . c o m*/
    } /* END MINE */
    Datastore.register(regId);
    setSuccess(resp);
}

From source file:marytts.tools.dbselection.DatabaseSelector.java

/**
 * Print the list of selected files//from  www  .  j  a  v a2s .  c  o  m
 * 
 * @param filename the file to print to
 * @param selected the list of files
 */
private static void storeResult(String filename, Set<Integer> selected) {

    PrintWriter out;
    try {
        out = new PrintWriter(new FileWriter(new File(filename)));
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("Error storing result");
    }
    for (int sel : selected) {
        out.println(sel);
    }
    out.flush();
    out.close();
}

From source file:com.fengduo.bee.commons.exception.SystemExceptionResolver.java

/**
 * Response  responseText/*  ww  w. j  a  v  a  2  s.c  o m*/
 * 
 * @param response
 * @param errorMsg
 */
private void printJSON(HttpServletResponse response, String errorMsg) {
    response.setCharacterEncoding("UTF-8");
    try {
        PrintWriter out = response.getWriter();
        out.println(errorMsg);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}