List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:BufferedCopy.java
public static void main(String[] args) throws Exception { BufferedInputStream bis = null; BufferedOutputStream bos = null; FileInputStream fis = new FileInputStream(args[0]); bis = new BufferedInputStream(fis); FileOutputStream fos = new FileOutputStream(args[1]); bos = new BufferedOutputStream(fos); int byte_; while ((byte_ = bis.read()) != -1) bos.write(byte_); }
From source file:MainClass.java
public static void main(String args[]) { JFrame x = new JFrame("Look at me"); x.setSize(200, 300);//from w w w.j a v a 2s .c o m x.setVisible(true); x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FileOutputStream f; try { f = new FileOutputStream("Test.xml"); XMLEncoder e = new XMLEncoder(new BufferedOutputStream(f)); e.writeObject(x); e.close(); } catch (Exception e) { } }
From source file:Main.java
public static void main(String[] argv) throws Exception { MyClass o = new MyClass(); o.setProp(1);/* ww w.j av a2s.c o m*/ o.setProps(new int[] { 1, 2, 3 }); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("outfilename.xml"))); encoder.writeObject(o); encoder.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeObject(Calendar.getInstance()); out.writeObject(new BigDecimal("123.123")); out.writeInt(1);// w ww. j a va 2s .co m out.writeUTF("tutorial"); out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); BigDecimal price; int unit; String desc; Calendar date = (Calendar) in.readObject(); System.out.println(date); price = (BigDecimal) in.readObject(); unit = in.readInt(); desc = in.readUTF(); System.out.println(unit); System.out.println(desc); System.out.println(price); in.close(); }
From source file:MainClass.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);/*from w w w .j av a 2 s .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(); System.setOut(console); }
From source file:Main.java
public static void main(String[] args) throws Exception { CheckedOutputStream checksum = new CheckedOutputStream(new FileOutputStream("data.zip"), new Adler32()); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum)); int size = 0; byte[] buffer = new byte[1024]; File dir = new File("."); String[] files = dir.list();/*from w w w. j a v a 2s. c om*/ for (int i = 0; i < files.length; i++) { System.out.println("Compressing: " + files[i]); FileInputStream fis = new FileInputStream(files[i]); ZipEntry zipEntry = new ZipEntry(files[i]); zos.putNextEntry(zipEntry); while ((size = fis.read(buffer, 0, buffer.length)) > 0) { zos.write(buffer, 0, size); } zos.closeEntry(); fis.close(); } zos.close(); System.out.println("Checksum : " + checksum.getChecksum().getValue()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Junk obj1 = new Junk("A"); Junk obj2 = new Junk("B"); Junk obj3 = new Junk("V"); ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("C:/JunkObjects.bin"))); objectOut.writeObject(obj1); // Write object objectOut.writeObject(obj2); // Write object objectOut.writeObject(obj3); // Write object objectOut.close(); // Close the output stream ObjectInputStream objectIn = null; int objectCount = 0; Junk object = null;/* ww w. j a v a 2 s . c o m*/ objectIn = new ObjectInputStream(new BufferedInputStream(new FileInputStream("C:/JunkObjects.bin"))); // Read from the stream until we hit the end while (objectCount < 3) { object = (Junk) objectIn.readObject(); objectCount++; System.out.println(object); } objectIn.close(); }
From source file:PrimeWriter.java
public static void main(String[] arguments) { int[] primes = new int[400]; int numPrimes = 0; int candidate = 2; while (numPrimes < 400) { primes[numPrimes] = candidate;/*from ww w . j a va 2 s.c om*/ numPrimes++; candidate++; } try { FileOutputStream file = new FileOutputStream("p.dat"); BufferedOutputStream buff = new BufferedOutputStream(file); DataOutputStream data = new DataOutputStream(buff); for (int i = 0; i < 400; i++) data.writeInt(primes[i]); data.close(); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:Main.java
public static void main(String[] args) { int[] x = new int[] { 1, 2, 3 }; int[] y = new int[] { 4, 5, 6 }; Polygon polygon = new Polygon(x, y, x.length); try {/*from www .jav a 2 s.c o m*/ ObjectOutputStream objectOut = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("Polygons.bin"))); objectOut.writeObject(polygon); objectOut.close(); } catch (IOException e) { e.printStackTrace(System.err); } try { ObjectInputStream objectIn = new ObjectInputStream( new BufferedInputStream(new FileInputStream("Polygons.bin"))); Polygon theLine = (Polygon) objectIn.readObject(); System.out.println(theLine); objectIn.close(); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ZipOutputStream fout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(args[0]))); for (int n = 1; n < args.length; n++) { BufferedInputStream fin = new BufferedInputStream(new FileInputStream(args[n])); ZipEntry ze = new ZipEntry(rmPath(args[n])); fout.putNextEntry(ze);//from w w w . j ava2 s.c o m int i; do { i = fin.read(); if (i != -1) fout.write(i); } while (i != -1); fout.closeEntry(); fin.close(); System.out.println("Compressing " + args[n]); System.out.println( " Original Size: " + ze.getSize() + " Compressed Size: " + ze.getCompressedSize() + "\n"); } fout.close(); }