List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.poscoict.license.web.controller.PhotoUploadController.java
@RequestMapping(value = { "PhotoUploadHTML5" }, method = { RequestMethod.POST }) public void PhotoUploadHTML5(HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from w ww. java 2 s . c o m System.out.println("________PhotoUploadHTML5"); //? String sFileInfo = ""; String filename = request.getHeader("file-name"); String filename_ext = filename.substring(filename.lastIndexOf(".") + 1); filename_ext = filename_ext.toLowerCase(); String[] allow_file = { "jpg", "png", "bmp", "gif" }; int cnt = 0; for (int i = 0; i < allow_file.length; i++) { if (filename_ext.equals(allow_file[i])) { cnt++; } } if (cnt == 0) { PrintWriter print = response.getWriter(); print.print("NOTALLOW_" + filename); print.flush(); print.close(); } else { String dftFilePath = request.getSession().getServletContext().getRealPath("/"); String folderPath = new SimpleDateFormat("yyyyMMdd").format(new java.util.Date()); String filePath = dftFilePath + "editor" + File.separator + "multiupload" + File.separator + folderPath + File.separator; File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } String realFileNm = ""; SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); String today = formatter.format(new java.util.Date()); realFileNm = today + UUID.randomUUID().toString() + filename.substring(filename.lastIndexOf(".")); String rlFileNm = filePath + realFileNm; InputStream is = request.getInputStream(); OutputStream os = new FileOutputStream(rlFileNm); int numRead; byte b[] = new byte[Integer.parseInt(request.getHeader("file-size"))]; while ((numRead = is.read(b, 0, b.length)) != -1) { os.write(b, 0, numRead); } if (is != null) { is.close(); } os.flush(); os.close(); //backup file = new File(backupFolderHTML5 + folderPath + File.separator); if (!file.exists()) { file.mkdirs(); } fileCopy(rlFileNm, backupFolderHTML5 + folderPath + File.separator + realFileNm); System.out.println("___________rlFileNm: " + rlFileNm); System.out.println("____________backupFolderHTML5: " + backupFolderHTML5 + folderPath + File.separator + realFileNm); String serverPath = request.getContextPath(); sFileInfo += "&bNewLine=true"; sFileInfo += "&sFileName=" + filename; sFileInfo += "&sFileURL=" + serverPath + "/editor/multiupload/" + folderPath + "/" + realFileNm; PrintWriter print = response.getWriter(); print.print(sFileInfo); print.flush(); print.close(); } } catch (Exception e) { e.getStackTrace(); } }
From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginInterceptor.java
private String redirectLogin(Map<String, Object> session, boolean getUserCurrentCookieFail) throws Exception { SecurityUtils.getSubject().logout(); if (session != null) { UserAccountHttpSessionSupport.remove(session); }//from w ww .j av a 2 s .c om String header = ServletActionContext.getRequest().getHeader("X-Requested-With"); String isDojoContentPaneXhrLoad = ServletActionContext.getRequest() .getParameter(Constants.IS_DOJOX_CONTENT_PANE_XHR_LOAD); if ("XMLHttpRequest".equalsIgnoreCase(header) && !YesNo.YES.equals(isDojoContentPaneXhrLoad)) { PrintWriter printWriter = ServletActionContext.getResponse().getWriter(); printWriter.print(Constants.NO_LOGIN_JSON_DATA); printWriter.flush(); printWriter.close(); return null; } if (YesNo.YES.equals(isDojoContentPaneXhrLoad)) { if (getUserCurrentCookieFail) { return Constants._S2_RESULT_LOGOUT_AGAIN; } return Constants._S2_RESULT_LOGIN_AGAIN; } if (getUserCurrentCookieFail) { return "logout"; } return "login"; }
From source file:de.betterform.agent.web.servlet.XFormsErrorServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.reset();//from w w w . j a va2s. com response.resetBuffer(); response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println(getHtmlhead(request.getContextPath())); writer.println(getHTML(request)); writer.println(HTMLFOOT); writer.flush(); response.getOutputStream().close(); }
From source file:org.posterita.core.AbstractChart.java
public void writeImageMap(OutputStream outputStream, String imageMapName) throws OperationException { PrintWriter printWriter = new PrintWriter(outputStream); try {//from w w w .j av a2 s . c o m ChartUtilities.writeImageMap(printWriter, imageMapName, renderingInfo, false); printWriter.flush(); printWriter.close(); } catch (IOException e) { throw new OperationException("Problem occured while writing imagemap", e); } }
From source file:org.apache.solr.client.solrj.impl.BackupRequestLBHttpSolrServer.java
@Override protected Exception addZombie(HttpSolrServer server, Exception e) { CharArrayWriter cw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(cw); e.printStackTrace(pw);/*w ww . jav a 2 s . co m*/ pw.flush(); String stack = cw.toString(); log.info("Server :{} did not respond correctly or timed out, the server is zombied. {}", server.baseUrl, e.toString() + stack); return super.addZombie(server, e); }
From source file:au.edu.unsw.cse.soc.federatedcloud.community.driven.cloudbase.connectors.docker.DockerConnector.java
private File writeStringToFile(String fileName, String fileContent) { File file = new File(fileName); boolean dirCreated = file.getParentFile().mkdirs(); PrintWriter out = null; try {//from w w w . j av a 2 s. co m out = new PrintWriter(file); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } out.println(fileContent); out.flush(); out.close(); return file; }
From source file:application.controllers.admin.EmotionList.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //upload image to browser for add emotions //upload image to browser for add emotions if (!ServletFileUpload.isMultipartContent(request)) { PrintWriter writer = response.getWriter(); writer.println("Request does not contain upload data"); writer.flush(); return;//from w w w . ja v a 2 s . com } // configures upload settings DiskFileItemFactory factory = new DiskFileItemFactory(); // maximum size that will be stored in memory factory.setSizeThreshold(UploadConstant.THRESHOLD_SIZE); // Location to save data that is larger than maxMemSize. factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // maximum file size to be uploaded. upload.setFileSizeMax(UploadConstant.MAX_FILE_SIZE); upload.setSizeMax(UploadConstant.MAX_REQUEST_SIZE); // constructs the directory path to store upload file // String uploadPath = Registry.get("Host") +"/emotions-image/"+ UPLOAD_DIRECTORY; String uploadPath = Registry.get("imageHost") + "/emotions-image/" + UploadConstant.UPLOAD_DIRECTORY; // creates the directory if it does not exist File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdir(); } //list image user upload String[] arrLinkImage = null; try { int indexImage = 0; // parses the request's content to extract file data List formItems = upload.parseRequest(request); arrLinkImage = new String[formItems.size()]; Iterator iter = formItems.iterator(); // iterates over form's fields while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); // processes only fields that are not form fields if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); String extensionImage = ""; for (int i = fileName.length() - 1; i >= 0; i--) { if (fileName.charAt(i) == '.') { break; } else { extensionImage = fileName.charAt(i) + extensionImage; } } String filePath = uploadPath + File.separator + fileName; File storeFile = new File(filePath); String contentType = item.getContentType(); boolean isInMemory = item.isInMemory(); long sizeInBytes = item.getSize(); String fieldName = item.getFieldName(); // saves the file on disk item.write(storeFile); arrLinkImage[indexImage++] = item.getName(); } } } catch (Exception ex) { request.setAttribute("message", "There was an error: " + ex.getMessage()); } // request.setAttribute("arrLinkImage", arrLinkImage); // RequestDispatcher rd = request.getRequestDispatcher("/groupEmotion/emotion/add"); // rd.forward(request, response); // String sessionId = request.getAttribute("sessionIdAdmin").toString(); String sessionId = request.getSession().toString(); String groupId = request.getParameter("groupId"); Memcached.set("arrLinkImage-" + sessionId, 3600, arrLinkImage); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", Registry.get("Host") + "/groupEmotion/emotion/add?groupId=" + groupId); response.setContentType("text/html"); }
From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java
private void printXml(HttpServletRequest request, HttpServletResponse response, String doc, UrlBuilder baseUrl) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/xml"); response.setCharacterEncoding(IOUtils.UTF8); String respDoc = doc;/*from www . jav a2 s.c om*/ respDoc = BASE_PATTERN.matcher(respDoc).replaceAll(baseUrl.toString()); respDoc = CORE_PATTERN.matcher(respDoc) .replaceAll((new UrlBuilder(baseUrl)).addPath("cmis").addParameter("core").toString()); respDoc = MSG_PATTERN.matcher(respDoc) .replaceAll((new UrlBuilder(baseUrl)).addPath("cmis").addParameter("msg").toString()); PrintWriter pw = response.getWriter(); pw.print(respDoc); pw.flush(); }
From source file:me.tfeng.toolbox.dust.NodeEngine.java
private JsonNode evaluate(Process process, String template, String data) throws IOException { PrintWriter writer = new PrintWriter(process.getOutputStream()); writer.println("["); printRenderScript(writer, template, data); writer.println("]"); writer.println("1"); writer.flush(); String result = readInput(process, "1"); JsonParser parser = new JsonFactory().createParser(result).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);/*from w ww.ja v a 2 s .c o m*/ ArrayNode arrayNode = OBJECT_MAPPER.readValue(parser, ArrayNode.class); return arrayNode.get(0); }
From source file:chat.com.server.ChatServer.java
private void typeChat(String msg) { try {/*from w w w . j av a2 s.c o m*/ JSONParser jsonParser = new JSONParser(); JSONObject jsonTypeChat = (JSONObject) jsonParser.parse(msg); String type = jsonTypeChat.get("type").toString(); if (type.equals("clientout")) { String idClientOut = jsonTypeChat.get("id").toString(); someQuit(idClientOut); } else { // send message String to = jsonTypeChat.get("to").toString(); String id = jsonTypeChat.get("id").toString(); if (!to.equals("all")) { PrintWriter writer = map.get(to); writer.println(msg); writer.flush(); jTextAreaChat.append(msg + '\n'); } else { for (String key : map.keySet()) { if (!id.equals(key)) { // send message to all PrintWriter writer = map.get(key); writer.println(msg); writer.flush(); jTextAreaChat.append(msg + '\n'); } } } } } catch (ParseException ex) { Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex); } }