Java Code Examples for java.io.OutputStream#toByteArray()

The following examples show how to use java.io.OutputStream#toByteArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: j.java    From letv with Apache License 2.0 6 votes vote down vote up
public static byte[] a(byte[] bArr) {
    if (bArr == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream);
    try {
        deflaterOutputStream.write(bArr, 0, bArr.length);
        deflaterOutputStream.finish();
        deflaterOutputStream.flush();
        deflaterOutputStream.close();
        return byteArrayOutputStream.toByteArray();
    } catch (Exception e) {
        return null;
    }
}
 
Example 2
Source File: ac.java    From letv with Apache License 2.0 6 votes vote down vote up
private static String c(String str) {
    String str2 = null;
    try {
        byte[] bytes = str.getBytes(z[5]);
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        OutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gZIPOutputStream.write(bytes);
        gZIPOutputStream.close();
        bytes = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        str2 = a.a(bytes);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    return str2;
}
 
Example 3
Source File: ImageActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
public void setAvator(Bitmap bitmap, IUiListener iUiListener) {
    Bundle composeCGIParams = composeCGIParams();
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 40, byteArrayOutputStream);
    byte[] toByteArray = byteArrayOutputStream.toByteArray();
    bitmap.recycle();
    IRequestListener tempRequestListener = new TempRequestListener(iUiListener);
    composeCGIParams.putByteArray(SocialConstants.PARAM_AVATAR_URI, toByteArray);
    HttpUtils.requestAsync(this.mToken, Global.getContext(), "user/set_user_face", composeCGIParams, "POST", tempRequestListener);
    d.a().a(this.mToken.getOpenId(), this.mToken.getAppId(), Constants.VIA_SET_AVATAR_SUCCEED, "12", "19", "0");
}
 
Example 4
Source File: jn.java    From letv with Apache License 2.0 5 votes vote down vote up
public static byte[] a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    a(inputStream, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}
 
Example 5
Source File: ir.java    From letv with Apache License 2.0 5 votes vote down vote up
public byte[] a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    jn.a(inputStream, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}
 
Example 6
Source File: HttpRequest.java    From letv with Apache License 2.0 5 votes vote down vote up
public byte[] bytes() throws HttpRequestException {
    OutputStream output = byteStream();
    try {
        copy(buffer(), output);
        return output.toByteArray();
    } catch (IOException e) {
        throw new HttpRequestException(e);
    }
}
 
Example 7
Source File: IOUtils.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public static byte[] toByteArray(InputStream input) throws IOException {
    OutputStream output = new ByteArrayOutputStream();
    copy(input, output);
    return output.toByteArray();
}
 
Example 8
Source File: IOUtils.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public static byte[] toByteArray(Reader input, Charset encoding) throws IOException {
    OutputStream output = new ByteArrayOutputStream();
    copy(input, output, encoding);
    return output.toByteArray();
}