List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.concursive.connect.web.webdav.resources.WebdavResource.java
protected void sendContentFinish(final PrintWriter printer) { printer.print("</body></html>"); printer.flush(); }
From source file:org.frat.common.exception.ExceptionResolver.java
@Override public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { if (WebUtil.isAjaxRequest(request)) { try {/*w w w.j a v a 2s. c o m*/ String formId = request.getHeader(ApplicationConstant.X_FORM_ID); Locale locale = request.getLocale(); ObjectMapper objectMapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); ResultDto error = getErrorDto(ex, handler, formId, locale); if (error.isNonBizError()) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } else { response.setStatus(HttpStatus.OK.value()); } PrintWriter writer = response.getWriter(); objectMapper.writeValue(response.getWriter(), error); writer.flush(); } catch (IOException ie) { LOGGER.error("Failed to serialize the object to json for exception handling.", ie); } return new ModelAndView(); } else { response.setContentType("text/html;charset=UTF-8"); ModelAndView mav = new ModelAndView(); mav.addObject("errorMessage", ExceptionUtils.getStackTrace(ex)); if (ex instanceof AuthorizationException) { LOGGER.warn("AuthorizationException handled (non-ajax style):", ex); mav.setViewName("error/access_denied"); } else { LOGGER.error("Unknown exception handled (non-ajax style):", ex); mav.setViewName("error/404"); } return mav; } }
From source file:cn.powerdash.libsystem.common.exception.ExceptionResolver.java
@Override public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { if (WebUtil.isAjaxRequest(request)) { try {//from w w w .ja v a 2 s.c o m String formId = request.getHeader(ApplicationConstant.X_FORM_ID); Locale locale = request.getLocale(); ObjectMapper objectMapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); ResultDto<?> error = getErrorDto(ex, handler, formId, locale); if (error.isNonBizError()) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } else { response.setStatus(HttpStatus.OK.value()); } PrintWriter writer = response.getWriter(); objectMapper.writeValue(response.getWriter(), error); writer.flush(); } catch (IOException ie) { LOGGER.error("Failed to serialize the object to json for exception handling.", ie); } return new ModelAndView(); } else { response.setContentType("text/html;charset=UTF-8"); ModelAndView mav = new ModelAndView(); mav.addObject("errorMessage", ExceptionUtils.getStackTrace(ex)); if (ex instanceof AuthorizationException) { LOGGER.warn("AuthorizationException handled (non-ajax style):", ex); mav.setViewName("error/access_denied"); } else { LOGGER.error("Unknown exception handled (non-ajax style):", ex); mav.setViewName("error/404"); } return mav; } }
From source file:io.proleap.vb6.TestGenerator.java
public static void generateTestClass(final File vb6InputFile, final File outputDirectory, final String packageName) throws IOException { final String inputFilename = getInputFilename(vb6InputFile); final File outputFile = new File( outputDirectory + "/" + inputFilename + OUTPUT_FILE_SUFFIX + JAVA_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating unit test {}.", outputFile); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); final String vb6InputFileName = vb6InputFile.getPath().replace("\\", "/"); pWriter.write("package " + packageName + ";\n"); pWriter.write("\n"); pWriter.write("import java.io.File;\n"); pWriter.write("\n"); pWriter.write("import org.junit.Test;\n"); pWriter.write("import io.proleap.vb6.runner.VbParseTestRunner;\n"); pWriter.write("import io.proleap.vb6.runner.impl.VbParseTestRunnerImpl;\n"); pWriter.write("\n"); pWriter.write("public class " + inputFilename + "Test {\n"); pWriter.write("\n"); pWriter.write(" @Test\n"); pWriter.write(" public void test() throws Exception {\n"); pWriter.write(" final File inputFile = new File(\"" + vb6InputFileName + "\");\n"); pWriter.write(" final VbParseTestRunner runner = new VbParseTestRunnerImpl();\n"); pWriter.write(" runner.parseFile(inputFile);\n"); pWriter.write(" }\n"); pWriter.write("}"); pWriter.flush(); pWriter.close();//from w w w . j av a2 s . com } }
From source file:cn.vlabs.umt.ui.actions.FindPasswordAction.java
/** * ???//from www. jav a 2 s . c o m * * */ public ActionForward sendRemindeEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("isStatic", "true"); String loginEmail = request.getParameter("loginEmail"); int uid = Integer.valueOf(request.getParameter("uid")); if (loginEmail != null) { loginEmail = loginEmail.toLowerCase(); } UserService us = getUserService(); boolean flag; if (!ValidatorFactory.getValidCodeEqualsValidator(request).validate(request.getParameter("ValidCode"))) { flag = false; } else { us.sendChangeMail(new UMTContext(request).getLocale(), uid, loginEmail, ServiceFactory.getWebUrl(request)); flag = true; } PrintWriter writer = response.getWriter(); writer.println("{\"result\":" + flag + ",\"url\":\"" + EmailUrlTagUtils.getEmailLink(loginEmail) + "\"}"); writer.flush(); writer.close(); return null; }
From source file:com.btoddb.chronicle.plunkers.FilePlunkerImpl.java
@Override protected void handleInternal(Collection<Event> events) throws Exception { for (Event event : events) { PrintWriter pw = retrievePrintWriter(tokenizedFilePath.render(event)); config.getEventSerializer().serialize(pw, event); pw.println();/*from w w w .ja v a 2s .c o m*/ pw.flush(); } }
From source file:au.com.micropacific.cordova.CipherlabRS30Plugin.java
public void initialise(CallbackContext callbackContext) { Log.v("CipherlabRS30Plugin", "CipherlabRS30Plugin.initialise()"); try {/*from w ww. jav a2 s.com*/ Log.v("CipherlabRS30Plugin", "com.cipherlab.barcode.GeneralString.Intent_SOFTTRIGGER_DATA: " + com.cipherlab.barcode.GeneralString.Intent_SOFTTRIGGER_DATA); if (cordova.getActivity() == null) { Log.v("CipherlabRS30Plugin", "cordova.getActivity() is null"); } else { Log.v("CipherlabRS30Plugin", "cordova.getActivity() is something"); } filter = new IntentFilter(); filter.addAction(com.cipherlab.barcode.GeneralString.Intent_SOFTTRIGGER_DATA); filter.addAction(com.cipherlab.barcode.GeneralString.Intent_PASS_TO_APP); filter.addAction(com.cipherlab.barcode.GeneralString.Intent_READERSERVICE_CONNECTED); mReaderManager = ReaderManager.InitInstance(cordova.getActivity()); mDataReceiver = new DataReceiver(this, this.mReaderManager); cordova.getActivity().registerReceiver(mDataReceiver, filter); Log.v("CipherlabRS30Plugin", "Got reader"); } catch (Exception e) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); printWriter.flush(); String stackTrace = writer.toString(); Log.v("CipherlabRS30Plugin", "Error starting reader manager: " + stackTrace); } Log.v("CipherlabRS30Plugin", "CipherlabRS30Plugin.initialise() Done"); callbackContext.success(); }
From source file:com.jjtree.servelet.Paragraphs.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* w w w . j a v a 2 s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); String pathInfo = request.getPathInfo(); String[] path = pathInfo.split("/"); int singleParagraphID = Integer.parseInt(path[1]); try { // Register JDBC driver Class.forName(JConstant.JDBC_DRIVER); // Open a connection conn = DriverManager.getConnection(JConstant.DB_URL, JConstant.USER, JConstant.PASSWORD); // Execute SQL query stmt = conn.createStatement(); String sql; sql = "SELECT * FROM JParagraph WHERE paragraphID = " + singleParagraphID; ResultSet rs = stmt.executeQuery(sql); // Extract data from result set while (rs.next()) { //Retrieve by column name int paragraphID = rs.getInt("paragraphID"); int articleID = rs.getInt("articleID"); int position = rs.getInt("position"); String type = rs.getString("type"); String content = rs.getString("content"); JSONObject paragraph = new JSONObject(); paragraph.put("paragraphID", paragraphID); paragraph.put("articleID", articleID); paragraph.put("position", position); paragraph.put("type", type); paragraph.put("content", content); PrintWriter writer = response.getWriter(); writer.print(paragraph); writer.flush(); } // Clean-up environment rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) { stmt.close(); } } catch (SQLException se2) { } // nothing we can do try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try }
From source file:com.redhat.rhn.taskomatic.core.BaseDaemon.java
/** * Convenience method to allow daemon implementations to log messages directly * to the host system's system log, ie not log4j or commons-logging. If a * java.lang.Throwable is passed in then the stack trace will be logged as well. * @param logLevel Desired log level/*from w w w. j av a 2 s. com*/ * @param msg Message to log * @param err Optional */ public void logMessage(int logLevel, String msg, Throwable err) { StringBuilder buf = new StringBuilder(); buf.append(msg); if (err != null) { buf.append("\n"); StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); err.printStackTrace(printWriter); printWriter.flush(); buf.append(writer.toString()); } WrapperManager.log(logLevel, buf.toString()); }
From source file:be.solidx.hot.rest.RestController.java
protected ResponseEntity<byte[]> buildErrorResponse(Exception e) { logger.error("", e); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter);// www. j av a2s. c o m printWriter.flush(); byte[] responseBytes; try { responseBytes = stringWriter.toString().getBytes(DEFAULT_CHARSET); } catch (UnsupportedEncodingException e1) { responseBytes = stringWriter.toString().getBytes(); } return new ResponseEntity<byte[]>(responseBytes, HttpStatus.INTERNAL_SERVER_ERROR); }