[jboss-svn-commits] JBoss Common SVN: r3944 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jan 21 00:18:35 EST 2010


Author: ALRubinger
Date: 2010-01-21 00:18:34 -0500 (Thu, 21 Jan 2010)
New Revision: 3944

Modified:
   shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExporter.java
   shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterImpl.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
Log:
[SHRINKWRAP-121] Support ZipExporter.exportZip(OutputStream)

Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExporter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExporter.java	2010-01-21 05:03:50 UTC (rev 3943)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExporter.java	2010-01-21 05:18:34 UTC (rev 3944)
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.jboss.shrinkwrap.api.Assignable;
 
@@ -58,6 +59,17 @@
 
    /**
     * Exports provided archive as a ZIP archive, written to the 
+    * specified {@link OutputStream} target.  The specified
+    * target will be closed upon completion.
+    * 
+    * @param target
+    * @throws ArchiveExportException
+    * @throws IllegalArgumentException If the target is not specified
+    */
+   void exportZip(OutputStream target) throws ArchiveExportException, IllegalArgumentException;
+
+   /**
+    * Exports provided archive as a ZIP archive, written to the 
     * specified {@link File} target.  If the target both exists and the "overwrite"
     * flag is true, this call will allow the existing file to be overwritten, else
     * the invocation will fail with {@link IllegalArgumentException}

Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterImpl.java	2010-01-21 05:03:50 UTC (rev 3943)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterImpl.java	2010-01-21 05:18:34 UTC (rev 3944)
@@ -105,6 +105,36 @@
    }
 
    /**
+    * @see org.jboss.shrinkwrap.api.exporter.ZipExporter#exportZip(java.io.OutputStream)
+    */
+   @Override
+   public void exportZip(final OutputStream target) throws ArchiveExportException, IllegalArgumentException
+   {
+      // Precondition checks
+      if (target == null)
+      {
+         throw new IllegalArgumentException("Target must be specified");
+      }
+
+      // Get Streams
+      final ZipExportTask handle = this.exportZip();
+      final InputStream in = handle.getContent();
+
+      // Write out
+      try
+      {
+         IOUtil.copyWithClose(in, target);
+      }
+      catch (final IOException e)
+      {
+         throw new ArchiveExportException("Error encountered in exporting archive to " + target, e);
+      }
+
+      // Ensure done and no exceptions (this also will throw ArchiveExportException)
+      handle.checkComplete();
+   }
+
+   /**
     * {@inheritDoc}
     * @see org.jboss.shrinkwrap.api.exporter.ZipExporter#exportZip(java.io.File, boolean)
     */
@@ -124,9 +154,7 @@
                + target.getAbsolutePath());
       }
 
-      // Get Streams
-      final ZipExportTask handle = this.exportZip();
-      final InputStream in = handle.getContent();
+      // Get Stream
       final OutputStream out;
       try
       {
@@ -138,17 +166,7 @@
       }
 
       // Write out
-      try
-      {
-         IOUtil.copyWithClose(in, out);
-      }
-      catch (final IOException e)
-      {
-         throw new ArchiveExportException("Error encountered in exporting archive to " + target.getAbsolutePath(), e);
-      }
-
-      // Ensure done and no exceptions (this also will throw ArchiveExportException)
-      handle.checkComplete();
+      this.exportZip(out);
    }
 
    /**

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2010-01-21 05:03:50 UTC (rev 3943)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2010-01-21 05:18:34 UTC (rev 3944)
@@ -198,6 +198,34 @@
    }
 
    /**
+    * Test to make sure an archive can be exported to Zip (OutStream) and all 
+    * contents are correctly located in the Zip.
+    * @throws Exception
+    */
+   @Test
+   public void testExportZipToOutStream() throws IOException
+   {
+      log.info("testExportZipToOutStream");
+
+      // Get a temp directory for the test
+      final File tempDirectory = createTempDirectory("testExportZipToOutStream");
+
+      // Get an archive instance
+      Archive<?> archive = createArchiveWithAssets();
+
+      // Export as OutStream and flush to a file manually
+      final File serializedArchive = new File(tempDirectory, archive.getName());
+      final OutputStream out = new FileOutputStream(serializedArchive);
+      archive.as(ZipExporter.class).exportZip(out);
+
+      // Get as ZipFile
+      final ZipFile expectedZip = new ZipFile(serializedArchive);
+
+      // Validate
+      ensureZipFileInExpectedForm(expectedZip);
+   }
+
+   /**
     * Test to make sure an archive can be exported to Zip (file) and all 
     * contents are correctly located in the Zip.
     * @throws Exception



More information about the jboss-svn-commits mailing list