List of usage examples for java.io PrintWriter close
public void close()
From source file:com.github.adam6806.mediarequest.StoreRequest.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(false); if (session != null) { } else {//www . j a va 2s. c o m try { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); response.sendRedirect("http://pirateofdw.gotdns.com/Login"); pw.close(); } catch (IOException ex) { Logger.getLogger(StoreRequest.class.getName()).log(Level.SEVERE, null, ex); } } try { connection = datasource.getConnection(); if (request.getParameter("request").equalsIgnoreCase("data-request")) { response.getWriter().write(getResultJSON(connection)); } else { String name = request.getParameter("medianame"); DSLContext create = DSL.using(connection, SQLDialect.POSTGRES); InsertSetMoreStep<RequestRecord> set = create.insertInto(REQUEST).set(REQUEST.DESCRIPTION, name) .set(REQUEST.MEDIAID, name).set(REQUEST.POSTERIMAGEURL, name).set(REQUEST.REQUESTDATE, name) .set(REQUEST.EMAIL, name).set(REQUEST.ISMOVIE, true); set.execute(); response.getWriter().write(getResultJSON(connection)); emailService.sendMail("asmith0935@gmail.com", name, name); } response.setStatus(200); } catch (SQLException | IOException ex) { Logger.getLogger(StoreRequest.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
/** Writes the class information to a file in SOMLib format. */ public static void writeAsSOMLib(SOMLibClassInformation classInfo, String fileName) throws IOException, SOMLibFileFormatException { PrintWriter writer = FileUtils.openFileForWriting("SOMLib class info", fileName); writer.println("$TYPE class_information"); writer.println("$NUM_CLASSES " + classInfo.numClasses()); writer.write("$CLASS_NAMES "); for (int i = 0; i < classInfo.numClasses(); i++) { writer.write(classInfo.getClassName(i)); if (i + 1 < classInfo.numClasses()) { writer.write(" "); }/*from w w w. ja v a 2s.c o m*/ } writer.println(); writer.println("$XDIM 2"); writer.println("$YDIM " + classInfo.numData); for (String element : classInfo.getDataNames()) { writer.println(element + " " + classInfo.getClassName(element)); } writer.flush(); writer.close(); }
From source file:com.teasoft.teavote.util.Utilities.java
public boolean restoreDB(String dbUserName, String dbPassword, String path) throws Exception { //Create a batch file String destpath = "restore_command.bat"; //creating batch file PrintWriter writer = new PrintWriter(destpath); String command = "mysql -u" + dbUserName + " -p" + dbPassword + " < \"" + path + "\""; writer.println(command);/*from www .ja v a 2s .c o m*/ writer.close(); //String executeCmd = "mysql -u" + dbUserName + " -p" + dbPassword + " < " + path; Process runtimeProcess; runtimeProcess = Runtime.getRuntime().exec(destpath); int processComplete = runtimeProcess.waitFor(); //Delete the bat file new File(destpath).delete(); return processComplete == 0; }
From source file:com.teasoft.teavote.util.Utilities.java
public boolean restoreDB2(String dbUserName, String dbPassword, String path) throws Exception { //Create a batch file String destpath = "restore_command.bat"; //creating batch file PrintWriter writer = new PrintWriter(destpath); String command = "mysql -u" + dbUserName + " -p" + dbPassword + " < \"" + path + "\""; writer.println(command);/*from w ww . j a v a 2 s .com*/ writer.close(); //String executeCmd = "mysql -u" + dbUserName + " -p" + dbPassword + " < " + path; Process runtimeProcess; runtimeProcess = Runtime.getRuntime().exec(destpath); int processComplete = runtimeProcess.waitFor(); //Delete the bat file new File(destpath).delete(); return processComplete == 0; }
From source file:com.ponysdk.core.export.xml.XMLExporter.java
public void exportXMLString(final String fileName, final String content) throws Exception { // Set MIME type to binary data to prevent opening of PDF in browser window UIContext.get().stackStreamRequest((req, response) -> { response.reset();/* ww w . j a va 2 s. com*/ response.setContentType("application/xml"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); PrintWriter printer; try { printer = response.getWriter(); printer.print(content); printer.flush(); printer.close(); } catch (final IOException e) { log.error("Error when exporting", e); } }); }
From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java
void create(String[] args) throws JDOMException, IOException { Set<String> xmls = new HashSet<String>(); if (args.length > 4) { for (int i = 4; i < args.length; i++) { xmls.add(args[i]);//from www.ja va 2s.c o m } } String result = (args.length > 4) ? merge(args[0], args[1], xmls.toArray(new String[0])) : merge(args[0], args[1]); final PrintWriter out = new PrintWriter(new FileOutputStream(args[3])); out.write(result); out.close(); }
From source file:cn.vlabs.umt.ui.actions.ManageApplicationAction.java
public ActionForward loadApp(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String idStr = request.getParameter("q"); AppService service = getAppService(); int appid = Integer.parseInt(idStr); Application app = service.getApplication(appid); String json = ""; if (app != null) { json = "[{" + "appname:'" + escape(app.getName()) + "'" + ",url:'" + escape(app.getUrl()) + "'" + ",description:'" + escape(app.getDescription()) + "'" + ",serverType:'" + escape(app.getServerType()) + "'" + ",allowOperate:" + app.isAllowOperate() + "}]"; }/*from w ww. j a v a2s . co m*/ response.setCharacterEncoding("UTF-8"); PrintWriter writer = response.getWriter(); writer.write(json); writer.close(); writer.flush(); return null; }
From source file:info.bitoo.Daemon.java
public void downloadCompleted(BiToo biToo) { logger.debug("download completed event"); PrintWriter output = (PrintWriter) biToos.remove(biToo); if (output != null) { output.println("OK"); output.flush();//ww w. j a v a 2 s . c o m output.close(); } else { logger.warn("No output for BiToo worker: [" + biToo.toString() + "]"); } biToo.destroy(); }
From source file:info.bitoo.Daemon.java
public void downloadFailed(BiToo biToo) { logger.debug("download failed event"); PrintWriter output = (PrintWriter) biToos.remove(biToo); if (output != null) { output.println("KO"); output.flush();/*from ww w. j a v a 2 s.c o m*/ output.close(); } else { logger.warn("No output for BiToo worker: [" + biToo.toString() + "]"); } biToo.destroy(); }
From source file:net.mybox.mybox.ClientStatus.java
private static void log(String message) { // TODO: change this to be a static PrintWriter opened at construction time PrintWriter out = null; try {//from w w w .j a v a2 s .c o m out = new PrintWriter(new FileWriter(logFile, true)); } catch (Exception e) { System.out.println("Unable to open log file: " + e); } out.println(message); out.close(); }