List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:OutputStreamDemo.java
public static void main(String[] args) throws IOException { OutputStream os1 = new FileOutputStream("tmp1.dat"); writeints("Unbuffered: ", 1000000, os1); OutputStream os2 = new BufferedOutputStream(new FileOutputStream("tmp2.dat")); writeints("Buffered: ", 1000000, os2); Writer wr1 = new FileWriter("tmp1.dat"); writeints("Unbuffered: ", 1000000, wr1); Writer wr2 = new BufferedWriter(new FileWriter("tmp2.dat")); writeints("Buffered: ", 1000000, wr2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, null);// w ww .j a v a2s .c o m pjDone.waitForDone(); is.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); DocPrintJob job = service.createPrintJob(); PrintJobAttributeSet set = new HashPrintJobAttributeSet(job.getAttributes()); set.add(new JobMediaSheetsCompleted(0)); job.addPrintJobAttributeListener(new MyPrintJobAttributeListener(), set); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); final DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; try {//from w w w . j a v a 2s . c o m cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); if (factories.length > 0) { StreamPrintService service = factories[0].getPrintService(fos); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, null);/*from ww w .jav a2s .com*/ pjDone.waitForDone(); } is.close(); fos.close(); }
From source file:org.jfree.chart.demo.MeterChartDemo4.java
public static void main(String args[]) { DefaultValueDataset defaultvaluedataset = new DefaultValueDataset(75D); MeterPlot meterplot = new MeterPlot(defaultvaluedataset); JFreeChart jfreechart = new JFreeChart("Scaled Image Test", meterplot); try {//from w w w . j a v a 2 s .c o m File file = new File("meterchart100.png"); BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(new FileOutputStream(file)); java.awt.image.BufferedImage bufferedimage = jfreechart.createBufferedImage(200, 200, 400D, 400D, null); ChartUtilities.writeBufferedImageAsPNG(bufferedoutputstream, bufferedimage); } catch (IOException ioexception) { System.out.println(ioexception.toString()); } }
From source file:Redirecting.java
public static void main(String[] args) throws IOException { PrintStream console = System.out; BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java")); PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out"))); System.setIn(in);/*w w w.ja v a 2s . co m*/ System.setOut(out); System.setErr(out); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = br.readLine()) != null) System.out.println(s); out.close(); // Remember this! System.setOut(console); }
From source file:Main.java
public static void main(String[] args) throws IOException { FileOutputStream f = new FileOutputStream("test.zip"); CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32()); ZipOutputStream zos = new ZipOutputStream(csum); BufferedOutputStream out = new BufferedOutputStream(zos); zos.setComment("A test of Java Zipping"); for (int i = 0; i < args.length; i++) { System.out.println("Writing file " + args[i]); BufferedReader in = new BufferedReader(new FileReader(args[i])); zos.putNextEntry(new ZipEntry(args[i])); int c;/*from w w w . ja va 2 s . co m*/ while ((c = in.read()) != -1) out.write(c); in.close(); } out.close(); System.out.println("Checksum: " + csum.getChecksum().getValue()); System.out.println("Reading file"); FileInputStream fi = new FileInputStream("test.zip"); CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32()); ZipInputStream in2 = new ZipInputStream(csumi); BufferedInputStream bis = new BufferedInputStream(in2); ZipEntry ze; while ((ze = in2.getNextEntry()) != null) { System.out.println("Reading file " + ze); int x; while ((x = bis.read()) != -1) System.out.write(x); } System.out.println("Checksum: " + csumi.getChecksum().getValue()); bis.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { try {/* www.j a v a 2s . c o m*/ OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); final DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; try { cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); } catch (PrintException e) { if (e.getCause() instanceof PrinterAbortException) { System.out.println("Print job was cancelled"); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ZipFile zf = new ZipFile("a.zip"); Enumeration<? extends ZipEntry> files = zf.entries(); while (files.hasMoreElements()) { ZipEntry ze = files.nextElement(); System.out.println("Decompressing " + ze.getName()); System.out.println(//from w w w.j a va2 s. c o m " Compressed Size: " + ze.getCompressedSize() + " Expanded Size: " + ze.getSize() + "\n"); BufferedInputStream fin = new BufferedInputStream(zf.getInputStream(ze)); BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(ze.getName())); int i; do { i = fin.read(); if (i != -1) fout.write(i); } while (i != -1); fout.close(); fin.close(); } zf.close(); }