Liron Ar has uploaded a new change for review.

Change subject: core: Add support for creating in memory tar
......................................................................

core: Add support for creating in memory tar

Change-Id: I090ab5f9323dca57e8de191c1bc32cd5a164b71d
Signed-off-by: Liron Aravot <lara...@redhat.com>
---
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/InMemoryTar.java
1 file changed, 41 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/66/23466/1

diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/InMemoryTar.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/InMemoryTar.java
new file mode 100644
index 0000000..642efa9
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/InMemoryTar.java
@@ -0,0 +1,41 @@
+package org.ovirt.engine.core.utils.archivers.tar;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class InMemoryTar {
+    private static final Log log = LogFactory.getLog(InMemoryTar.class);
+    TarArchiveOutputStream tarArchiveOutputStream;
+
+    public InMemoryTar(OutputStream outputStream) {
+        this.tarArchiveOutputStream = new TarArchiveOutputStream(outputStream);
+    }
+
+    public void addTarEntry(byte[] data, String name) {
+        try {
+            TarArchiveEntry entry = new TarArchiveEntry(name);
+            entry.setSize(data.length);
+            tarArchiveOutputStream.putArchiveEntry(entry);
+            tarArchiveOutputStream.write(data);
+            tarArchiveOutputStream.closeArchiveEntry();
+        } catch (IOException e) {
+            log.error("Error while writing entry to tar", e);
+            closeTar();
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void closeTar() {
+        try {
+            tarArchiveOutputStream.close();
+        } catch(IOException e) {
+            log.error("Error while closing tar", e);
+            throw new RuntimeException(e);
+        }
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/23466
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I090ab5f9323dca57e8de191c1bc32cd5a164b71d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Liron Ar <lara...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to