Example usage for org.apache.commons.io IOUtils copy

List of usage examples for org.apache.commons.io IOUtils copy

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils copy.

Prototype

public static void copy(Reader input, OutputStream output) throws IOException 

Source Link

Document

Copy chars from a Reader to bytes on an OutputStream using the default character encoding of the platform, and calling flush.

Usage

From source file:com.jeffy.hdfs.compression.StreamCompressor.java

public static void main(String[] args) throws ClassNotFoundException, IOException {
    ///*from  www  .  ja  v a2 s.  c o  m*/
    String codecClassname = args[0];

    Class<?> codecClass = Class.forName(codecClassname);

    Configuration conf = new Configuration();

    CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf);

    CompressionOutputStream out = codec.createOutputStream(System.out);

    IOUtils.copy(System.in, out);

    out.finish();

}

From source file:com.tc.simple.apn.quicktests.SaveFeedbackData.java

/**
 * @param args/*from w ww  . j  av a 2 s. c  om*/
 * @throws IOException 
 */
public static void main(String[] args) {
    try {

        InputStream in = SaveFeedbackData.class.getResourceAsStream("webshell-dev.p12");

        byte[] p12 = IOUtils.toByteArray(in);

        SocketWrapper feedback = new APNSocketPool().feedBack(p12, "xxxxxxxxx", false);

        IOUtils.copy(feedback.getSocket().getInputStream(),
                new FileOutputStream("c:/temp/feedbackservice.apn", true));

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.cloudera.earthquake.GetData.java

public static void main(String[] args) throws IOException {
    URL url = new URL("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.connect();/*from  ww w  .  j  ava  2s.c o  m*/
    InputStream connStream = conn.getInputStream();

    FileSystem hdfs = FileSystem.get(new Configuration());
    FSDataOutputStream outStream = hdfs.create(new Path(args[0], "month.txt"));
    IOUtils.copy(connStream, outStream);

    outStream.close();
    connStream.close();
    conn.disconnect();
}

From source file:net.awl.edoc.pdfa.compression.FlateDecode.java

public static void main(String[] args) throws Exception {
    Inflater inf = new Inflater(false);

    File f = new File("resources/content_2_0.ufd");
    FileInputStream fis = new FileInputStream(f);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(fis, baos);
    IOUtils.closeQuietly(fis);/*  w  ww  . ja v  a  2  s.  c om*/
    IOUtils.closeQuietly(baos);
    byte[] buf = baos.toByteArray();
    inf.setInput(buf);
    byte[] res = new byte[buf.length];
    int size = inf.inflate(res);
    String s = new String(res, 0, size, "utf8");
    System.err.println(s);

}

From source file:com.jeffy.hdfs.HDFSWriteFile.java

/**
 * ??hdfs/*ww  w.j  a v  a2  s.c  o  m*/
 * 
 * @param args
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Please input two parameter!");
        System.out.println("Parameter: localfile hdfsfile");
        System.exit(1);
    }

    String localPath = args[0];
    String hdfsPath = args[1];
    //??
    Configuration config = new Configuration();
    //??
    try (InputStream in = new BufferedInputStream(new FileInputStream(localPath))) {
        FileSystem fs = FileSystem.get(URI.create(hdfsPath), config);
        try (FSDataOutputStream out = fs.create(new Path(hdfsPath), new Progressable() {
            @Override
            public void progress() {
                System.out.println(".");
            }
        })) {
            //??OutputStream,Hadooporg.apache.commons.io.IOUtils
            IOUtils.copy(in, out);
            System.out.println("File copy finished.");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.streamreduce.util.CAGenerator.java

public static void main(String[] args) throws Exception {

    KeyStore store = KeyStore.getInstance("JKS");
    //        store.load(CAGenerator.class.getResourceAsStream("/mmc-keystore.jks"), "ion-mmc".toCharArray());
    store.load(null);//from  ww  w. j  ava  2  s  . c  o m

    KeyPair keypair = generateKeyPair();

    X509Certificate cert = generateCACert(keypair);

    char[] password = "nodeable-agent".toCharArray();
    store.setKeyEntry("nodeable", keypair.getPrivate(), password, new Certificate[] { cert });
    store.store(new FileOutputStream("nodeable-keystore.jks"), password);
    byte[] certBytes = getCertificateAsBytes(cert);
    FileOutputStream output = new FileOutputStream("nodeable.crt");
    IOUtils.copy(new ByteArrayInputStream(certBytes), output);
    output.close();
}

From source file:eu.europa.esig.dss.cookbook.example.sign.SigningApplication.java

public static void main(String[] args) throws IOException {

    preparePKCS12TokenAndKey();/*w w w . j  av a  2 s . c o  m*/

    DSSDocument toBeSigned = new FileDocument("src/main/resources/xml_example.xml");

    XAdESSignatureParameters params = new XAdESSignatureParameters();

    params.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
    params.setSignaturePackaging(SignaturePackaging.ENVELOPED);
    params.setSigningCertificate(privateKey.getCertificate());
    params.setCertificateChain(privateKey.getCertificateChain());
    params.bLevel().setSigningDate(new Date());

    CommonCertificateVerifier commonCertificateVerifier = new CommonCertificateVerifier();
    XAdESService service = new XAdESService(commonCertificateVerifier);
    ToBeSigned dataToSign = service.getDataToSign(toBeSigned, params);
    SignatureValue signatureValue = signingToken.sign(dataToSign, params.getDigestAlgorithm(), privateKey);
    DSSDocument signedDocument = service.signDocument(toBeSigned, params, signatureValue);
    IOUtils.copy(signedDocument.openStream(), System.out);
}

From source file:com.semsaas.utils.anyurl.App.java

public static void main(String[] rawArgs) throws Exception {
    Properties props = new Properties();
    String args[] = processOption(rawArgs, props);

    String outputFile = props.getProperty("output");
    OutputStream os = outputFile == null ? System.out : new FileOutputStream(outputFile);

    final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main();
    main.setApplicationContextUri("classpath:application.xml");

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                main.stop();//ww  w.ja v a2 s.com
            } catch (Exception e) {
            }
        }
    });

    if (args.length > 0) {
        main.start();
        if (main.isStarted()) {
            CamelContext camelContext = main.getCamelContexts().get(0);

            String target = rewriteEndpoint(args[0]);
            boolean producerBased = checkProducerBased(target);

            InputStream is = null;
            if (producerBased) {
                ProducerTemplate producer = camelContext.createProducerTemplate();
                is = producer.requestBody(target, null, InputStream.class);
            } else {
                ConsumerTemplate consumer = camelContext.createConsumerTemplate();
                is = consumer.receiveBody(target, InputStream.class);
            }
            IOUtils.copy(is, os);

            main.stop();
        } else {
            System.err.println("Couldn't trigger jobs, camel wasn't started");
        }
    } else {
        logger.info("No triggers. Running indefintely");
    }
}

From source file:geocodingsql.Main.java

/**
 * @param args the command line arguments
 *//*from   w ww.j  a v a2s  .co  m*/
public static void main(String[] args) throws JSONException {
    Main x = new Main();
    ResultSet rs = null;
    String string = "";

    x.establishConnection();
    rs = x.giveName();

    try {
        while (rs.next()) {
            string += rs.getString(1) + " ";
        }

        JOptionPane.showMessageDialog(null, string, "authors", 1);
    } catch (Exception e) {
        System.out.println("Problem when printing the database.");
    }
    x.closeConnection();

    // Now do Geocoding
    String req = "https://maps.googleapis.com/maps/api/geocode/json?latlng=41.3166662867211,-72.9062497615814&result_type=point_of_interest&key="
            + key;
    try {
        URL url = new URL(req + "&sensor=false");
        URLConnection conn = url.openConnection();
        ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
        IOUtils.copy(conn.getInputStream(), output);
        output.close();
        req = output.toString();
    } catch (Exception e) {
        System.out.println("Geocoding Error");
    }
    JSONObject jObject = new JSONObject(req);
    JSONArray resultArray = jObject.getJSONArray("results");
    //this prints out the neighborhood of the provided coordinates
    System.out.println(resultArray.getJSONObject(0).getJSONArray("address_components")
            .getJSONObject("neighborhood").getString("long_name"));
}

From source file:com.heliosdecompiler.appifier.Appifier.java

public static void main(String[] args) throws Throwable {
    if (args.length == 0) {
        System.out.println("An input JAR must be specified");
        return;// w w w  .  ja va 2 s .  co m
    }

    File in = new File(args[0]);

    if (!in.exists()) {
        System.out.println("Input not found");
        return;
    }

    String outName = args[0];
    outName = outName.substring(0, outName.length() - ".jar".length()) + "-appified.jar";

    File out = new File(outName);

    if (out.exists()) {
        if (!out.delete()) {
            System.out.println("Could not delete out file");
            return;
        }
    }

    try (ZipOutputStream outstream = new ZipOutputStream(new FileOutputStream(out));
            ZipFile zipFile = new ZipFile(in)) {

        {
            ZipEntry systemHook = new ZipEntry("com/heliosdecompiler/appifier/SystemHook.class");
            outstream.putNextEntry(systemHook);
            outstream.write(SystemHookDump.dump());
            outstream.closeEntry();
        }

        Enumeration<? extends ZipEntry> enumeration = zipFile.entries();

        while (enumeration.hasMoreElements()) {
            ZipEntry next = enumeration.nextElement();

            if (!next.isDirectory()) {
                ZipEntry result = new ZipEntry(next.getName());
                outstream.putNextEntry(result);
                if (next.getName().endsWith(".class")) {
                    byte[] classBytes = IOUtils.toByteArray(zipFile.getInputStream(next));
                    outstream.write(transform(classBytes));
                } else {
                    IOUtils.copy(zipFile.getInputStream(next), outstream);
                }
                outstream.closeEntry();
            }
        }
    }
}