use of java.util.zip.GZIPOutputStream in project sling by apache.
the class JSONRecording method toJSON.
private byte[] toJSON() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (compress) {
os = new GZIPOutputStream(os);
}
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
JSONWriter jw = new JSONWriter(osw);
jw.object();
jw.key("method").value(method);
timeTaken = System.currentTimeMillis() - start;
jw.key("time").value(timeTaken);
jw.key("timestamp").value(start);
addRequestProgressLogs(jw);
queryCollector.done();
addJson(jw, "queries", queries);
addJson(jw, "logs", logs);
addLoggerNames(jw);
jw.endObject();
osw.flush();
os.close();
return baos.toByteArray();
}
use of java.util.zip.GZIPOutputStream in project bnd by bndtools.
the class Sed method gzFile2GzFile.
public static void gzFile2GzFile(String filenameIn, String searchPattern, String replacementPattern, String filenameOut) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filenameIn))));
BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(filenameOut)));
processObrFileInternal(reader, searchPattern, replacementPattern, out);
}
use of java.util.zip.GZIPOutputStream in project dhis2-core by dhis2.
the class XmlMessageConverter method writeInternal.
@Override
protected void writeInternal(RootNode rootNode, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (Compression.GZIP == compression) {
if (!outputMessage.getHeaders().getFirst(ContextUtils.HEADER_CONTENT_DISPOSITION).contains("attachment")) {
outputMessage.getHeaders().set(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=metadata.xml.gz");
outputMessage.getHeaders().set(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
}
GZIPOutputStream outputStream = new GZIPOutputStream(outputMessage.getBody());
nodeService.serialize(rootNode, "application/xml", outputStream);
outputStream.close();
} else if (Compression.ZIP == compression) {
if (!outputMessage.getHeaders().getFirst(ContextUtils.HEADER_CONTENT_DISPOSITION).contains("attachment")) {
outputMessage.getHeaders().set(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=metadata.xml.zip");
outputMessage.getHeaders().set(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
}
ZipOutputStream outputStream = new ZipOutputStream(outputMessage.getBody());
outputStream.putNextEntry(new ZipEntry("metadata.xml"));
nodeService.serialize(rootNode, "application/xml", outputStream);
outputStream.close();
} else {
nodeService.serialize(rootNode, "application/xml", outputMessage.getBody());
outputMessage.getBody().close();
}
}
use of java.util.zip.GZIPOutputStream in project android_frameworks_base by crdroidandroid.
the class DropBoxTest method testAddEntriesInTheFuture.
public void testAddEntriesInTheFuture() throws Exception {
File dir = getEmptyDir("testAddEntriesInTheFuture");
long before = System.currentTimeMillis();
// Near future: should be allowed to persist
FileWriter w0 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 5000) + ".txt"));
w0.write("FUTURE0");
w0.close();
// Far future: should be collapsed
FileWriter w1 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 100000) + ".txt"));
w1.write("FUTURE1");
w1.close();
// Another far future item, this one gzipped
File f2 = new File(dir, "DropBoxTest@" + (before + 100001) + ".txt.gz");
GZIPOutputStream gz2 = new GZIPOutputStream(new FileOutputStream(f2));
gz2.write("FUTURE2".getBytes());
gz2.close();
// Tombstone in the far future
new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
// Until a write, the timestamps are taken at face value
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
assertEquals("FUTURE0", e0.getText(80));
assertEquals("FUTURE1", e1.getText(80));
assertEquals("FUTURE2", e2.getText(80));
assertEquals(null, e3.getText(80));
assertEquals(before + 5000, e0.getTimeMillis());
assertEquals(before + 100000, e1.getTimeMillis());
assertEquals(before + 100001, e2.getTimeMillis());
assertEquals(before + 100002, e3.getTimeMillis());
e0.close();
e1.close();
e2.close();
e3.close();
// Write something to force a collapse
dropbox.addText("NotDropBoxTest", "FUTURE");
e0 = dropbox.getNextEntry(null, before);
e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
assertEquals("FUTURE0", e0.getText(80));
assertEquals("FUTURE1", e1.getText(80));
assertEquals("FUTURE2", e2.getText(80));
assertEquals(null, e3.getText(80));
assertEquals(before + 5000, e0.getTimeMillis());
assertEquals(before + 5001, e1.getTimeMillis());
assertEquals(before + 5002, e2.getTimeMillis());
assertEquals(before + 5003, e3.getTimeMillis());
e0.close();
e1.close();
e2.close();
e3.close();
}
use of java.util.zip.GZIPOutputStream in project bnd by bndtools.
the class XMLResourceGenerator method save.
public void save(OutputStream out) throws IOException {
try {
if (compress) {
out = new GZIPOutputStream(out);
}
try (Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
PrintWriter pw = new PrintWriter(writer)) {
pw.printf("<?xml version='1.0' encoding='UTF-8'?>\n");
repository.print(indent, pw);
}
} finally {
out.close();
}
}
Aggregations