Search in sources :

Example 61 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project killbill by killbill.

the class TestDatabaseExportDao method getDump.

private String getDump() {
    final DatabaseExportOutputStream out = new CSVExportOutputStream(new ByteArrayOutputStream());
    dao.exportDataForAccount(out, internalCallContext);
    return out.toString();
}
Also used : DatabaseExportOutputStream(org.killbill.billing.util.api.DatabaseExportOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 62 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project ion by koush.

the class PojoBody method getBodyBytes.

byte[] getBodyBytes() {
    if (bodyBytes != null)
        return bodyBytes;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    OutputStreamWriter out = new OutputStreamWriter(bout);
    if (type == null)
        gson.toJson(pojo, out);
    else
        gson.toJson(pojo, type, out);
    try {
        out.flush();
        bout.flush();
    } catch (Exception e) {
    }
    bodyBytes = bout.toByteArray();
    return bodyBytes;
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 63 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project ion by koush.

the class ProgressTests method testProgress.

public void testProgress() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    final Semaphore progressSemaphore = new Semaphore(0);
    final Md5 md5 = Md5.createInstance();
    Ion.with(getContext()).load("https://raw.githubusercontent.com/koush/AndroidAsync/master/AndroidAsync/test/assets/6691924d7d24237d3b3679310157d640").setHandler(null).setTimeout(600000).setLogging("testProgress", Log.VERBOSE).progress(new ProgressCallback() {

        @Override
        public void onProgress(long downloaded, long total) {
            // depending on gzip, etc. the total may vary... the actual length of the uncompressed data
            // is 100000
            assertTrue(total > 90000 && total < 110000);
            progressSemaphore.release();
        }
    }).write(new ByteArrayOutputStream()).setCallback(new FutureCallback<ByteArrayOutputStream>() {

        @Override
        public void onCompleted(Exception e, ByteArrayOutputStream result) {
            byte[] bytes = result.toByteArray();
            md5.update(new ByteBufferList(bytes));
            assertEquals(md5.digest(), dataNameAndHash);
            semaphore.release();
        }
    });
    assertTrue(semaphore.tryAcquire(600000, TimeUnit.MILLISECONDS));
    assertTrue(progressSemaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
}
Also used : ByteBufferList(com.koushikdutta.async.ByteBufferList) ProgressCallback(com.koushikdutta.ion.ProgressCallback) Semaphore(java.util.concurrent.Semaphore) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 64 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project eweb4j-framework by laiweiwei.

the class ThumbUtil method generateThumb.

public static ByteArrayOutputStream generateThumb(String imagePath, int sharpenTimes, float quality, float contrast, float brightness, String outputFormat, int failRetryTimes, long sleep, int outputWidth, int outputHeight, boolean isCrop) throws Exception {
    BufferedImage img = generate(imagePath, sharpenTimes, quality, contrast, brightness, outputFormat, failRetryTimes, sleep, outputWidth, outputHeight, isCrop);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ImageIO.write(img, outputFormat, os);
    return os;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage)

Example 65 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project eweb4j-framework by laiweiwei.

the class CommonUtil method serialize.

public static <T> byte[] serialize(T obj) {
    ObjectOutputStream oos = null;
    ByteArrayOutputStream os = null;
    try {
        os = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(os);
        oos.writeObject(obj);
        return os.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (oos != null) {
            try {
                os.close();
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

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