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 InputStream stringToInputStream(String xml) {
    ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes());
    return stream;
}

From source file:Main.java

public static InputStream str2InputStream(String str) {
    return new ByteArrayInputStream(str.getBytes());
}

From source file:Main.java

public static String getHexStr(byte[] b) {
    StringBuilder builder = new StringBuilder();
    ByteArrayInputStream input = new ByteArrayInputStream(b);
    int i = 0;//from  w  ww. j  a  va 2 s . c  o m
    while ((i = input.read()) != -1) {
        builder.append(
                Integer.toHexString(i).length() == 2 ? Integer.toHexString(i) : 0 + Integer.toHexString(i));
        builder.append(" ");
    }
    return builder.toString();
}

From source file:Main.java

public static Object fromByteArray(byte[] inputBytes) {
    Object obj = null;/* w  w w  . j  a  v a 2s.c  o  m*/
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputBytes);
    ObjectInput objIn = null;
    try {
        objIn = new ObjectInputStream(byteArrayInputStream);
        obj = objIn.readObject();
    } catch (java.io.IOException ioe) {
        return null;
    } catch (java.lang.ClassNotFoundException cnfe) {
        return null;
    } finally {
        try {
            byteArrayInputStream.close();
            objIn.close();
        } catch (java.io.IOException closeIOE) {

        }
    }
    return obj;
}

From source file:Main.java

public static InputStream ByteToStream(byte[] data) {
    ByteArrayInputStream os = new ByteArrayInputStream(data);
    return os;/*from   w ww .  j  a v a  2 s . com*/
}

From source file:Main.java

private static InputStream trustedCertificatesInputStreamByCertificateString(String certificate) {
    try {/*from   ww w  .j  a v  a  2  s. co  m*/
        return new ByteArrayInputStream(certificate.getBytes("UTF-8"));
    } catch (Exception var3) {
        return null;
    }
}

From source file:Main.java

static InputStream createInputStream(final String input) {
    return input == null ? null : new ByteArrayInputStream(input.getBytes());
}

From source file:Main.java

public static InputStream bytes2InputStream(byte[] bytes) {
    if (bytes == null || bytes.length <= 0)
        return null;
    return new ByteArrayInputStream(bytes);
}

From source file:Main.java

public static long byteArrayToLong(byte[] input) {
    try {/*from w w w  .  jav  a 2  s . c  om*/
        ByteArrayInputStream bis = new ByteArrayInputStream(input);
        DataInputStream dis = new DataInputStream(bis);
        long numb = dis.readLong();
        dis.close();
        return numb;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

private static InputStream String2Inputstream(String str) throws UnsupportedEncodingException {
    return new ByteArrayInputStream(str.getBytes("utf-8"));
}