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:net.mohatu.bloocoin.miner.RegisterClass.java

private void saveBloostamp() {
    try {//from w  ww .  j  a va 2s .c o  m
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("bloostamp")));
        out.print(addr + ":" + key);
        out.close();
        MainView.loadDataPub();

    } catch (IOException e) {
        System.out.println("Saving of bloostamp file failed, check permissions.");
    }
}

From source file:cognition.pipeline.service.CoordinatorClientService.java

private void saveCoordinatesInFile(String jsonCoordinates, String fileName) {
    try {/*from w ww  .  jav a  2 s .  c  o  m*/
        PrintWriter writer = new PrintWriter(fileName, "UTF-8");
        writer.println(jsonCoordinates);
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginMobileInterceptor.java

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    AccountObj accountObj = UserAccountHttpSessionSupport.get(ServletActionContext.getRequest());
    String accountId = accountObj.getAccount();
    if (SecurityUtils.getSubject().isAuthenticated() && !StringUtils.isBlank(accountId)) {
        return actionInvocation.invoke();
    }//www . j  a v  a 2s  .  c  o  m
    String header = ServletActionContext.getRequest().getHeader("X-Requested-With");
    if ("XMLHttpRequest".equalsIgnoreCase(header)) {
        PrintWriter printWriter = ServletActionContext.getResponse().getWriter();
        printWriter.print(Constants.NO_LOGIN_JSON_DATA);
        printWriter.flush();
        printWriter.close();
        return null;
    }
    return "logout";
}

From source file:com.aptechfpt.controller.InsertSalePerson.java

private void checkEmail(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String email = request.getParameter("value");
    boolean isExisted = accountFacade.isExistedEmail(email);
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    out.print(!isExisted);/* w  w w.  ja v a 2s . c  o  m*/
    out.close();
}

From source file:com.alibaba.doris.admin.service.main.DorisAdminServlet.java

@SuppressWarnings("unchecked")
private void doResponse(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String ip = DorisConfigUtil.getIpAddr(request);
    String uuid = UUID.randomUUID().toString();
    long begin = System.currentTimeMillis();
    if (logger.isDebugEnabled()) {
        logger.debug("The request is from :" + ip + ", new assigned id is :" + uuid);
    }/*  ww w. j  av  a  2  s.co  m*/
    String resTxt = AdminServiceConstants.ADMIN_SERVICE_ERROR;
    try {

        String actionName = request.getParameter(AdminServiceConstants.ADMIN_SERVICE_ACTION_NAME);

        if (StringUtils.isNotEmpty(actionName)) {
            // get Action
            AdminServiceAction serviceAction = AdminServiceActionFactory.getAdminServiceAction(actionName);
            if (logger.isDebugEnabled()) {
                logger.debug("The action for request\"" + uuid + "\" is " + actionName);
            }
            Map<String, String[]> paramsMap = request.getParameterMap();
            Map<String, String> paras = new HashMap<String, String>();
            for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
                String paraKey = entry.getKey();
                String[] values = entry.getValue();
                if (values.length > 0) {
                    String paraValue = entry.getValue()[0];
                    paras.put(paraKey, paraValue);
                }
            }
            // used in some action
            paras.put(AdminServiceConstants.REMOTE_IP, ip);

            resTxt = serviceAction.execute(paras);

        } else {
            // return empty string for request that is not specified action name.
            resTxt = AdminServiceConstants.ADMIN_SERVICE_ERROR;
        }

    } catch (Exception e) {
        resTxt = AdminServiceConstants.ADMIN_SERVICE_ERROR;
        logger.error(e.getMessage(), e);
    }

    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/plain;charset=UTF-8");
    PrintWriter writer = response.getWriter();
    writer.write(resTxt);

    writer.close();

    if (logger.isDebugEnabled()) {
        long end = System.currentTimeMillis();
        logger.debug("The time cost for request\"" + uuid + "\" is " + (end - begin));
    }
}

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

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler redirectHandler = new ContextHandler("/" + REDIRECT) {
        @Override/*from   w ww .j a  va2s  . co m*/
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            if (redirects > 0) {
                redirects--;
                if (circular) {
                    response.sendRedirect("/" + REDIRECT);
                } else {
                    response.sendRedirect("/" + REDIRECT + "?r=" + redirects);
                }
            } else {
                response.setStatus(200);
                PrintWriter rw = response.getWriter();
                rw.write("r: " + redirects);
                rw.close();
            }
        }
    };
    return new Handler[] { redirectHandler };
}

From source file:com.bstek.dorado.view.registry.AbstractVelocityResolver.java

@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (StringUtils.isBlank(pageTemplate)) {
        throw new IllegalArgumentException("'pageTemplate' undefined.");
    }//from   w ww .  j a  v  a  2  s  . com

    org.apache.velocity.context.Context velocityContext = velocityHelper.getContext(null, request, response);
    initVelocityContext(velocityContext, request, response);

    Template template = velocityHelper.getVelocityEngine().getTemplate(pageTemplate);
    PrintWriter writer = getWriter(request, response);
    try {
        template.merge(velocityContext, writer);
    } finally {
        writer.flush();
        writer.close();
    }
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageMeasurementFilterTest.java

@Test
public void testAcceptAllLines() throws Exception {
    final java.io.File configFile = temporaryFolder.newFile("coverage.txt");
    final PrintWriter writer = new PrintWriter(configFile);
    writer.println("src/java/net/example/Foo.java;*");
    writer.close();

    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE))
            .thenReturn(configFile.getAbsolutePath());

    final IgnoreCoverageMeasurementFilter filter = new IgnoreCoverageMeasurementFilter(configuration);

    final File file = File.create("src/java/net/example/Foo.java");
    Assert.assertFalse("matching on all lines", filter.accept(file, new Measure(CoreMetrics.COVERAGE, 42.0)));
}

From source file:net.psexton.authzwriter.Main.java

/**
 * Given a String body and a file path, writes fileBody to filePath
 * @param fileBody/*from   ww  w  .  j  ava2  s  .c o  m*/
 * @param filePath 
 */
private void writeToFile(String fileBody, String filePath) {
    File file = new File(filePath);
    try {
        PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        writer.print(fileBody);
        writer.flush();
        writer.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:info.novatec.testit.livingdoc.repository.FileSystemRepositoryTest.java

private void assertSpecification(Document doc) {
    assertNotNull(doc);//  ww  w .j  a  va2  s . c o m

    StringWriter buffer = new StringWriter();
    PrintWriter writer = new PrintWriter(buffer);
    doc.print(writer);
    writer.close();

    assertEquals(specificationhtml(), buffer.toString());
}