Search in sources :

Example 91 with GZIPOutputStream

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();
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 92 with GZIPOutputStream

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream)

Example 93 with GZIPOutputStream

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();
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry)

Example 94 with GZIPOutputStream

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();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 95 with GZIPOutputStream

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();
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Aggregations

GZIPOutputStream (java.util.zip.GZIPOutputStream)835 ByteArrayOutputStream (java.io.ByteArrayOutputStream)339 IOException (java.io.IOException)254 FileOutputStream (java.io.FileOutputStream)251 OutputStream (java.io.OutputStream)185 File (java.io.File)179 Test (org.junit.Test)93 BufferedOutputStream (java.io.BufferedOutputStream)84 GZIPInputStream (java.util.zip.GZIPInputStream)77 FileInputStream (java.io.FileInputStream)72 InputStream (java.io.InputStream)64 ByteArrayInputStream (java.io.ByteArrayInputStream)60 OutputStreamWriter (java.io.OutputStreamWriter)53 ObjectOutputStream (java.io.ObjectOutputStream)39 DataOutputStream (java.io.DataOutputStream)38 BufferedWriter (java.io.BufferedWriter)30 ByteBuffer (java.nio.ByteBuffer)28 Path (java.nio.file.Path)28 ArrayList (java.util.ArrayList)28 NodeSettings (org.knime.core.node.NodeSettings)28