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

The following are Jave code examples for showing how to use toByteArray() of the java.io.OutputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: letv   File: ac.java   View Source Code Vote up 6 votes
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 2
Project: boohee_v5.6   File: b.java   View Source Code Vote up 6 votes
public static Bitmap a(Bitmap bitmap) {
    Bitmap bitmap2 = bitmap;
    while (true) {
        float width = (float) bitmap2.getWidth();
        float height = (float) bitmap2.getHeight();
        float f = 1024.0f / (width > height ? width : height);
        if (width <= 1024.0f && height <= 1024.0f) {
            break;
        }
        Matrix matrix = new Matrix();
        matrix.postScale(f, f);
        bitmap2 = Bitmap.createBitmap(bitmap2, 0, 0, (int) width, (int) height, matrix, true);
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap2.compress(CompressFormat.JPEG, 100, byteArrayOutputStream);
    int i = 80;
    while (byteArrayOutputStream.toByteArray().length / 1024 > 150) {
        byteArrayOutputStream.reset();
        bitmap2.compress(CompressFormat.JPEG, i, byteArrayOutputStream);
        i -= 20;
    }
    return BitmapFactory.decodeStream(new ByteArrayInputStream(byteArrayOutputStream
            .toByteArray()));
}
 
Example 3
Project: boohee_v5.6   File: b.java   View Source Code Vote up 6 votes
private static void a(Bitmap bitmap, File file) {
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int i = 80;
    bitmap.compress(CompressFormat.JPEG, 80, byteArrayOutputStream);
    while (byteArrayOutputStream.toByteArray().length / 1024 > 100) {
        byteArrayOutputStream.reset();
        i -= 10;
        bitmap.compress(CompressFormat.JPEG, i, byteArrayOutputStream);
    }
    try {
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(byteArrayOutputStream.toByteArray());
        fileOutputStream.flush();
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Project: boohee_v5.6   File: a.java   View Source Code Vote up 6 votes
private String i(String str) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes());
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    String str2 = null;
    try {
        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        byte[] bArr = new byte[1024];
        while (true) {
            int read = byteArrayInputStream.read(bArr, 0, 1024);
            if (read == -1) {
                break;
            }
            gZIPOutputStream.write(bArr, 0, read);
        }
        gZIPOutputStream.flush();
        gZIPOutputStream.close();
        byte[] toByteArray = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.flush();
        byteArrayOutputStream.close();
        byteArrayInputStream.close();
        str2 = Base64.encodeToString(toByteArray, 2);
    } catch (Throwable e) {
        Ln.e(e);
    }
    return str2;
}
 
Example 5
Project: boohee_v5.6   File: CommonUtils.java   View Source Code Vote up 6 votes
public static String textCompress(String str) {
    try {
        Object array = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(str.length()).array();
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream(str.length());
        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gZIPOutputStream.write(str.getBytes("UTF-8"));
        gZIPOutputStream.close();
        byteArrayOutputStream.close();
        Object obj = new byte[(byteArrayOutputStream.toByteArray().length + 4)];
        System.arraycopy(array, 0, obj, 0, 4);
        System.arraycopy(byteArrayOutputStream.toByteArray(), 0, obj, 4, byteArrayOutputStream.toByteArray().length);
        return Base64.encodeToString(obj, 8);
    } catch (Exception e) {
        return "";
    }
}
 
Example 6
Project: boohee_v5.6   File: WechatHelper.java   View Source Code Vote up 6 votes
private byte[] a(Context context, Bitmap bitmap, CompressFormat compressFormat) {
    if (bitmap == null) {
        throw new RuntimeException("checkArgs fail, thumbData is null");
    } else if (bitmap.isRecycled()) {
        throw new RuntimeException("checkArgs fail, thumbData is recycled");
    } else {
        int i = 120;
        while (i > 40 && a(bitmap, compressFormat) > 32768) {
            int dipToPx = R.dipToPx(context, i);
            i -= 5;
            bitmap = a(bitmap, dipToPx);
        }
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(compressFormat, 100, byteArrayOutputStream);
        byteArrayOutputStream.flush();
        byteArrayOutputStream.close();
        return byteArrayOutputStream.toByteArray();
    }
}
 
Example 7
Project: letv   File: ImageActivity.java   View Source Code Vote up 5 votes
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 8
Project: boohee_v5.6   File: WechatHelper.java   View Source Code Vote up 5 votes
private void b(Context context, String str, String str2, Bitmap bitmap, int i, k kVar) {
    Object wXEmojiObject = new WXEmojiObject();
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, byteArrayOutputStream);
    byteArrayOutputStream.flush();
    wXEmojiObject.emojiData = byteArrayOutputStream.toByteArray();
    byteArrayOutputStream.close();
    WXMediaMessage wXMediaMessage = new WXMediaMessage();
    wXMediaMessage.title = str;
    wXMediaMessage.mediaObject = wXEmojiObject;
    wXMediaMessage.description = str2;
    wXMediaMessage.thumbData = a(context, wXEmojiObject.emojiData);
    a(wXMediaMessage, "emoji", i, kVar);
}
 
Example 9
Project: letv   File: jn.java   View Source Code Vote up 5 votes
public static byte[] a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    a(inputStream, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}
 
Example 10
Project: letv   File: ir.java   View Source Code Vote up 5 votes
public byte[] a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    jn.a(inputStream, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}
 
Example 11
Project: letv   File: HttpRequest.java   View Source Code Vote up 5 votes
public byte[] bytes() throws HttpRequestException {
    OutputStream output = byteStream();
    try {
        copy(buffer(), output);
        return output.toByteArray();
    } catch (IOException e) {
        throw new HttpRequestException(e);
    }
}
 
Example 12
Project: boohee_v5.6   File: WXImageObject.java   View Source Code Vote up 5 votes
public WXImageObject(Bitmap bitmap) {
    try {
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 85, byteArrayOutputStream);
        this.imageData = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 13
Project: boohee_v5.6   File: e.java   View Source Code Vote up 5 votes
public static File b(String str, String str2) {
    Bitmap c = c(str);
    Bitmap a = a(str, c);
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    a.compress(CompressFormat.PNG, 60, byteArrayOutputStream);
    byte[] toByteArray = byteArrayOutputStream.toByteArray();
    File file = null;
    try {
        file = a(toByteArray, str2);
        if (!a.isRecycled()) {
            a.recycle();
        }
        if (!(c == null || c.isRecycled())) {
            c.recycle();
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (!a.isRecycled()) {
            a.recycle();
        }
        if (!(c == null || c.isRecycled())) {
            c.recycle();
        }
    } catch (Throwable th) {
        if (!a.isRecycled()) {
            a.recycle();
        }
        if (!(c == null || c.isRecycled())) {
            c.recycle();
        }
    }
    return file;
}
 
Example 14
Project: boohee_v5.6   File: Hex.java   View Source Code Vote up 5 votes
public static byte[] decode(String str) {
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        a.decode(str, byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException("exception decoding Hex string: " + e);
    }
}
 
Example 15
Project: boohee_v5.6   File: Hex.java   View Source Code Vote up 5 votes
public static byte[] decode(byte[] bArr) {
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        a.decode(bArr, 0, bArr.length, byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException("exception decoding Hex string: " + e);
    }
}
 
Example 16
Project: boohee_v5.6   File: Hex.java   View Source Code Vote up 5 votes
public static byte[] encode(byte[] bArr, int i, int i2) {
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        a.encode(bArr, i, i2, byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException("exception encoding Hex string: " + e);
    }
}
 
Example 17
Project: boohee_v5.6   File: b.java   View Source Code Vote up 5 votes
public static AbstractHttpEntity a(byte[] bArr) {
    if (((long) bArr.length) < a) {
        return new ByteArrayEntity(bArr);
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    OutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
    gZIPOutputStream.write(bArr);
    gZIPOutputStream.close();
    AbstractHttpEntity byteArrayEntity = new ByteArrayEntity(byteArrayOutputStream.toByteArray());
    byteArrayEntity.setContentEncoding(AsyncHttpClient.ENCODING_GZIP);
    new StringBuilder("gzip size:").append(bArr.length).append("->").append(byteArrayEntity.getContentLength());
    return byteArrayEntity;
}
 
Example 18
Project: boohee_v5.6   File: WXMediaMessage.java   View Source Code Vote up 5 votes
public final void setThumbImage(Bitmap bitmap) {
    try {
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 85, byteArrayOutputStream);
        this.thumbData = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
    } catch (Throwable e) {
        Ln.e(e);
        Ln.e("put thumb failed", new Object[0]);
    }
}
 
Example 19
Project: boohee_v5.6   File: WXImageObject.java   View Source Code Vote up 5 votes
public WXImageObject(Bitmap bitmap) {
    try {
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 85, byteArrayOutputStream);
        this.imageData = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
    } catch (Throwable e) {
        Ln.e(e);
    }
}
 
Example 20
Project: boohee_v5.6   File: WechatHelper.java   View Source Code Vote up 5 votes
private void a(Context context, String str, String str2, Bitmap bitmap, int i, k kVar) {
    Object wXImageObject = new WXImageObject();
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, byteArrayOutputStream);
    byteArrayOutputStream.flush();
    byteArrayOutputStream.close();
    wXImageObject.imageData = byteArrayOutputStream.toByteArray();
    WXMediaMessage wXMediaMessage = new WXMediaMessage();
    wXMediaMessage.title = str;
    wXMediaMessage.mediaObject = wXImageObject;
    wXMediaMessage.description = str2;
    wXMediaMessage.thumbData = a(context, wXImageObject.imageData);
    a(wXMediaMessage, SocialConstants.PARAM_IMG_URL, i, kVar);
}