本文整理汇总了Java中java.io.OutputStream.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStream.toByteArray方法的具体用法?Java OutputStream.toByteArray怎么用?Java OutputStream.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.OutputStream
的用法示例。
在下文中一共展示了OutputStream.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: c
import java.io.OutputStream; //导入方法依赖的package包/类
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;
}
示例2: a
import java.io.OutputStream; //导入方法依赖的package包/类
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()));
}
示例3: i
import java.io.OutputStream; //导入方法依赖的package包/类
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;
}
示例4: textCompress
import java.io.OutputStream; //导入方法依赖的package包/类
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 "";
}
}
示例5: a
import java.io.OutputStream; //导入方法依赖的package包/类
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();
}
}
示例6: setAvator
import java.io.OutputStream; //导入方法依赖的package包/类
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");
}
示例7: b
import java.io.OutputStream; //导入方法依赖的package包/类
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);
}
示例8: a
import java.io.OutputStream; //导入方法依赖的package包/类
public static byte[] a(InputStream inputStream) throws IOException {
if (inputStream == null) {
return null;
}
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
a(inputStream, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
示例9: a
import java.io.OutputStream; //导入方法依赖的package包/类
public byte[] a(InputStream inputStream) throws IOException {
if (inputStream == null) {
return null;
}
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
jn.a(inputStream, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
示例10: bytes
import java.io.OutputStream; //导入方法依赖的package包/类
public byte[] bytes() throws HttpRequestException {
OutputStream output = byteStream();
try {
copy(buffer(), output);
return output.toByteArray();
} catch (IOException e) {
throw new HttpRequestException(e);
}
}
示例11: WXImageObject
import java.io.OutputStream; //导入方法依赖的package包/类
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();
}
}
示例12: b
import java.io.OutputStream; //导入方法依赖的package包/类
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;
}
示例13: decode
import java.io.OutputStream; //导入方法依赖的package包/类
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);
}
}
示例14: encode
import java.io.OutputStream; //导入方法依赖的package包/类
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);
}
}
示例15: a
import java.io.OutputStream; //导入方法依赖的package包/类
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;
}