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[], int offset, int length) 

Source Link

Document

Creates ByteArrayInputStream that uses buf as its buffer array.

Usage

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69, 70, 71, 72, 73 };

    // create new byte array input stream
    ByteArrayInputStream bais = new ByteArrayInputStream(buf, 2, 3);

}

From source file:Main.java

public static byte[] decompressInGzip(byte[] compressData, int offset, int length) throws Exception {

    ByteArrayInputStream bis = new ByteArrayInputStream(compressData, offset, length);
    GZIPInputStream gzipInStream = new GZIPInputStream(bis);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int count;/*  w w  w .  j a va 2s.c om*/
    byte[] buf = new byte[1024];
    while ((count = gzipInStream.read(buf)) > 0) {
        bos.write(buf, 0, count);
    }
    gzipInStream.close();

    byte[] originalData = bos.toByteArray();
    bos.close();

    return originalData;
}

From source file:com.ebt.platform.utility.WebServiceCaller.java

public static String CallCasWebService(String xml) {
    PostMethod postMethod = new PostMethod("http://ws.e-baotong.cn:8085/CASServer.asmx?wsdl");
    String responseString = null;
    try {//from w  w w  . ja  v  a  2  s .  c om
        byte[] b = xml.getBytes("utf-8");
        InputStream inS = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity req = new InputStreamRequestEntity(inS, b.length, "text/xml; charset=utf-8");
        postMethod.setRequestEntity(req);

        HttpClient httpClient = new HttpClient();
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == 200) {
            responseString = new String(postMethod.getResponseBodyAsString().getBytes("ISO-8859-1"), "UTF-8");
            System.out.println("WebService??====" + responseString);
        } else {
            System.out.println("WebService??" + statusCode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return responseString;
}

From source file:Main.java

/**
 * Creates a reader from the given input stream and encoding.
 * This method assumes the input stream working buffer is at least
 * 128 byte long. The input stream is restored before this method
 * returns. The 4 first bytes are skipped before creating the reader.
 *//*ww  w  . j  a v a2  s.c  o  m*/
protected static Reader createXMLDeclarationReader(PushbackInputStream pbis, String enc) throws IOException {
    byte[] buf = new byte[128];
    int len = pbis.read(buf);

    if (len > 0) {
        pbis.unread(buf, 0, len);
    }

    return new InputStreamReader(new ByteArrayInputStream(buf, 4, len), enc);
}

From source file:com.cloudera.branchreduce.impl.thrift.Writables.java

public static <T extends Writable> T fromByteBuffer(ByteBuffer bb, Class<T> clazz) {
    T instance = ReflectionUtils.newInstance(clazz, DUMMY);
    try {//from  w ww .  ja v  a  2s .  c o  m
        instance.readFields(
                new DataInputStream(new ByteArrayInputStream(bb.array(), bb.arrayOffset(), bb.limit())));
    } catch (IOException e) {
        LOG.error("Deserialization error for class: " + clazz, e);
    }
    return instance;
}