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:eu.matejkormuth.crawler2.documents.BinaryDocument.java

public BinaryDocument(String contentType, String contentEncoding, long contentLength, InputStream content) {
    super(contentEncoding);
    try {//from  w  ww  .j  av a 2 s.  c om
        this.content = IOUtils.toByteArray(content);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.voa.weixin.work.DownloadFileWork.java

@Override
public void toDo() throws WorkException {
    try {//from   ww w  .ja  v  a 2s. c  o  m
        DownloadFileTask task = (DownloadFileTask) this.task;
        byte[] bs = IOUtils.toByteArray(task.getInputStream());

        FileOutputStream out = new FileOutputStream(new File("c:/tt.jpg"));
        IOUtils.write(bs, out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:de.mas.telegramircbot.utils.images.ImgurUploader.java

public static String uploadImageAndGetLink(String clientID, InputStream is) throws IOException {
    return uploadImageAndGetLink(clientID, IOUtils.toByteArray(is));
}

From source file:ezbake.frack.submitter.util.UnzipUtilTest.java

@Test
public void testUnzip() throws IOException {
    File unzipped = null;/*from  w  ww. j  a  v  a 2  s . c  o  m*/
    try {
        InputStream is = getClass().getResourceAsStream("/example.tar.gz");
        byte[] tarGzBytes = IOUtils.toByteArray(is);
        is.close();
        unzipped = UnzipUtil.unzip(new File(System.getProperty("user.dir")), ByteBuffer.wrap(tarGzBytes));
        assertTrue("Unzipped folder exists", unzipped.exists());
        assertTrue("Unzipped folder is a folder", unzipped.isDirectory());

        Optional<String> jarPath = UnzipUtil.getJarPath(unzipped);
        assertTrue("Jar path exists", jarPath.isPresent());

        File jarFile = new File(jarPath.get());
        assertEquals("Jar path has correct name", "example.jar", jarFile.getName());
        assertEquals("Jar has correct parent", "bin", jarFile.getParentFile().getName());

        Optional<String> confPath = UnzipUtil.getConfDirectory(unzipped);
        assertTrue("Conf path exists", confPath.isPresent());

        File confDir = new File(confPath.get());
        Optional<String> sslPath = UnzipUtil.getSSLPath(confDir);
        assertTrue("SSL path exists", sslPath.isPresent());

        File keyPath = UnzipUtil.findSubDir(confDir, "keys");
        assertTrue("Keys path exists", keyPath.exists());

    } finally {
        if (unzipped != null && unzipped.exists()) {
            FileUtils.deleteDirectory(unzipped);
        }
    }
}

From source file:com.imag.nespros.network.devices.PADevice.java

public PADevice(String name, double cpuSpeed, int totalMemory) {
    super(name, cpuSpeed, totalMemory, DeviceType.PA);
    try {//from  ww  w.ja v a  2s  .c o m
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/pa.jpg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.googlecode.dex2jar.reader.ZipExtractor.java

public byte[] extract(byte[] data, String name) throws IOException {
    ZipInputStream zis = null;//from   w w  w  .  ja  v  a2 s . co m
    try {
        zis = new ZipInputStreamHack(new ByteArrayInputStream(data));
        for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
            if (entry.getName().equals(name)) {
                data = IOUtils.toByteArray(zis);
                zis.close();
                return data;
            }
        }
    } finally {
        IOUtils.closeQuietly(zis);
    }
    throw new IOException("can't find classes.dex in the zip");
}

From source file:com.barchart.netty.rest.client.TestRequestHandler.java

@Override
public void handle(final HttpServerRequest request) throws IOException {

    method = request.getMethod();//from   w w  w .j  a  va  2  s. com
    params = request.getParameters();
    headers = request.headers();
    input = IOUtils.toByteArray(request.getInputStream());

    request.response().setStatus(status);
    request.response().write(output);
    request.response().finish();

}

From source file:com.hurence.logisland.processor.hbase.util.StringSerDe.java

@Override
public String deserialize(final InputStream input) throws DeserializationException, IOException {
    byte[] value = IOUtils.toByteArray(input);
    if (value == null) {
        return null;
    }//from  w  w w  .java 2 s .  c  o  m

    return new String(value, StandardCharsets.UTF_8);
}

From source file:com.ctriposs.r2.filter.compression.SnappyCompressor.java

@Override
public byte[] inflate(InputStream data) throws CompressionException {
    try {/*w w  w. ja v a  2 s. co  m*/
        byte[] temp = IOUtils.toByteArray(data);
        return Snappy.uncompress(temp, 0, temp.length);
    } catch (IOException e) {
        throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
    }

}

From source file:fr.mosica.javaMonolithicTraining.own.WeatherStub.java

@Override
public void stub() {
    try {//from   w ww .  j ava2 s  . c  om
        ResponseDefinitionBuilder response = aResponse().withStatus(status).withHeader("Content-type",
                "application/json");

        if (this.jsonFileName != null) {
            response.withBody(IOUtils.toByteArray(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(this.jsonFileName)));
        }

        stubFor(get(urlEqualTo(path)).willReturn(response));
    } catch (IOException ex) {
        throw new TestException(ex);
    }
}