List of usage examples for java.io PrintWriter close
public void close()
From source file:uk.co.md87.android.common.ExceptionHandler.java
public void uncaughtException(Thread t, Throwable e) { String timestamp = String.valueOf(System.currentTimeMillis()); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter);// www . j av a2 s. c o m String stacktrace = result.toString(); printWriter.close(); String filename = timestamp + ".stacktrace"; sendToServer(stacktrace, filename); defaultUEH.uncaughtException(t, e); }
From source file:de.mpg.escidoc.services.syndication.presentation.RestServlet.java
/** * Take care on an incoming exception.//ww w . jav a2 s. c om * * @param e * exception * @param resp * response stream * @throws IOException * @throws Exception * if the handling went wrong on any reason */ private void handleException(final Exception e, final HttpServletResponse resp) throws IOException { logger.error(e.getMessage(), e); PrintWriter pw; pw = resp.getWriter(); pw.print("Error: "); e.printStackTrace(pw); pw.close(); }
From source file:com.cloudbees.jenkins.support.SupportLogFormatter.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "DE_MIGHT_IGNORE" }, justification = "The exception wasn't thrown on our stack frame") public String format(LogRecord record) { StringBuilder builder = new StringBuilder(); builder.append(fdf.format(new Date(record.getMillis()))); builder.append(" [id=").append(record.getThreadID()).append("]"); builder.append("\t").append(record.getLevel().getName()).append("\t"); if (record.getSourceMethodName() != null) { String sourceClass;//from ww w. j a v a2s. c o m if (record.getSourceClassName() == null) { sourceClass = record.getLoggerName(); } else { sourceClass = record.getSourceClassName(); } builder.append(abbreviateClassName(sourceClass, 32)).append("#").append(record.getSourceMethodName()); } else { String sourceClass; if (record.getSourceClassName() == null) { sourceClass = record.getLoggerName(); } else { sourceClass = record.getSourceClassName(); } builder.append(abbreviateClassName(sourceClass, 40)); } builder.append(": ").append(formatMessage(record)); if (record.getThrown() != null) { try { StringWriter writer = new StringWriter(); PrintWriter out = new PrintWriter(writer); record.getThrown().printStackTrace(out); out.close(); builder.append(writer.toString()); } catch (Exception e) { // ignore } } builder.append("\n"); return builder.toString(); }
From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.FileAccessServiceImpl.java
public void generateSiteFile() throws IOException { logger.info("Generate site.pp"); String fileContent = catalogManager.generateSiteStr(); logger.debug("site content: " + fileContent); logger.debug("defaultManifestsPath: " + defaultManifestsPath); try {/*from w ww . j a v a2 s . co m*/ PrintWriter writer = new PrintWriter(defaultManifestsPath + "site.pp", "UTF-8"); writer.println(fileContent); writer.close(); } catch (IOException ex) { logger.debug("Error creating site.pp file", ex); throw new IOException("Error creating site.pp file"); } logger.debug("Site.pp file created"); }
From source file:MyServlet.java
public void saveState() { FileWriter fileWriter = null; PrintWriter printWriter = null; try {/* w ww .ja v a2 s.co m*/ fileWriter = new FileWriter("InitDestroyCounter.initial"); printWriter = new PrintWriter(fileWriter); printWriter.println(count); printWriter.close(); return; } catch (IOException e) { } }
From source file:mack.servlets.TransfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TransformerException { geraXSL();/*from w w w . j a va 2 s. c o m*/ geraXML(); Source xmlSource = new StreamSource("/temp/posicao.xml"); File xslFile = new File("/temp/gpx.xsl"); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(new StreamSource(xslFile)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); trans.transform(xmlSource, new StreamResult(bos)); PrintWriter w = new PrintWriter("/temp/posicao_proc.gpx", "UTF-8"); w.print(bos); w.close(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println(new String(bos.toByteArray())); } // response.getWriter().print(bos); // request.getRequestDispatcher("mapaTeste.html").forward(request, response); }
From source file:com.greenpepper.repository.FileSystemRepositoryTest.java
private void assertSpecification(Document doc) throws IOException { assertNotNull(doc);/* w w w .j ava2 s.co m*/ StringWriter buffer = new StringWriter(); PrintWriter writer = new PrintWriter(buffer); doc.print(writer); writer.close(); assertEquals(specification(), buffer.toString()); }
From source file:com.vmware.photon.controller.api.frontend.lib.ova.OvaTestModule.java
private void generateOvaFile(String ovaName, String ovfName, String ovfContent, String vmdkName, String vmdkContent) throws IOException, InterruptedException { PrintWriter out = new PrintWriter(new File(fileLocation, ovfName)); out.print(ovfContent);/*from w ww .j a v a 2 s . c om*/ out.close(); out = new PrintWriter(new File(fileLocation, vmdkName)); out.print(vmdkContent); out.close(); Runtime.getRuntime().exec(String.format("tar cvf %s %s %s --format ustar", ovaName, ovfName, vmdkName), null, new File(fileLocation)).waitFor(); }
From source file:marytts.util.io.FileUtils.java
public static void writeTextFile(String[][] textInRows, String textFile) { PrintWriter out = null; try {/*from w ww . j a v a 2s . c om*/ out = new PrintWriter(new FileWriter(textFile)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (out != null) { for (int n = 0; n < textInRows.length; n++) { String line = ""; for (int i = 0; i < textInRows[n].length; i++) line += textInRows[n][i] + " "; out.println(line); } out.close(); } else System.out.println("Error! Cannot create file: " + textFile); }
From source file:org.opennms.features.vaadin.pmatrix.manual.PmatrixDpdCalculatorSimpleMovingAverageImplMarshalTest.java
public void testMarshalData() { System.out.println("start of test:testMarshalData()"); // check slf4j settings LOG.debug("debug message"); LOG.warn("warn message"); LOG.info("info message"); try {/*from w ww . j a v a 2 s . c o m*/ String testFileName = this.getClass().getSimpleName() + "_File.xml"; File file = new File("target/" + testFileName); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.close(); System.out.println("file location:" + file.getAbsolutePath()); JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.calculator"); // ***************** // create calculator // ***************** PmatrixDpdCalculatorSimpleMovingAvgImpl simpleMovingAvgCalc = new PmatrixDpdCalculatorSimpleMovingAvgImpl(); simpleMovingAvgCalc.setLatestDataValue(1010d); simpleMovingAvgCalc.setLatestTimestamp(new Date().getTime()); simpleMovingAvgCalc.setPrevDataValue(3040d); simpleMovingAvgCalc.setPreviousTimestamp(new Date().getTime()); NameValuePair property = new NameValuePair( PmatrixDpdCalculatorSimpleMovingAvgImpl.MAX_SAMPLE_NO_PROPERTY_NAME, "10"); simpleMovingAvgCalc.getConfiguration().add(property); for (int i = 1; i < 15; i++) { Double latestDataValue = Double.valueOf(i); Long latestTimestamp = new Date().getTime() + i; // adding to show small increment in time simpleMovingAvgCalc.updateCalculation(latestDataValue, latestTimestamp); } // ********************** // marshal test file // ********************** Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd"); jaxbMarshaller.marshal(simpleMovingAvgCalc, file); //jaxbMarshaller.marshal(pmatrixSpecificationList_context, file); // ********************** // unmarshal test file // ********************** Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller(); //Object o = jaxbUnMarshaller.unmarshal( new StringReader( marshalledXml ) ); Object o = jaxbUnMarshaller.unmarshal(file); System.out.println("o.tostring:" + o.toString()); if (o instanceof PmatrixDpdCalculatorSimpleMovingAvgImpl) { System.out.println("unmarshalled list:"); System.out.println((PmatrixDpdCalculatorSimpleMovingAvgImpl) o); } else System.out.println("cant unmarshal object:"); } catch (JAXBException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } System.out.println("end of test:testMarshalData()"); }