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:com.myjeeva.spring.security.secureuri.SecureServerURI.java

/**
 * writes the Bad Request String in the Servlet response if condition falis
 * //from w w w.j  a v a 2 s.c om
 * @param res a {@link javax.servlet.http.HttpServletResponse} object
 * @throws IOException
 */
private void badRequest(HttpServletResponse res) throws IOException {
    res.setContentType("text/html");
    PrintWriter pw = res.getWriter();
    pw.write(BAD_REQUEST);
    pw.close();
}

From source file:se.vgregion.sitemap.servlet.DefaultSitemapServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *//*w  ww .j a v a  2 s  . com*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    getLogger().debug("doGet(): Starting to put together the sitemap.");

    long startTimeMillis = System.currentTimeMillis();

    String sitemapContent = getSitemapService().getSitemapContent();

    long endTimeMillis = System.currentTimeMillis();

    getLogger()
            .debug("Generation finished. It took: " + (endTimeMillis - startTimeMillis) / 1000 + " seconds.");

    response.setCharacterEncoding(ENCODING_UTF8);

    PrintWriter pw = response.getWriter();
    pw.write(sitemapContent);
    pw.flush();
    pw.close();
}

From source file:cat.calidos.morfeu.webapp.GenericHttpServlet.java

protected void writeTo(String content, String contentType, HttpServletResponse resp) throws IOException {

    // to simulate slowness
    //   try {/*from w w  w.j a  v a 2s.  com*/
    //      Thread.sleep(20000);
    //   } catch (InterruptedException e) {
    //      // TODO Auto-generated catch block
    //      e.printStackTrace();
    //   }
    resp.setContentType(contentType);
    PrintWriter out = resp.getWriter();
    out.print(content);
    out.close();

}

From source file:com.diversityarrays.dalclient.DalUtil.java

public static void showXmlResult(String xml, Writer w) {
    if (looksLikeDoctype(xml)) {
        // just print it!
        PrintWriter pw = new PrintWriter(w);
        pw.print(xml);//  ww w  .ja v  a 2s  .co m
        pw.close();
    } else {
        try {
            writeXmlResult(xml, w);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.undercouch.gradle.tasks.download.InterceptorTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentLengthHandler = new ContextHandler("/" + INTERCEPTOR) {
        @Override//from www . ja v  a 2s  .com
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);

            String message = UNINTERCEPTED;
            String addValue = request.getHeader(ADDITIONAL_REQUEST_HEADER_KEY);
            if (addValue != null) {
                message += ":" + addValue;
            }

            PrintWriter rw = response.getWriter();
            rw.write(message);
            rw.close();
        }
    };
    return new Handler[] { contentLengthHandler };
}

From source file:edu.clemson.cs.nestbed.server.nesc.weaver.MakefileWeaver.java

public void regenerateMakefile() throws FileNotFoundException, IOException {
    boolean append = true;
    PrintWriter out = new PrintWriter(new FileWriter(makefile, append));

    for (String i : linesAdded) {
        out.println(i);//w  w w .  j a v  a 2 s .co  m
    }

    out.close();
}

From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzDataProperties.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) {
        return;/*from  w  w w .ja va  2  s . c om*/
    }

    VitroRequest vreq = new VitroRequest(request);

    String vClassURI = vreq.getParameter("vClassURI");
    if (vClassURI == null || vClassURI.trim().equals("")) {
        return;
    }

    String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    respo += "<options>";

    // Add rdfs:label to the list
    respo += "<option>" + "<key>" + "label" + "</key>" + "<value>"
            + "http://www.w3.org/2000/01/rdf-schema#label" + "</value>" + "</option>";

    DataPropertyDao ddao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();

    Collection<DataProperty> dataProps = ddao.getDataPropertiesForVClass(vClassURI);
    Iterator<DataProperty> dataPropIt = dataProps.iterator();
    HashSet<String> dpropURIs = new HashSet<String>();
    while (dataPropIt.hasNext()) {
        DataProperty dp = dataPropIt.next();
        if (!(dpropURIs.contains(dp.getURI()))) {
            dpropURIs.add(dp.getURI());
            DataProperty dprop = (DataProperty) ddao.getDataPropertyByURI(dp.getURI());
            if (dprop != null) {
                respo += "<option>" + "<key>" + dprop.getLocalName() + "</key>" + "<value>" + dprop.getURI()
                        + "</value>" + "</option>";
            }
        }
    }
    respo += "</options>";
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    out.println(respo);
    out.flush();
    out.close();
}

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

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String keyString = request.getParameter("keyid");
    if (keyString == null) {
        wrongParameter(response);//w w w  .  ja  v  a 2s  .c  o  m
        return;
    }
    try {
        AppService service = (AppService) factory.getBean("ApplicationService");
        int keyid = -1;
        String content;
        if ("umt".equals(keyString)) {
            Application app = service.getApplication("umt");
            keyid = app.getKeyid();
            content = app.getPublicKey();
        } else {
            keyid = Integer.parseInt(keyString);
            content = service.getPublicKey(keyid);
        }
        if (content != null) {
            response.setContentType("text/plain");
            response.setHeader("keyid", Integer.toString(keyid));
            PrintWriter out = response.getWriter();
            out.write(content);
            out.flush();
            out.close();
        } else {
            notFound(response);
        }
    } catch (NumberFormatException e) {
        wrongParameter(response);
        return;
    }
}

From source file:com.cognifide.qa.bb.cumber.Bobcumber.java

private File createFile(String path) throws FileNotFoundException, UnsupportedEncodingException {
    File file = new File(path);
    if (!file.exists()) {
        PrintWriter writer = new PrintWriter(file, CharEncoding.UTF_8);
        writer.close();
    }//  w  w w  .j  a  v a  2 s.  co m
    return file;
}

From source file:joanakeyrefactoring.javaforkeycreator.JavaProjectCopyHandler.java

public void addClassToTest(List<String> classContent, StaticCGJavaClass javaClass)
        throws FileNotFoundException, IOException {
    String relPathForJavaClass = getRelPathForJavaClass(javaClass);
    String className = javaClass.getOnlyClassName();
    File relPathFile = new File(pathToNew + "/" + relPathForJavaClass);
    relPathFile.mkdirs();//from www . jav a 2  s  .  com
    File javaFile = new File(pathToNew + relPathForJavaClass + "/" + className + ".java");
    javaFile.createNewFile();
    String classFileAsOneString = "";
    for (String l : classContent) {
        classFileAsOneString += l + System.lineSeparator();
    }
    PrintWriter out = new PrintWriter(javaFile);
    out.print(classFileAsOneString);
    out.close();
}