Search in sources :

Example 86 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project questdb by bluestreak01.

the class AppendObjectBlobs method processDir.

private static int processDir(JournalWriter writer, File dir) throws JournalException, IOException {
    int count = 0;
    File[] files = dir.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f.isDirectory()) {
                count += processDir(writer, f);
                continue;
            }
            JournalEntryWriter w = writer.entryWriter(System.currentTimeMillis());
            w.putSym(0, f.getAbsolutePath());
            try (InputStream in = new FileInputStream(f)) {
                try (GZIPOutputStream out = new GZIPOutputStream(w.putBin(1))) {
                    pump(in, out);
                }
            }
            w.append();
            count++;
        }
        writer.commit();
    }
    return count;
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 87 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project nifi by apache.

the class TestPersistentProvenanceRepository method testWithWithEventFileMissingRecord.

/**
 * Here the event file is simply corrupted by virtue of not having any event
 * records while having correct headers
 */
@Test
public void testWithWithEventFileMissingRecord() throws Exception {
    assumeFalse(isWindowsEnvironment());
    File eventFile = this.prepCorruptedEventFileTests();
    final Query query = new Query(UUID.randomUUID().toString());
    query.addSearchTerm(SearchTerms.newSearchTerm(SearchableFields.ComponentID, "foo-*"));
    query.setMaxResults(100);
    DataOutputStream in = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(eventFile)));
    in.writeUTF("BlahBlah");
    in.writeInt(4);
    in.close();
    assertTrue(eventFile.exists());
    final QueryResult result = repo.queryEvents(query, createUser());
    assertEquals(10, result.getMatchingEvents().size());
}
Also used : QueryResult(org.apache.nifi.provenance.search.QueryResult) Query(org.apache.nifi.provenance.search.Query) GZIPOutputStream(java.util.zip.GZIPOutputStream) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) TestUtil.createFlowFile(org.apache.nifi.provenance.TestUtil.createFlowFile) FlowFile(org.apache.nifi.flowfile.FlowFile) File(java.io.File) Test(org.junit.Test)

Example 88 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project nifi by apache.

the class TestPersistentProvenanceRepository method testWithWithEventFileCorrupted.

/**
 * Here the event file is simply corrupted by virtue of being empty (0
 * bytes)
 */
@Test
public void testWithWithEventFileCorrupted() throws Exception {
    assumeFalse(isWindowsEnvironment());
    File eventFile = this.prepCorruptedEventFileTests();
    final Query query = new Query(UUID.randomUUID().toString());
    query.addSearchTerm(SearchTerms.newSearchTerm(SearchableFields.ComponentID, "foo-*"));
    query.setMaxResults(100);
    DataOutputStream in = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(eventFile)));
    in.close();
    final QueryResult result = repo.queryEvents(query, createUser());
    assertEquals(10, result.getMatchingEvents().size());
}
Also used : QueryResult(org.apache.nifi.provenance.search.QueryResult) Query(org.apache.nifi.provenance.search.Query) GZIPOutputStream(java.util.zip.GZIPOutputStream) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) TestUtil.createFlowFile(org.apache.nifi.provenance.TestUtil.createFlowFile) FlowFile(org.apache.nifi.flowfile.FlowFile) File(java.io.File) Test(org.junit.Test)

Example 89 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project coprhd-controller by CoprHD.

the class WorkflowHelper method makeArchive.

/**
 * @param out
 * @param workflowPackage
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonGenerationException
 */
private static void makeArchive(final ByteArrayOutputStream out, final CustomServicesWorkflowPackage workflowPackage) throws IOException {
    try (final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(out)))) {
        tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (final Entry<URI, CustomServicesWorkflowRestRep> workflow : workflowPackage.workflows().entrySet()) {
            final String name = WORKFLOWS_FOLDER + "/" + workflow.getKey().toString();
            final byte[] content = MAPPER.writeValueAsBytes(workflow.getValue());
            final Date modTime = workflow.getValue().getCreationTime().getTime();
            addArchiveEntry(tarOut, name, modTime, content);
        }
        for (final Entry<URI, CustomServicesPrimitiveRestRep> operation : workflowPackage.operations().entrySet()) {
            final String name = OPERATIONS_FOLDER + "/" + operation.getKey().toString();
            final byte[] content = MAPPER.writeValueAsBytes(operation.getValue());
            final Date modTime = operation.getValue().getCreationTime().getTime();
            addArchiveEntry(tarOut, name, modTime, content);
        }
        for (final Entry<URI, ResourcePackage> resource : workflowPackage.resources().entrySet()) {
            final String name = RESOURCES_FOLDER + "/" + resource.getKey().toString() + ".md";
            final String resourceFile = RESOURCES_FOLDER + "/" + resource.getKey().toString();
            final byte[] metadata = MAPPER.writeValueAsBytes(resource.getValue().metadata());
            final Date modTime = resource.getValue().metadata().getCreationTime().getTime();
            addArchiveEntry(tarOut, name, modTime, metadata);
            addArchiveEntry(tarOut, resourceFile, modTime, resource.getValue().bytes());
        }
        tarOut.finish();
    }
}
Also used : CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) GZIPOutputStream(java.util.zip.GZIPOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) BufferedOutputStream(java.io.BufferedOutputStream)

Example 90 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project indy by Commonjava.

the class StorageFileIO method write.

@Override
public void write(MarshalledEntry<? extends String, ? extends byte[]> entry) {
    String key = entry.getKey();
    logKey("write()", key);
    Path path = Paths.get(storageRoot, key);
    File dir = path.getParent().toFile();
    if (!dir.isDirectory() && !dir.mkdirs()) {
        throw new RuntimeException("Cannot create storage directory: " + dir);
    }
    try (ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(path.toFile())))) {
        out.writeObject(new StorageFileEntry(entry));
    } catch (IOException e) {
        throw new RuntimeException("Cannot store: " + path, e);
    }
}
Also used : Path(java.nio.file.Path) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File)

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