List of usage examples for java.io FileOutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this file output stream. From source file:Copy.java
public static void main(String[] args) throws Exception { FileInputStream fis = null;// w w w. j a v a 2 s.c o m FileOutputStream fos = null; fis = new FileInputStream(args[0]); fos = new FileOutputStream(args[1]); int byte_; while ((byte_ = fis.read()) != -1) fos.write(byte_); }
From source file:com.npower.dm.util.XMLPrettyFormatter.java
/** * TestCase & Demo.//from w w w . j av a2 s . com * @param args */ public static void main(String[] args) { try { //String text = "<A><B></B></A>"; //XMLPrettyFormatter formatter = new XMLPrettyFormatter(text); File file = new File("D:/Zhao/MyWorkspace/nWave-DM-Common/metadata/ddf/sony_ericsson/M600_DDF.xml"); XMLPrettyFormatter formatter = new XMLPrettyFormatter(file); String result = formatter.format(); FileOutputStream out = new FileOutputStream("C:/temp/M600_DDF.xml"); out.write(result.getBytes()); out.close(); } catch (DocumentException e) { log.info("XMLPrettyFormatter:" + e); } catch (IOException e) { log.info("XMLPrettyFormatter:" + e); } }
From source file:controller.tempClass.java
/** * @desc Image manipulation - Conversion * * @filename ImageManipulation.java/* w w w. j a va 2 s. c o m*/ * @author Jeevanandam M. (jeeva@myjeeva.com) * @copyright myjeeva.com */ public static void main(String[] args) { File file = new File("E:\\Photograph\\Temporary\\mshien.jpg"); try { // Reading a Image file from file system FileInputStream imageInFile = new FileInputStream(file); byte imageData[] = new byte[(int) file.length()]; imageInFile.read(imageData); // Converting Image byte array into Base64 String System.out.println(encodeImage(imageData)); String imageDataString = encodeImage(imageData); // Converting a Base64 String into Image byte array byte[] imageByteArray = decodeImage(imageDataString); // Write a image byte array into file system FileOutputStream imageOutFile = new FileOutputStream("C:\\Users\\doanvanthien\\Desktop\\LOGO.png"); imageOutFile.write(imageByteArray); imageInFile.close(); imageOutFile.close(); System.out.println("Image Successfully Manipulated!"); } catch (FileNotFoundException e) { System.out.println("Image not found" + e); } catch (IOException ioe) { System.out.println("Exception while reading the Image " + ioe); } }
From source file:Main.java
public static void main(String[] args) throws IOException { ZipFile zf = new ZipFile("a.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); FileOutputStream fout = new FileOutputStream(ze.getName()); InputStream in = zf.getInputStream(ze); for (int c = in.read(); c != -1; c = in.read()) { fout.write(c); }//from w ww . ja va2 s .c o m in.close(); fout.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { ZipFile zf = new ZipFile(args[0]); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); InputStream in = zf.getInputStream(ze); for (int c = in.read(); c != -1; c = in.read()) { fout.write(c); }/*w w w . j a v a2s. c o m*/ in.close(); fout.close(); } }
From source file:Main.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].toLowerCase().endsWith(".dfl")) { try { FileInputStream fin = new FileInputStream(args[i]); InflaterInputStream iis = new InflaterInputStream(fin); FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 4)); for (int c = iis.read(); c != -1; c = iis.read()) { fout.write(c); }/*from ww w . ja v a 2 s. c o m*/ fout.close(); } catch (IOException ex) { System.err.println(ex); } } else { System.err.println(args[i] + " does not appear to be a deflated file."); } } }
From source file:MainClass.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].toLowerCase().endsWith(".gz")) { try { FileInputStream fin = new FileInputStream(args[i]); GZIPInputStream gzin = new GZIPInputStream(fin); FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3)); for (int c = gzin.read(); c != -1; c = gzin.read()) { fout.write(c); }//from ww w . ja va 2s. c o m fout.close(); } catch (IOException ex) { System.err.println(ex); } } else { System.err.println(args[i] + " does not appear to be a gzipped file."); } } }
From source file:GenSig.java
public static void main(String[] args) { /* Generate a DSA signature */ if (args.length != 1) { System.out.println("Usage: GenSig nameOfFileToSign"); } else/*from ww w . j a v a2s . c o m*/ try { /* Generate a key pair */ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); keyGen.initialize(1024, random); KeyPair pair = keyGen.generateKeyPair(); PrivateKey priv = pair.getPrivate(); PublicKey pub = pair.getPublic(); /* * Create a Signature object and initialize it with the private * key */ Signature dsa = Signature.getInstance("SHA1withDSA", "SUN"); dsa.initSign(priv); /* Update and sign the data */ FileInputStream fis = new FileInputStream(args[0]); BufferedInputStream bufin = new BufferedInputStream(fis); byte[] buffer = new byte[1024]; int len; while (bufin.available() != 0) { len = bufin.read(buffer); dsa.update(buffer, 0, len); } ; bufin.close(); /* * Now that all the data to be signed has been read in, generate * a signature for it */ byte[] realSig = dsa.sign(); /* Save the signature in a file */ FileOutputStream sigfos = new FileOutputStream("sig"); sigfos.write(realSig); sigfos.close(); /* Save the public key in a file */ byte[] key = pub.getEncoded(); FileOutputStream keyfos = new FileOutputStream("suepk"); keyfos.write(key); keyfos.close(); } catch (Exception e) { System.err.println("Caught exception " + e.toString()); } }
From source file:bigfat.hadoop.HDFSDirInputStream.java
/** * Test case, input int dir wants to read and the file to output * //from w w w . java2 s.c o m * @param args * @throws IOException */ public static void main(String args[]) throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); HDFSDirInputStream inp = new HDFSDirInputStream(fs, args[0]); FileOutputStream ops = new FileOutputStream(args[1]); int r; while ((r = inp.read()) != -1) { ops.write(r); } ops.close(); }
From source file:com.rabbitmq.examples.FileConsumer.java
public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "uri", true, "AMQP URI")); options.addOption(new Option("q", "queue", true, "queue name")); options.addOption(new Option("t", "type", true, "exchange type")); options.addOption(new Option("e", "exchange", true, "exchange name")); options.addOption(new Option("k", "routing-key", true, "routing key")); options.addOption(new Option("d", "directory", true, "output directory")); CommandLineParser parser = new GnuParser(); try {/*from w ww. ja v a 2 s . co m*/ CommandLine cmd = parser.parse(options, args); String uri = strArg(cmd, 'h', "amqp://localhost"); String requestedQueueName = strArg(cmd, 'q', ""); String exchangeType = strArg(cmd, 't', "direct"); String exchange = strArg(cmd, 'e', null); String routingKey = strArg(cmd, 'k', null); String outputDirName = strArg(cmd, 'd', "."); File outputDir = new File(outputDirName); if (!outputDir.exists() || !outputDir.isDirectory()) { System.err.println("Output directory must exist, and must be a directory."); System.exit(2); } ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUri(uri); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); String queueName = (requestedQueueName.equals("") ? ch.queueDeclare() : ch.queueDeclare(requestedQueueName, false, false, false, null)).getQueue(); if (exchange != null || routingKey != null) { if (exchange == null) { System.err.println("Please supply exchange name to bind to (-e)"); System.exit(2); } if (routingKey == null) { System.err.println("Please supply routing key pattern to bind to (-k)"); System.exit(2); } ch.exchangeDeclare(exchange, exchangeType); ch.queueBind(queueName, exchange, routingKey); } QueueingConsumer consumer = new QueueingConsumer(ch); ch.basicConsume(queueName, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); Map<String, Object> headers = delivery.getProperties().getHeaders(); byte[] body = delivery.getBody(); Object headerFilenameO = headers.get("filename"); String headerFilename = (headerFilenameO == null) ? UUID.randomUUID().toString() : headerFilenameO.toString(); File givenName = new File(headerFilename); if (givenName.getName().equals("")) { System.out.println("Skipping file with empty name: " + givenName); } else { File f = new File(outputDir, givenName.getName()); System.out.print("Writing " + f + " ..."); FileOutputStream o = new FileOutputStream(f); o.write(body); o.close(); System.out.println(" done."); } ch.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }