package org.ovirt.engine.core.utils.archivers.tar;

import java.io.OutputStream;

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;

public class InMemoryTar implements AutoCloseable{
    private TarArchiveOutputStream tarArchiveOutputStream;

    public InMemoryTar(OutputStream outputStream) {
        tarArchiveOutputStream = new TarArchiveOutputStream(outputStream);
    }

    public void addTarEntry(byte[] data, String name) throws Exception {
        TarArchiveEntry entry = new TarArchiveEntry(name);
        entry.setSize(data.length);
        tarArchiveOutputStream.putArchiveEntry(entry);
        tarArchiveOutputStream.write(data);
        tarArchiveOutputStream.closeArchiveEntry();
    }

    @Override
    public void close() throws Exception {
        tarArchiveOutputStream.close();
    }
}

Add support for creating in memory tar
core: Add support for creating in memory tar

Change-Id: I090ab5f9323dca57e8de191c1bc32cd5a164b71d
Signed-off-by: Liron Aravot <3348b1f361b8c114be0a6d9109c20a9213007b88@redhat.com>
