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:jadx.core.utils.android.Res9patchStreamDecoder.java

public void decode(InputStream in, OutputStream out) throws JadxException {
    try {/*  w  w  w .  j av a  2  s  .  c om*/
        byte[] data = IOUtils.toByteArray(in);

        BufferedImage im = ImageIO.read(new ByteArrayInputStream(data));
        int w = im.getWidth(), h = im.getHeight();

        BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
        im2.createGraphics().drawImage(im, 1, 1, w, h, null);

        NinePatch np = getNinePatch(data);
        drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
        drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom);

        int[] xDivs = np.xDivs;
        for (int i = 0; i < xDivs.length; i += 2) {
            drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]);
        }

        int[] yDivs = np.yDivs;
        for (int i = 0; i < yDivs.length; i += 2) {
            drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]);
        }

        ImageIO.write(im2, "png", out);
    } catch (IOException | NullPointerException ex) {
        throw new JadxException(ex.toString());
    }
}

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

public DCDevice(String name, double cpuSpeed, int totalMemory) {
    super(name, cpuSpeed, totalMemory, DeviceType.DC);
    try {/*from   w  w w .  j  a  va  2 s  .co  m*/
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/dc.jpeg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.igormaznitsa.zxpoly.components.RomData.java

public static RomData read(final InputStream in) throws IOException {
    try {//w w  w . ja v  a  2  s  . co  m
        return new RomData(IOUtils.toByteArray(in));
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.nesscomputing.httpclient.response.HttpResponseContentConverter.java

@Override
public HttpResponse convert(HttpClientResponse response, InputStream inputStream) throws IOException {
    return new HttpResponse(response.getStatusCode(), IOUtils.toByteArray(inputStream), response.getCharset(),
            headersFor(response.getAllHeaders()));
}

From source file:eu.matejkormuth.crawler2.documents.HtmlDocument.java

public HtmlDocument(String contentType, String contentEncoding, long contentLength, InputStream content) {
    super(contentEncoding);
    try {/*w  ww  . j  a  va2s . c o  m*/
        this.content = IOUtils.toByteArray(content);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:brut.androlib.res.decoder.Res9patchStreamDecoder.java

@Override
public void decode(InputStream in, OutputStream out) throws AndrolibException {
    try {// w  w  w  .  j a  v  a 2 s . c  o m
        byte[] data = IOUtils.toByteArray(in);

        BufferedImage im = ImageIO.read(new ByteArrayInputStream(data));
        int w = im.getWidth(), h = im.getHeight();

        ImageTypeSpecifier its = ImageTypeSpecifier.createFromRenderedImage(im);
        BufferedImage im2 = its.createBufferedImage(w + 2, h + 2);

        im2.getRaster().setRect(1, 1, im.getRaster());
        NinePatch np = getNinePatch(data);
        drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
        drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom);

        int[] xDivs = np.xDivs;
        for (int i = 0; i < xDivs.length; i += 2) {
            drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]);
        }

        int[] yDivs = np.yDivs;
        for (int i = 0; i < yDivs.length; i += 2) {
            drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]);
        }

        ImageIO.write(im2, "png", out);
    } catch (IOException ex) {
        throw new AndrolibException(ex);
    } catch (NullPointerException ex) {
        // In my case this was triggered because a .png file was
        // containing a html document instead of an image.
        // This could be more verbose and try to MIME ?
        throw new AndrolibException(ex);
    }
}

From source file:com.moz.fiji.schema.util.SplitKeyFile.java

/**
 * Constructs a split key file from an input stream.  This object will take ownership of
 * the inputStream, which you should clean up by calling close().
 *
 * @param inputStream The file contents.
 * @return the region boundaries, as a list of row keys.
 * @throws IOException on I/O error./*from www. j a va 2  s  .  c o  m*/
 */
public static List<byte[]> decodeRegionSplitList(InputStream inputStream) throws IOException {
    try {
        final String content = Bytes.toString(IOUtils.toByteArray(Preconditions.checkNotNull(inputStream)));
        final String[] encodedKeys = content.split("\n");
        final List<byte[]> keys = Lists.newArrayListWithCapacity(encodedKeys.length);
        for (String encodedKey : encodedKeys) {
            keys.add(decodeRowKey(encodedKey));
        }
        return keys;
    } finally {
        ResourceUtils.closeOrLog(inputStream);
    }
}

From source file:com.javacreed.examples.sc.part3.MembersServiceImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    FileUtils.writeByteArrayToFile(dataFile, IOUtils.toByteArray(getClass().getResource("members.txt")));
}

From source file:com.haulmont.yarg.formatters.impl.inline.ImageContentInliner.java

protected byte[] getContent(Object paramValue) {
    try {/*from w  ww .j a v a2 s  . c o  m*/
        return IOUtils.toByteArray(new URL(paramValue.toString()).openStream());
    } catch (IOException e) {
        throw new ReportFormattingException("Unable to get image from " + paramValue, e);
    }
}

From source file:com.gs.plistconv.matchers.RsBodyMatcher.java

@Override
protected boolean matchesSafely(Response item) {
    try {//from  w w w .  j  a va  2s  . co  m
        return Arrays.equals(IOUtils.toByteArray(item.body()), expectedBody);
    } catch (IOException e) {
        return false;
    }
}