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

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

Introduction

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

Prototype

public static byte[] toByteArray(String input) throws IOException 

Source Link

Document

Get the contents of a String as a byte[] using the default character encoding of the platform.

Usage

From source file:NewMain.java

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

    FileInputStream myStream = new FileInputStream("D:\\logout.png");

    byte[] imageInBytes = IOUtils.toByteArray(myStream);

    System.out.println(imageInBytes);

}

From source file:com.swemel.sevenzip.Extract.java

public static void main(String[] args) throws IOException {
    String fileName = "D:\\incubator\\commpressors\\test_100K_2_b.7z";
    //    SevenZFile sevenZFile = new SevenZFile(new File("D:\\incubator\\commpressors\\test_100K_2_b.7z"));
    byte[] inputData = IOUtils.toByteArray(new FileInputStream(fileName)); // 7z archive contents

    SeekableInMemoryByteChannel inMemoryByteChannel = new SeekableInMemoryByteChannel(inputData);
    SevenZFile sevenZFile = new SevenZFile(inMemoryByteChannel);

    SevenZArchiveEntry entry;/*w  w w  .  j av  a 2  s  .c o m*/
    Iterable<SevenZArchiveEntry> entrys = sevenZFile.getEntries();
    for (SevenZArchiveEntry entry1 : entrys) {
        String name = entry1.getName();
        System.out.println("name = " + name + "\t" + entry1.toString());
    }
    ArrayList<InputStream> strams = sevenZFile.getStrams();
    String str = IOUtils.toString(strams.get(10));
    System.out.println("str = " + str);
    //   entry = sevenZFile.getNextEntry();
    //   sevenZFile.read();  // read current entry's data
}

From source file:de.britter.beyondstringutils.CodecExample.java

public static void main(String[] args) throws Exception {
    InputStream is = CodecExample.class.getResourceAsStream("asf_logo.png");
    byte[] imgBytes = IOUtils.toByteArray(is);
    String base64 = Base64.encodeBase64String(imgBytes);

    System.out.println(base64);//w ww . ja va  2  s  . c  om
}

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

/**
 * @param args//from  ww  w .  j  a  v  a  2 s.  c o m
 * @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.bia.config.Main.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext*.xml");

    EmployeeCassandraServiceImpl service = context.getBean(EmployeeCassandraServiceImpl.class);

    Emp emp = new Emp();
    emp.setId((new Date()).toString());
    String username = "IM-" + new Date();
    emp.setUsername(username);//from w  ww. ja  v a2 s. c o  m
    emp.setJoinDate(new Date());
    emp.setStorageSize(10.0);
    emp.setContent(ByteBuffer
            .wrap(IOUtils.toByteArray(Main.class.getClassLoader().getResourceAsStream("log4j.properties"))));

    service.saveEmployee(emp);
    int count = 0;
    for (Emp e : service.findAllEmployees()) {
        System.out.println(e + String.valueOf(e.getContent()));
        System.out.println(new String(e.getContent().array()));
        count++;
    }

    System.out.println("done " + count);

    System.out.println(service.findByUsername(username));

}

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

/**
 * @param args/*from   ww  w . ja v  a 2  s. c  o m*/
 * @throws IOException 
 */
public static void main(String[] args) {
    try {

        System.out.println(KeyManagerFactory.getDefaultAlgorithm());

        String token = "8cebc7c08f79fa62f0994eb4298387ff930857ff8d14a50de431559cf476b223";

        InputStream in = Test2.class.getResourceAsStream("webshell-dev.p12");
        byte[] p12 = IOUtils.toByteArray(in);

        Map<String, Object> custom = new HashMap<String, Object>();
        //custom.put("scriptfunction", "afterPushNotice");
        //custom.put("customdata", "hi there");
        //custom.put("url","http://google.com");

        for (int i = 0; i < 2; i++) {
            Payload payload = new PayloadFactory().buildPayload(token, "Hi There " + i, 0, null, custom);
            //String payload="{\"aps\":{\"alert\":\"yabadabadooo" + i + "\"}}";
            //String payload = "{\"aps\":{\"alert\":\"Hi There" + i + "\"}}";
            send(p12, payload.getToken(), i * 100, payload.getJson());
        }

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

}

From source file:br.com.topsys.cd.util.AssinarArquivo.java

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

    InputStream assinatura = AssinarArquivo.assinarDocumento();

    byte[] assinatura_binario = IOUtils.toByteArray(assinatura);
    FileUtils.writeByteArrayToFile(//from   w  ww. ja v a  2 s .com
            new File(caminho + "assinados//" + "assinatura_detached_bytes_prontuario.p7s"), assinatura_binario);

}

From source file:LegacyTest.java

public static void main(String[] args) {
    try {//from ww  w . ja  va 2  s . c o m
        PdfAs pdfAS = PdfAsFactory.createPdfAs();

        SignParameters signParameters = new SignParameters();
        signParameters.setSignatureDevice("bku");
        signParameters.setSignatureProfileId("SIGNATURBLOCK_DE");

        InputStream is = LegacyTest.class.getResourceAsStream("simple.pdf");

        byte[] inputData = IOUtils.toByteArray(is);
        ByteArrayDataSink bads = new ByteArrayDataSink();
        signParameters.setDocument(new ByteArrayDataSource(inputData));
        signParameters.setOutput(bads);
        SignResult result = pdfAS.sign(signParameters);
        IOUtils.write(bads.getBytes(), new FileOutputStream("/tmp/test.pdf"));

        System.out.println("Signed @ " + result.getSignaturePosition().toString());
        System.out.println("Signed by " + result.getSignerCertificate().getSubjectDN().getName());

        VerifyParameters verifyParameters = new VerifyParameters();
        verifyParameters.setDocument(new ByteArrayDataSource(bads.getBytes()));
        verifyParameters.setSignatureToVerify(0);

        VerifyResults results = pdfAS.verify(verifyParameters);

        Iterator iter = results.getResults().iterator();

        while (iter.hasNext()) {
            Object obj = iter.next();
            if (obj instanceof VerifyResult) {
                VerifyResult vresult = (VerifyResult) obj;
                System.out.println("Verified: " + vresult.getValueCheckCode().getCode() + " "
                        + vresult.getValueCheckCode().getMessage());
            }
        }

    } catch (Throwable e) {
        System.out.println("ERROR");
        e.printStackTrace();
    }
}

From source file:com.lightboxtechnologies.spectrum.InfoPutter.java

public static void main(String[] args) throws IOException {
    final Configuration conf = HBaseConfiguration.create();

    final String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();

    if (otherArgs.length != 2) {
        System.err.println("Usage: InfoPutter <imageID> <friendly_name>");
        System.exit(1);//ww w .j a  va2s  .  c om
    }

    final String imageID = otherArgs[0];
    final String friendlyName = otherArgs[1];

    HTable imgTable = null;

    try {
        imgTable = HBaseTables.summon(conf, HBaseTables.IMAGES_TBL_B, HBaseTables.IMAGES_COLFAM_B);

        // check whether the image ID is in the images table
        final byte[] hash = Bytes.toBytes(imageID);

        final Get get = new Get(hash);
        final Result result = imgTable.get(get);

        if (result.isEmpty()) {
            // row does not exist, add it

            final byte[] friendly_col = "friendly_name".getBytes();
            final byte[] json_col = "json".getBytes();

            final byte[] friendly_b = friendlyName.getBytes();
            final byte[] json_b = IOUtils.toByteArray(System.in);

            final Put put = new Put(hash);
            put.add(HBaseTables.IMAGES_COLFAM_B, friendly_col, friendly_b);
            put.add(HBaseTables.IMAGES_COLFAM_B, json_col, json_b);

            imgTable.put(put);

            System.exit(0);
        } else {
            // row exists, fail!
            System.exit(1);
        }
    } finally {
        imgTable.close();
    }
}

From source file:at.gv.egiz.pdfas.web.client.test.SimpleTest.java

public static void main(String[] args) {
    try {/*from www . j a va  2s  . com*/
        FileInputStream fis = new FileInputStream("/home/afitzek/simple.pdf");
        byte[] inputData = IOUtils.toByteArray(fis);

        PDFASSignParameters signParameters = new PDFASSignParameters();
        signParameters.setConnector(Connector.JKS);
        signParameters.setPosition(null);
        signParameters.setProfile("SIGNATURBLOCK_SMALL_DE");
        signParameters.setQRCodeContent("TEST CONTENT");
        //signParameters.setKeyIdentifier("test");

        PDFASSignRequest request = new PDFASSignRequest();
        request.setInputData(inputData);
        request.setParameters(signParameters);
        request.setRequestID("SOME TEST ID");

        //URL endpoint = new
        //URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl");
        //URL endpoint = new
        //      URL("http://www.buergerkarte.at/pdf-as-extern-4/wssign?wsdl");
        String baseUrl = "http://demo.egiz.gv.at/demoportal-pdf_as/services/";
        //String baseUrl  = "http://localhost:8080/pdf-as-web/services/";
        //URL endpoint = new URL(
        //      "http://192.168.56.10/pdf-as-web/wssign?wsdl");

        URL signEndpoint = new URL(baseUrl + "wssign?wsdl");
        URL verifyEndpoint = new URL(baseUrl + "wsverify?wsdl");

        RemotePDFSigner signer = new RemotePDFSigner(signEndpoint, true);
        RemotePDFVerifier verifier = new RemotePDFVerifier(verifyEndpoint, true);

        PDFASSignRequest signrequest = new PDFASSignRequest();
        signrequest.setInputData(inputData);
        signrequest.setParameters(signParameters);
        signParameters.setTransactionId("MYID ....");
        System.out.println("Simple Request:");
        PDFASSignResponse response = signer.signPDFDokument(signrequest);

        System.out.println("Sign Error: " + response.getError());

        PDFASVerifyRequest verifyRequest = new PDFASVerifyRequest();
        verifyRequest.setInputData(response.getSignedPDF());
        verifyRequest.setVerificationLevel(VerificationLevel.INTEGRITY_ONLY);

        PDFASVerifyResponse verifyResponse = verifier.verifyPDFDokument(verifyRequest);

        List<PDFASVerifyResult> results = verifyResponse.getVerifyResults();

        for (int i = 0; i < results.size(); i++) {
            PDFASVerifyResult result = results.get(i);
            printVerifyResult(result);
        }

        /*
         * System.out.println("Simple Request:"); byte[] outputFile =
         * signer.signPDFDokument(inputData, signParameters);
         * 
         * FileOutputStream fos = new FileOutputStream(
         * "/home/afitzek/simple_request_signed.pdf");
         * fos.write(outputFile); fos.close();
         * 
         * System.out.println("Simple Request Obj:"); PDFASSignResponse
         * response = signer.signPDFDokument(request);
         * 
         * if (response.getSignedPDF() != null) { FileOutputStream fos2 =
         * new FileOutputStream(
         * "/home/afitzek/simple_request_obj_signed.pdf");
         * fos2.write(response.getSignedPDF()); fos2.close(); }
         * 
         * if(response.getError() != null) { System.out.println("ERROR: " +
         * response.getError()); }
         */

        /*
        List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>();
        for (int i = 0; i < 10; i++) {
           bulk.add(request);
        }
                
        PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest();
        bulkRequest.setSignRequests(bulk);
                
        for (int j = 0; j < 10; j++) {
           System.out.println("Bulk Request:");
           PDFASBulkSignResponse responses = signer
          .signPDFDokument(bulkRequest);
                
           for (int i = 0; i < responses.getSignResponses().size(); i++) {
              PDFASSignResponse bulkresponse = responses
             .getSignResponses().get(i);
              System.out.println("ID: " + bulkresponse.getRequestID());
                
              if (bulkresponse.getError() != null) {
          System.out.println("ERROR: " + bulkresponse.getError());
              } else {
          System.out.println("OK");
              }
           }
        }
        */
        System.out.println("Done!");
    } catch (Throwable e) {
        e.printStackTrace();
    }
}