List of usage examples for java.io PrintWriter close
public void close()
From source file:presentation.webgui.vitroappservlet.VisualStyles.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); this.uStyleId = request.getParameter("suid"); Model3dStylesList myStylesIndex = Model3dStylesList.getModel3dStylesList(); Model3dStylesEntry currStyleEntry = myStylesIndex.getStyleWithId(this.uStyleId); if (currStyleEntry != null) { response.setContentType("image/png"); OutputStream out = response.getOutputStream(); try {/*from ww w .j av a 2 s.c o m*/ JFreeChart chart = StyleCreator.createDatasetAndChart(currStyleEntry); int chartHeight = 40; if (chart.getCategoryPlot().getDataset().getColumnKeys().size() > 1) { chartHeight = chart.getCategoryPlot().getDataset().getColumnKeys().size() * 22; } ChartUtilities.writeChartAsPNG(out, chart, 300, chartHeight); } catch (Exception e) { System.err.println(e.toString()); response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>Error</b>:" + e.toString()); outPrintWriter.flush(); outPrintWriter.close(); } finally { out.close(); } return; } else { response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>No style defined</b>"); outPrintWriter.flush(); outPrintWriter.close(); } }
From source file:edu.vt.vbi.patric.portlets.DataLanding.java
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); String windowID = request.getWindowID(); PortletRequestDispatcher prd;/*from w w w .j a v a 2 s .c o m*/ if (windowID.indexOf("Genomes") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "genomes.json"); request.setAttribute("jsonData", jsonData); request.setAttribute("ftpUrl", ftpUrl); response.setTitle("Genomes"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Genomes.jsp"); prd.include(request, response); } else if (windowID.indexOf("GenomicFeatures") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "features.json"); request.setAttribute("jsonData", jsonData); request.setAttribute("ftpUrl", ftpUrl); response.setTitle("Features"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/GenomicFeatures.jsp"); prd.include(request, response); } else if (windowID.indexOf("SpecialtyGenes") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "specialtygenes.json"); request.setAttribute("jsonData", jsonData); response.setTitle("Specialty Genes"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/SpecialtyGenes.jsp"); prd.include(request, response); } else if (windowID.indexOf("AntibioticResistance") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "antibioticresistance.json"); request.setAttribute("jsonData", jsonData); response.setTitle("Antibiotic Resistance"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/AntibioticResistance.jsp"); prd.include(request, response); } else if (windowID.indexOf("ProteinFamilies") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "proteinfamilies.json"); request.setAttribute("jsonData", jsonData); request.setAttribute("ftpUrl", ftpUrl); response.setTitle("Protein Families"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/ProteinFamilies.jsp"); prd.include(request, response); } else if (windowID.indexOf("Transcriptomics") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "transcriptomics.json"); request.setAttribute("jsonData", jsonData); response.setTitle("Transcriptomics"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Transcriptomics.jsp"); prd.include(request, response); } else if (windowID.indexOf("Proteomics") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "proteomics.json"); request.setAttribute("jsonData", jsonData); response.setTitle("Proteomics"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Proteomics.jsp"); prd.include(request, response); } else if (windowID.indexOf("PPInteractions") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "ppinteractions.json"); request.setAttribute("jsonData", jsonData); response.setTitle("Protein Protein Interactions"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/PPInteractions.jsp"); prd.include(request, response); } else if (windowID.indexOf("Pathways") >= 1) { JSONObject jsonData = readJsonData(request, JsonDataRoot + "pathways.json"); request.setAttribute("jsonData", jsonData); request.setAttribute("ftpUrl", ftpUrl); response.setTitle("Pathways"); prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Pathways.jsp"); prd.include(request, response); } else { PrintWriter writer = response.getWriter(); writer.write(" "); writer.close(); } }
From source file:elkfed.mmax.visualize.Page.java
public void writeHTML(String fname) throws FileNotFoundException { PrintWriter out = new PrintWriter( new OutputStreamWriter(new FileOutputStream(new File(fname)), Charset.forName("ISO-8859-15"))); writeHTML(out);//from w w w . ja v a2s. c o m out.close(); }
From source file:model.settings.ReadSettings.java
private static void installWindows() { /*/* www . j a va 2 s .c o m*/ * setting up "open with" links for paint. * Therefore request SUDO rights. */ try { final String userHome = System.getProperty("user.home"); final boolean openWith = false; // not implemented yet. if (openWith) { final String localDest = userHome + "/paint.desktop"; final String finalDest = "/usr/share/applications/paint.desktop"; Util.exportResource("/res/files/paint.desktop", localDest); String passwd = ""; /* * Check whether the execution was successfully (and the password * was correct) or the file already exists */ while (!new File(finalDest).exists()) { /* * Request SUDO privileges. */ passwd = Util.requestSudoRights("mv " + localDest + " " + finalDest); if (passwd.equals("")) { JOptionPane.showMessageDialog(null, "installation failed due to lack of privileges."); return; } try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } String passwd = Util.requestSudoRights("echo hier"); /* * Copy jar file */ /////////////////////////Path for jar file./////////////////// // /usr/lib/paint/paint.jar requests sudo rights. // because of this, each time an update is done these rights // have to be requested. Thus chose another path: // ~/.PaintUni/paint.jar // (PROGRAM_LOCATION/paint.jar) /* * STEP 2: Create (executable) file which is called if the * application is run. */ final String dest_jar_file = PROGRAM_LOCATION + "paint.jar"; final String dest_exec = "/usr/bin/paint"; String orig_jar_file = URLDecoder.decode(ClassLoader.getSystemClassLoader().getResource(".").getPath(), "UTF-8"); // if Eclipse on-the-fly-compiling final String eclipseSubstring = "target/classes/"; if (orig_jar_file.endsWith(eclipseSubstring)) { orig_jar_file = orig_jar_file.substring(0, orig_jar_file.length() - eclipseSubstring.length()); } orig_jar_file += "paint.jar"; /* * Step 3: Copy .jar file to the destination. */ final String command1 = "cp " + "\"" + orig_jar_file + "\"" + " " + "\"" + dest_jar_file + "\""; String ret1 = Util.executeCommandLinux(command1); System.out.println(command1 + "" + ret1); final String content = "#!/bin/bash \n" + "java -jar " + dest_jar_file + " $1"; PrintWriter writer = new PrintWriter(userHome + "/paint", "UTF-8"); writer.println(content); writer.close(); final String command = "mv " + userHome + "/paint " + dest_exec; Util.execSudoCommand(command, passwd); // if the password was not correct / no sudo rights if (!new File(dest_exec).exists()) { while (!new File(dest_exec).exists()) { /* * Request SUDO privileges. */ passwd = Util.requestSudoRights(command); if (passwd.equals("")) { JOptionPane.showMessageDialog(null, "installation failed due to lack of privileges."); return; } try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Util.execSudoCommand("chmod a+x " + dest_exec, passwd); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.moss.appkeep.server.HttpPublisher.java
private void completeWithError(String message, int code, HttpServletResponse response) throws IOException { response.setStatus(code);//w w w .j a v a2 s . c o m PrintWriter w = response.getWriter(); w.write(message); w.close(); }
From source file:gool.generator.cpp.CppCodePrinter.java
@Override public List<File> printGoolLibraryClass(ClassDef pclass) throws FileNotFoundException { String goolClass = pclass.getPackageName() + "." + pclass.getName(); ArrayList<String> goolClassImplems = new ArrayList<String>(); for (String Import : GeneratorMatcher.matchImports(goolClass)) if (Import.startsWith("+")) goolClassImplems.add(Import.substring(1)); List<File> result = new ArrayList<File>(); for (String goolClassImplem : goolClassImplems) { String goolClassImplemName = goolClassImplem.substring(goolClassImplem.lastIndexOf(".") + 1); String goolClassImplemPackage = goolClassImplem.substring(0, goolClassImplem.lastIndexOf(".")); String implemFileName = goolClassImplemName + ".cpp"; String headerFileName = goolClassImplemName + ".h"; String codeImplem = GeneratorMatcher.matchGoolClassImplementation(goolClass, implemFileName); String codeHeader = GeneratorMatcher.matchGoolClassImplementation(goolClass, headerFileName); File dir = new File(getOutputDir().getAbsolutePath(), StringUtils.replace(goolClassImplemPackage, ".", File.separator)); dir.mkdirs();//from w ww. java 2s.c o m File implemFile = new File(dir, implemFileName); File headerFile = new File(dir, headerFileName); //print implementation file PrintWriter writer = new PrintWriter(implemFile); writer.println(codeImplem); writer.close(); //print header file writer = new PrintWriter(headerFile); writer.println(codeHeader); writer.close(); } printedClasses.add(pclass); return result; }
From source file:com.grantedbyme.example.ServletAjax.java
public void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json; charset=UTF-8"); String operation = request.getParameter("operation"); int challengeType = Integer.valueOf(request.getParameter("challenge_type")); Boolean isSuccess = false;/*w ww. j a v a2s . c om*/ JSONObject result = null; JSONObject defaultResult = null; try { defaultResult = (JSONObject) new JSONParser().parse("{\"success\": false, \"error\": 0}"); } catch (Exception e) { e.printStackTrace(); } if (operation != null) { _log(operation); GrantedByMe sdk = ServletUtils.getSDK(this); //sdk.setDebugMode(true); // process operation String challenge = null; if (operation.equals("getChallenge")) { result = sdk.getChallenge(challengeType); } else if (operation.equals("getChallengeState")) { challenge = request.getParameter("challenge"); result = sdk.getChallengeState(challenge); if (challengeType == GrantedByMe.CHALLENGE_AUTHORIZE) { handleGetAccountState(result, challenge, sdk); } else if (challengeType == GrantedByMe.CHALLENGE_AUTHENTICATE) { handleGetSessionState(result); } else if (challengeType == GrantedByMe.CHALLENGE_PROFILE) { handleGetRegisterState(result, challenge, sdk); } } } if (result == null) { result = defaultResult; } PrintWriter out = response.getWriter(); out.print(result.toJSONString()); out.close(); }
From source file:cloudlens.engine.CL.java
public void export(String path) throws IOException { final BlockObject log = cl.get("log"); final Gson gson = new GsonBuilder().setPrettyPrinting().create(); final String prettyOutput = gson.toJson(log); final PrintWriter writer = new PrintWriter(path); writer.println(prettyOutput);//from w w w . j a v a2 s . c om writer.close(); }
From source file:com.ibm.liberty.starter.api.v1.LibertyFileUploader.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String tech = request.getParameter(PARAMETER_TECH); String workspaceId = request.getParameter(PARAMETER_WORKSPACE); //specify the unique workspace directory to upload the file(s) to. Collection<Part> filePartCollection = request.getParts(); String serverHostPort = request.getRequestURL().toString().replace(request.getRequestURI(), ""); int schemeLength = request.getScheme().toString().length(); String internalHostPort = "http" + serverHostPort.substring(schemeLength); log.log(Level.FINER, "serverHostPort : " + serverHostPort); final ServiceConnector serviceConnector = new ServiceConnector(serverHostPort, internalHostPort); HashMap<Part, String> fileNames = new HashMap<Part, String>(); if (!isValidRequest(request, response, tech, workspaceId, filePartCollection, serviceConnector, fileNames)) {//from w ww . ja v a2s.com return; } Service techService = serviceConnector.getServiceObjectFromId(tech); String techDirPath = StarterUtil.getWorkspaceDir(workspaceId) + "/" + techService.getId(); File techDir = new File(techDirPath); if (techDir.exists() && techDir.isDirectory() && "true".equalsIgnoreCase(request.getParameter(PARAMETER_CLEANUP))) { FileUtils.cleanDirectory(techDir); log.log(Level.FINER, "Cleaned up tech workspace directory : " + techDirPath); } for (Part filePart : filePartCollection) { if (!techDir.exists()) { FileUtils.forceMkdir(techDir); log.log(Level.FINER, "Created tech directory :" + techDirPath); } String filePath = techDirPath + "/" + fileNames.get(filePart); log.log(Level.FINER, "File path : " + filePath); File uploadedFile = new File(filePath); Files.copy(filePart.getInputStream(), uploadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); log.log(Level.FINE, "Copied file to " + filePath); } if ("true".equalsIgnoreCase(request.getParameter(PARAMETER_PROCESS))) { // Process uploaded file(s) String processResult = serviceConnector.processUploadedFiles(techService, techDirPath); if (!processResult.equalsIgnoreCase("success")) { log.log(Level.INFO, "Error processing the files uploaded to " + techDirPath + " : Result=" + processResult); response.sendError(500, processResult); return; } log.log(Level.FINE, "Processed the files uploaded to " + techDirPath); } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("success"); out.close(); }
From source file:com.kdab.daytona.Logger.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Use PUT to deliver content to notify"); out.flush();//from w ww . ja v a 2 s . c om out.close(); }