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

The following examples show how to use java.io.OutputStream#toByteArray() . These examples are extracted from open source projects. 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 Project: letv   File: j.java    License: 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 Project: letv   File: ac.java    License: 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 Project: letv   File: ImageActivity.java    License: 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 Project: letv   File: jn.java    License: 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 Project: letv   File: ir.java    License: 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 Project: letv   File: HttpRequest.java    License: 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 Project: FimiX8-RE   File: IOUtils.java    License: 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 Project: FimiX8-RE   File: IOUtils.java    License: 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();
}