Example usage for java.io ByteArrayInputStream ByteArrayInputStream

List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream

Introduction

In this page you can find the example usage for java.io ByteArrayInputStream ByteArrayInputStream.

Prototype

public ByteArrayInputStream(byte buf[]) 

Source Link

Document

Creates a ByteArrayInputStream so that it uses buf as its buffer array.

Usage

From source file:Main.java

public static Document LoadXml(String xml) throws Exception {
    // create...//from ww w.  j  a  v  a 2  s . co m
    ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes());
    try {
        return LoadXml(stream);
    } finally {
        if (stream != null)
            stream.close();
    }
}

From source file:Main.java

public static String descomprimeComGZIP(byte[] bytes, String encoding) {
    String decompressedString = "";
    try {/*  ww w .  j av  a 2s  . c  o  m*/
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        GZIPInputStream gzip = new GZIPInputStream(bais);
        Reader reader = new InputStreamReader(gzip, encoding);
        StringBuffer sbuf = new StringBuffer();
        char[] buffer = new char[32 * 1024];
        int nread;
        while ((nread = reader.read(buffer)) >= 0) {
            sbuf.append(buffer, 0, nread);
        }
        decompressedString = sbuf.toString();
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return decompressedString;
}

From source file:Main.java

public static ByteArrayInputStream Bitmap2InputStream(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    ByteArrayInputStream is = new ByteArrayInputStream(baos.toByteArray());
    return is;/*from  w  ww  . j a v  a 2 s . c  o m*/
}

From source file:Main.java

public static byte[] inflate(byte[] in) throws IOException {
    return inflate(new ByteArrayInputStream(in), EXPECTED_COMPRESSION_RATIO * in.length);
}

From source file:Main.java

public static Bitmap getBitmapByString(String imgSrc) {
    if (imgSrc != null) {
        byte[] buf = Base64.decode(imgSrc, Base64.NO_WRAP);
        ByteArrayInputStream bas = new ByteArrayInputStream(buf);
        Bitmap pic = BitmapFactory.decodeStream(bas);
        return pic;
    } else// w w  w .j a  v  a 2s . c  o  m
        return null;
}

From source file:Main.java

public static Object convertByteArrayToObject(byte[] bytes) throws IOException, ClassNotFoundException {
    ObjectInputStream is = null;/*  ww w.ja v a 2s. c  o m*/
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    is = new ObjectInputStream(new BufferedInputStream(byteArrayInputStream));
    Object obj = is.readObject();
    is.close();
    return obj;

}

From source file:Main.java

public static InputStream Bitmap2IS(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    InputStream sbs = new ByteArrayInputStream(baos.toByteArray());
    return sbs;//from ww  w. jav a 2  s.  c  om
}

From source file:Main.java

public static InputStream bitmapToInputStream(Bitmap bitmap) {
    int size = bitmap.getHeight() * bitmap.getRowBytes();
    ByteBuffer buffer = ByteBuffer.allocate(size);
    bitmap.copyPixelsToBuffer(buffer);/*from w ww.j  av a2 s  . c o  m*/
    return new ByteArrayInputStream(buffer.array());
}

From source file:Main.java

public static Document parseString(final String xml) {
    try {//w w  w  . j a  v  a  2s  . co m
        return parseStream(new ByteArrayInputStream(xml.getBytes("utf-8")));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Node stringToNode(final String confXmlString) {
    try {/*from   ww w .  j  a  v  a 2s.c om*/
        return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(confXmlString.getBytes())).getFirstChild();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}