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();
}
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;
}
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));
}
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;
}
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;
}
Aggregations