use of java.io.ByteArrayOutputStream in project libgdx by libgdx.
the class StreamUtils method copyStreamToByteArray.
/** Copy the data from an {@link InputStream} to a byte array. The stream is not closed.
* @param estimatedSize Used to allocate the output byte[] to possibly avoid an array copy. */
public static byte[] copyStreamToByteArray(InputStream input, int estimatedSize) throws IOException {
ByteArrayOutputStream baos = new OptimizedByteArrayOutputStream(Math.max(0, estimatedSize));
copyStream(input, baos);
return baos.toByteArray();
}
use of java.io.ByteArrayOutputStream in project Talon-for-Twitter by klinker24.
the class SendTweet method sendTweet.
public boolean sendTweet(AppSettings settings, Context context) {
try {
Twitter twitter = getTwitter();
if (remainingChars < 0 && !pwiccer) {
// twitlonger goes here
TwitLongerHelper helper = new TwitLongerHelper(message, twitter);
helper.setInReplyToStatusId(tweetId);
return helper.createPost() != 0;
} else {
twitter4j.StatusUpdate reply = new twitter4j.StatusUpdate(message);
reply.setInReplyToStatusId(tweetId);
if (!attachedUri.equals("")) {
// context being the Activity pointer
File outputDir = context.getCacheDir();
File f = File.createTempFile("compose", "picture", outputDir);
Bitmap bitmap = getBitmapToSend(Uri.parse(attachedUri), context);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
if (!settings.twitpic) {
reply.setMedia(f);
twitter.updateStatus(reply);
return true;
} else {
TwitPicHelper helper = new TwitPicHelper(twitter, message, f, context);
helper.setInReplyToStatusId(tweetId);
return helper.createPost() != 0;
}
} else {
// no picture
twitter.updateStatus(reply);
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of java.io.ByteArrayOutputStream in project disconf by knightliao.
the class MyStringUtils method inputStreamToString.
/**
* 将InputStream转换成指定编码的String
*/
private static String inputStreamToString(InputStream in, String encoding) throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
int count = -1;
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
outStream.write(data, 0, count);
}
return new String(outStream.toByteArray(), encoding);
}
use of java.io.ByteArrayOutputStream in project Lazy by l123456789jy.
the class BitmapUtil method getBytesFromBitmap.
/**
* 把bitmap转化为bytes
*
* @param bitmap 源Bitmap
* @return Byte数组
*/
public static byte[] getBytesFromBitmap(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
use of java.io.ByteArrayOutputStream in project cordova-android-chromeview by thedracle.
the class CameraLauncher method processPicture.
/**
* Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
*
* @param bitmap
*/
public void processPicture(Bitmap bitmap) {
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
try {
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encode(code, Base64.DEFAULT);
String js_out = new String(output);
this.callbackContext.success(js_out);
js_out = null;
output = null;
code = null;
}
} catch (Exception e) {
this.failPicture("Error compressing image.");
}
jpeg_data = null;
}
Aggregations