Search in sources :

Example 66 with ByteArrayOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 67 with ByteArrayOutputStream

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;
    }
}
Also used : Bitmap(android.graphics.Bitmap) TwitPicHelper(com.klinker.android.twitter.utils.api_helper.TwitPicHelper) FileOutputStream(java.io.FileOutputStream) Twitter(twitter4j.Twitter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) TwitLongerHelper(com.klinker.android.twitter.utils.api_helper.TwitLongerHelper) IOException(java.io.IOException)

Example 68 with ByteArrayOutputStream

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);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 69 with ByteArrayOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 70 with ByteArrayOutputStream

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;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) JSONException(org.json.JSONException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)8438 Test (org.junit.Test)2232 ByteArrayInputStream (java.io.ByteArrayInputStream)2148 IOException (java.io.IOException)2037 PrintStream (java.io.PrintStream)800 InputStream (java.io.InputStream)765 ObjectOutputStream (java.io.ObjectOutputStream)759 DataOutputStream (java.io.DataOutputStream)705 ObjectInputStream (java.io.ObjectInputStream)361 File (java.io.File)331 OutputStream (java.io.OutputStream)318 HashMap (java.util.HashMap)279 ArrayList (java.util.ArrayList)264 FileInputStream (java.io.FileInputStream)211 OutputStreamWriter (java.io.OutputStreamWriter)207 DataInputStream (java.io.DataInputStream)198 Test (org.testng.annotations.Test)184 PrintWriter (java.io.PrintWriter)162 URL (java.net.URL)160 Map (java.util.Map)158