List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:com.kappaware.logtrawler.output.flow.FileJsonOutputFlow.java
public FileJsonOutputFlow(String fileName, boolean outputArray) throws IOException { super(outputArray); out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true))); log.info(String.format("Json events will be stored in to '%s'", fileName)); }
From source file:com.github.ibole.infrastructure.common.exception.MoreThrowables.java
/** * ErrorStackString.//from w w w.j av a2s. c o m */ public static String getStackTraceAsString(Throwable e) { if (e == null) { return ""; } StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); return stringWriter.toString(); }
From source file:com.ifeng.computing.batch.job.writer.NewsItemFlatFileItemWriter.java
@Override public void write(List<? extends List<NewsItem>> items) throws Exception { PrintWriter pw = new PrintWriter(new File("sub_data.csv")); StringBuilder sb = null;//from w ww . ja va2 s . c om for (List<NewsItem> news : items) { for (NewsItem item : news) { sb = new StringBuilder(""); sb.append(item.getId()); sb.append(","); sb.append(item.getCategory()); sb.append(","); sb.append(item.getHotLevel()); sb.append(","); sb.append(item.getpId()); sb.append(","); sb.append(item.getSimScore()); pw.append(sb.toString()); pw.println(); } } pw.flush(); pw.close(); }
From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java
@Override public void ticket(List<DetalleFactura> detalles) { try (PrintWriter ticket = new PrintWriter("command/ticket.200")) { DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); ticket.println("@" + (char) 28 + "T" + (char) 28 + "T"); BigDecimal descuento = new BigDecimal(BigInteger.ZERO); for (DetalleFactura detalle : detalles) { if (detalle.getDescuentoDetalle() != null) { descuento = descuento.add(detalle.getDescuentoDetalle()); }/*from w w w . j a v a 2s. c om*/ String price = null; BigDecimal sinIVA = detalle.getProducto().getPrecioVenta().subtract(detalle.getProducto() .getPrecioVenta().multiply(new BigDecimal(17.35)).divide(new BigDecimal(100))); price = sinIVA.setScale(4, RoundingMode.HALF_UP).toString(); ticket.println("B" + (char) 28 /*Abrimos linea*/ + detalle.getProducto().getDescripcion() + (char) 28 /*Nombre producto*/ + detalle.getCantidadDetalle() + ".0" + (char) 28 /*Cantidad*/ + price.replace(",", ".") + (char) 28 /*Precio unitario*/ + "21.0" + (char) 28 /*Impuestos IVA*/ + "M" + (char) 28 /*Suma monto*/ + "0.0" + (char) 28 /*Impuestos internos*/ + "0" + (char) 28 /*Parametro display*/ + "b"); /*Cierra de linea*/ } if (!descuento.equals(new BigDecimal(BigInteger.ZERO))) { ticket.println("T" + (char) 28 /*Abrimos linea descuento*/ + "Descuento: " + (char) 28 /*Texto a mostrar*/ + descuento + (char) 28 /*Monto descuento*/ + "m" + (char) 28 /*m: descuento, M: aumento*/ + "0" + (char) 28 /*parametro display*/ + "T"); /*cierre linea descuento*/ } ticket.println("E"); } catch (FileNotFoundException ex) { Logger.getLogger(FiscalDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.alibaba.otter.shared.common.utils.cmd.StreamAppender.java
public StreamAppender(OutputStream output) { this.output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output))); }
From source file:mrdshinse.md2html.util.FileUtil.java
/** * Create file by String.// www . j a v a 2s.co m * * @param file File class for output file. * @param str file content * @return Processed file */ public static File create(File file, String str) { try (PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)))) { pw.print(str); } catch (IOException ex) { LOG.error(ex); return file; } return file; }
From source file:SecureService.java
public void serve(InputStream i, OutputStream o) throws IOException { PrintWriter out = new PrintWriter(o); // Try to install our own security manager. If we can do this, // we can defeat any access control. out.println("Trying to create and install a security manager..."); try {// w ww . j a v a2 s . c o m System.setSecurityManager(new SecurityManager()); out.println("Success!"); } catch (Exception e) { out.println("Failed: " + e); } // Try to make the Server and the Java VM exit. // This is a denial of service attack, and it should not succeed! out.println(); out.println("Trying to exit..."); try { System.exit(-1); } catch (Exception e) { out.println("Failed: " + e); } // The default system policy allows this property to be read out.println(); out.println("Attempting to find java version..."); try { out.println(System.getProperty("java.version")); } catch (Exception e) { out.println("Failed: " + e); } // The default system policy does not allow this property to be read out.println(); out.println("Attempting to find home directory..."); try { out.println(System.getProperty("user.home")); } catch (Exception e) { out.println("Failed: " + e); } // Our custom policy explicitly allows this property to be read out.println(); out.println("Attempting to read service.tmp property..."); try { String tmpdir = System.getProperty("service.tmp"); out.println(tmpdir); File dir = new File(tmpdir); File f = new File(dir, "testfile"); // Check whether we've been given permission to write files to // the tmpdir directory out.println(); out.println("Attempting to write a file in " + tmpdir + "..."); try { new FileOutputStream(f); out.println("Opened file for writing: " + f); } catch (Exception e) { out.println("Failed: " + e); } // Check whether we've been given permission to read files from // the tmpdir directory out.println(); out.println("Attempting to read from " + tmpdir + "..."); try { FileReader in = new FileReader(f); out.println("Opened file for reading: " + f); } catch (Exception e) { out.println("Failed: " + e); } } catch (Exception e) { out.println("Failed: " + e); } // Close the Service sockets out.close(); i.close(); }
From source file:model.SQLiteModel.java
public static void writeLineToLog(String line) { try {/*from ww w . ja v a 2 s .co m*/ writer = new FileWriter(logPath, true); print_line = new PrintWriter(writer); print_line.println(line); writer.close(); print_line.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.stitchgalaxy.sg_manager_web.GlobalDefaultExceptionHandler.java
@ExceptionHandler(value = Exception.class) public ModelAndView defaultErrorHandler(Exception e) throws Exception { // If the exception is annotated with @ResponseStatus rethrow it and let // the framework handle it - like the OrderNotFoundException example // at the start of this post. // AnnotationUtils is a Spring Framework utility class. if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) throw e;//from ww w. j a va 2 s . co m StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); ModelAndView mav = new ModelAndView("error"); mav.addObject("stack_trace", sw.toString()); return mav; }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.MD5ChecksumCreatorFastTest.java
public void setUp() throws FileNotFoundException { PrintWriter writer = null;/*w w w. j a v a 2 s . c om*/ try { testFile = new File(TEST_FILE_NAME); //noinspection IOResourceOpenedButNotSafelyClosed writer = new PrintWriter(testFile); writer.print(TEST_CHECKSUM_TEXT); } finally { IOUtils.closeQuietly(writer); } }