[jboss-svn-commits] JBoss Common SVN: r3945 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 21 20:07:25 EST 2010
Author: ALRubinger
Date: 2010-01-21 20:07:24 -0500 (Thu, 21 Jan 2010)
New Revision: 3945
Added:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/FutureCompletionInputStream.java
Removed:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExportTask.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/IsReadReportingInputStream.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportHandleImpl.java
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/JdkZipExporterDelegate.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipArchiveInputStreamFactory.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
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
Log:
[SHRINKWRAP-116] Abstract concurrent ZIP export from the user completely
Deleted: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExportTask.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExportTask.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExportTask.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.shrinkwrap.api.exporter;
-
-import java.io.InputStream;
-
-/**
- * Handle returned to callers from a request to export via
- * the {@link ZipExporter}. As the encoding process is an asynchronous
- * operation, here we provide the user access to read the
- * content as well as check for completeness and integrity.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- */
-public interface ZipExportTask
-{
- /**
- * Obtains an {@link InputStream} from which the encoded
- * content may be read.
- *
- * @return
- */
- InputStream getContent();
-
- /**
- * Blocking operation which will wait until the encoding process's internal
- * streams have been closed and verified for integrity. Do not call this method
- * until all bytes have been read from {@link ZipExportTask#getContent()}; otherwise
- * this may introduce a deadlock. Any problems with the encoding process will be reported
- * by throwing {@link ArchiveExportException}.
- * @return
- * @throws ArchiveExportException If an error occurred during export
- * @throws IllegalStateException If invoked before {@link ZipExportTask#getContent()} has been
- * fully-read
- */
- void checkComplete() throws ArchiveExportException, IllegalStateException;
-}
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:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/exporter/ZipExporter.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -42,7 +42,7 @@
*
* @return {@link InputStream} for exported Zip
*/
- ZipExportTask exportZip();
+ InputStream exportZip();
/**
* Exports provided archive as a ZIP archive, written to the
Copied: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/FutureCompletionInputStream.java (from rev 3944, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/IsReadReportingInputStream.java)
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/FutureCompletionInputStream.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/FutureCompletionInputStream.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.impl.base.exporter;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
+
+/**
+ * {@link PipedInputStream} which, when fully-read, will
+ * block upon a {@link Future} and report any exceptional
+ * circumstances to the owning Thread.
+ *
+ * @param <T> Response type of the {@link Future}
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ */
+class FutureCompletionInputStream extends PipedInputStream
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(FutureCompletionInputStream.class.getName());
+
+ /**
+ * Number of bytes read signaling the end has been reached
+ */
+ private static final int EOF = -1;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The job upon which we'll block and obtain any exceptions from when we're done reading
+ */
+ private final Future<?> job;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new Stream
+ */
+ public FutureCompletionInputStream(final Future<?> job)
+ {
+ super();
+ this.job = job;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.io.PipedInputStream#read()
+ */
+ @Override
+ public synchronized int read() throws IOException
+ {
+ final int bytesRead = super.read();
+ this.awaitOnFutureOnDone(bytesRead);
+ return bytesRead;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.io.PipedInputStream#read(byte[], int, int)
+ */
+ @Override
+ public synchronized int read(byte[] b, int off, int len) throws IOException
+ {
+ final int bytesRead = super.read(b, off, len);
+ this.awaitOnFutureOnDone(bytesRead);
+ return bytesRead;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * If we've read the full stream, awaits on {@link FutureCompletionInputStream#job},
+ * reporting any exceptions
+ * wrapped in an {@link ArchiveExportException}.
+ *
+ * @param bytesRead
+ * @throws ArchiveExportException
+ */
+ private void awaitOnFutureOnDone(final int bytesRead) throws ArchiveExportException
+ {
+ if (bytesRead == EOF)
+ {
+ try
+ {
+ // Block until the streams have been closed in the underlying job
+ job.get();
+ }
+ catch (final InterruptedException e)
+ {
+ Thread.interrupted();
+ log.log(Level.WARNING, "We've been interrupted while waiting for the export process to complete", e);
+ }
+ // Some error
+ catch (final ExecutionException ee)
+ {
+ // Unwrap and rethrow
+ final Throwable cause = ee.getCause();
+ if (cause == null)
+ {
+ throw new IllegalStateException("Cause of execution failure not specified: ", ee);
+ }
+ // Wrap as our exception type and rethrow
+ throw new ArchiveExportException(cause);
+ }
+ }
+ }
+}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/IsReadReportingInputStream.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/IsReadReportingInputStream.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/IsReadReportingInputStream.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.shrinkwrap.impl.base.exporter;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-
-/**
- * {@link PipedInputStream} which may report whether or not
- * it has been fully read.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- */
-class IsReadReportingInputStream extends PipedInputStream
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Number of bytes read signaling the end has been reached
- */
- private static final int EOF = -1;
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Flag showing whether or not we've been fully-read
- */
- private boolean isRead;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new Stream
- */
- public IsReadReportingInputStream()
- {
- super();
- }
-
- /**
- * {@inheritDoc}
- * @see java.io.PipedInputStream#read()
- */
- @Override
- public synchronized int read() throws IOException
- {
- final int bytesRead = super.read();
- this.markReadOnStreamEnd(bytesRead);
- return bytesRead;
- }
-
- /**
- * {@inheritDoc}
- * @see java.io.PipedInputStream#read(byte[], int, int)
- */
- @Override
- public synchronized int read(byte[] b, int off, int len) throws IOException
- {
- final int bytesRead = super.read(b, off, len);
- this.markReadOnStreamEnd(bytesRead);
- return bytesRead;
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Marks this stream as read
- * if the number of bytes specified is equal to {@link IsReadReportingInputStream#EOF}
- */
- private void markReadOnStreamEnd(final int bytesRead)
- {
- if (bytesRead == EOF)
- {
- try
- {
- isRead = true;
- }
- catch (final Exception e)
- {
- throw new RuntimeException("Encountered exception in callback", e);
- }
- }
- }
-
- /**
- * Returns whether or not this stream has been fully read
- * @return
- */
- boolean isRead()
- {
- return isRead;
- }
-}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -23,6 +23,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -36,7 +37,6 @@
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
-import org.jboss.shrinkwrap.api.exporter.ZipExportTask;
import org.jboss.shrinkwrap.impl.base.asset.DirectoryAsset;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.jboss.shrinkwrap.impl.base.io.StreamErrorHandler;
@@ -51,7 +51,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class JdkZipExporterDelegate extends AbstractExporterDelegate<ZipExportTask>
+public class JdkZipExporterDelegate extends AbstractExporterDelegate<InputStream>
{
//-------------------------------------------------------------------------------------||
// Class Members ----------------------------------------------------------------------||
@@ -81,9 +81,9 @@
private ZipOutputStream zipOutputStream;
/**
- * Handle to be returned to the caller
+ * {@link InputStream} to be returned to the caller
*/
- private ZipExportTask handle;
+ private InputStream inputStream;
/**
* A Set of Paths we've exported so far (so that we don't write
@@ -91,6 +91,11 @@
*/
private Set<ArchivePath> pathsExported = new HashSet<ArchivePath>();
+ /**
+ * Synchronization point where the encoding process will wait until all streams have been set up
+ */
+ private final CountDownLatch latch = new CountDownLatch(1);
+
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -163,8 +168,17 @@
}
};
+ // Get a handle and return it to the caller
+ final Future<Void> job = service.submit(exportTask);
+
+ /*
+ * At this point the job will start, but hit the latch until we set up the streams
+ * and tell it to proceed.
+ */
+
// Stream to return to the caller
- final IsReadReportingInputStream input = new IsReadReportingInputStream();
+ final FutureCompletionInputStream input = new FutureCompletionInputStream(job);
+ inputStream = input;
/**
* OutputStream which will be associated with the returned InStream, and the
@@ -183,10 +197,11 @@
// Set up the stream to which we'll write entries, backed by the piped stream
zipOutputStream = new ZipOutputStream(output);
- // Get a handle and return it to the caller
- final Future<Void> job = service.submit(exportTask);
- final ZipExportTask handle = new ZipExportHandleImpl(input, job);
- this.handle = handle;
+ /*
+ * The job is now waiting on us to signal that we've set up the streams;
+ * let it continue
+ */
+ latch.countDown();
}
/**
@@ -258,6 +273,12 @@
// Make a ZipEntry
final ZipEntry entry = new ZipEntry(resolvedPath);
+ /*
+ * Wait until all streams have been set up for encoding, or
+ * do nothing if everything's set up already
+ */
+ latch.await();
+
// Write the Asset under the same Path name in the Zip
try
{
@@ -300,9 +321,9 @@
* @see org.jboss.shrinkwrap.impl.base.exporter.AbstractExporterDelegate#getResult()
*/
@Override
- protected ZipExportTask getResult()
+ protected InputStream getResult()
{
- return handle;
+ return inputStream;
}
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipArchiveInputStreamFactory.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipArchiveInputStreamFactory.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipArchiveInputStreamFactory.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -45,7 +45,7 @@
protected InputStream doGetInputStream(Archive<?> archive)
{
// Get InputStream from the ZipExporter
- final InputStream inputStream = archive.as(ZipExporter.class).exportZip().getContent();
+ final InputStream inputStream = archive.as(ZipExporter.class).exportZip();
// Return input stream
return inputStream;
}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportHandleImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportHandleImpl.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportHandleImpl.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -1,133 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.shrinkwrap.impl.base.exporter;
-
-import java.io.InputStream;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
-import org.jboss.shrinkwrap.api.exporter.ZipExportTask;
-
-/**
- * Implementation of a {@link ZipExportTask}
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- */
-class ZipExportHandleImpl implements ZipExportTask
-{
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Contents of the export process
- */
- private final IsReadReportingInputStream content;
-
- /**
- * Underlying job carrying out the encoding process; we never expose
- * this because if the user blocks on {@link Future#get()} than this could
- * deadlock the process (the writer Thread would be waiting for the reader Thread
- * to pull off the buffer). So just provide a mechanism for the caller to see
- * if we're done, and if there was an exception raised via {@link ZipExportTask#isDone()}
- */
- private final Future<Void> job;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new handle with the specified content and pointer to the encoding
- * job. Both arguments must be specified.
- */
- ZipExportHandleImpl(final IsReadReportingInputStream content, final Future<Void> job)
- {
- // Precondition checks
- assert content != null : "Contents must be specified";
- assert job != null : "job must be specified";
-
- // Set
- this.content = content;
- this.job = job;
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.shrinkwrap.api.exporter.ZipExportTask#getContent()
- */
- @Override
- public InputStream getContent()
- {
- return content;
- }
-
- /**
- * @see org.jboss.shrinkwrap.api.exporter.ZipExportTask#checkComplete()
- */
- @Override
- public void checkComplete() throws ArchiveExportException, IllegalStateException
- {
- // Ensure we can be called; the Stream must have been fully-read
- if (!this.content.isRead())
- {
- throw new IllegalStateException(
- "Cannot invoke until the stream has been fully-read; otherwise we might lead to deadlock");
- }
-
- // See if we're done
- final boolean done = job.isDone();
-
- // If done (either completed or exception)
- if (done)
- {
- try
- {
- // Block until the streams have been closed in the underlying job
- job.get();
- }
- catch (final InterruptedException e)
- {
- Thread.interrupted();
- }
- // Some error
- catch (final ExecutionException ee)
- {
- // Unwrap and rethrow
- final Throwable cause = ee.getCause();
- if (cause == null)
- {
- throw new IllegalStateException("Cause of execution failure not specified: ", ee);
- }
- // Wrap as our exception type and rethrow
- throw new ArchiveExportException(cause);
- }
- }
-
- // Return
- return;
- }
-}
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:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterImpl.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -27,7 +27,6 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
import org.jboss.shrinkwrap.api.exporter.FileExistsException;
-import org.jboss.shrinkwrap.api.exporter.ZipExportTask;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.impl.base.AssignableBase;
import org.jboss.shrinkwrap.impl.base.Validate;
@@ -90,18 +89,18 @@
* @see org.jboss.shrinkwrap.api.exporter.ZipExporter#exportZip()
*/
@Override
- public ZipExportTask exportZip()
+ public InputStream exportZip()
{
// Create export delegate
- AbstractExporterDelegate<ZipExportTask> exportDelegate = new JdkZipExporterDelegate(archive);
+ AbstractExporterDelegate<InputStream> exportDelegate = new JdkZipExporterDelegate(archive);
// Execute export
exportDelegate.export();
// Get results
- ZipExportTask handle = exportDelegate.getResult();
+ InputStream stream = exportDelegate.getResult();
// Return
- return handle;
+ return stream;
}
/**
@@ -116,9 +115,8 @@
throw new IllegalArgumentException("Target must be specified");
}
- // Get Streams
- final ZipExportTask handle = this.exportZip();
- final InputStream in = handle.getContent();
+ // Get Stream
+ final InputStream in = this.exportZip();
// Write out
try
@@ -129,9 +127,6 @@
{
throw new ArchiveExportException("Error encountered in exporting archive to " + target, e);
}
-
- // Ensure done and no exceptions (this also will throw ArchiveExportException)
- handle.checkComplete();
}
/**
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:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -34,7 +34,6 @@
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
import org.jboss.shrinkwrap.api.exporter.FileExistsException;
-import org.jboss.shrinkwrap.api.exporter.ZipExportTask;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
@@ -83,15 +82,11 @@
Archive<?> archive = createArchiveWithAssets();
// Export as Zip InputStream
- final ZipExportTask task = archive.as(ZipExporter.class).exportZip();
- final InputStream zipStream = task.getContent();
+ final InputStream zipStream = archive.as(ZipExporter.class).exportZip();
// Write zip content to temporary file
ZipFile expectedZip = getExportedZipFile(NAME_ARCHIVE, zipStream, tempDirectory);
- // Ensure all's OK
- task.checkComplete();
-
// Validate
ensureZipFileInExpectedForm(expectedZip);
}
@@ -112,25 +107,6 @@
}
/**
- * Test to make sue an archive can be exported to Zip and all contents are correctly located in the Zip.
- * @throws Exception
- */
- @Test(expected = IllegalStateException.class)
- public void checkCompleteBeforeReadingContents() throws Exception
- {
- log.info("checkCompleteBeforeReadingContents");
-
- // Get an archive instance
- Archive<?> archive = createArchiveWithAssets();
-
- // Export as Zip InputStream
- final ZipExportTask handle = archive.as(ZipExporter.class).exportZip();
- // We cannot check complete until we fully read the instream from the handle
- handle.checkComplete();
-
- }
-
- /**
* Ensures that we can export archives of large sizes without
* leading to {@link OutOfMemoryError}
*/
@@ -142,7 +118,7 @@
log.info("This test may take awhile as it's intended to fill memory");
// Get an archive instance
- JavaArchive archive = Archives.create("hugeArchive.jar", JavaArchive.class);
+ final JavaArchive archive = Archives.create("hugeArchive.jar", JavaArchive.class);
// Approximate the free memory to start
final Runtime runtime = Runtime.getRuntime();
@@ -152,7 +128,7 @@
// Loop through and add a MB Asset
final String pathPrefix = "path";
- // Fill up the archive until we'e got only 30% of memory left
+ // Fill up the archive until we've got only 30% of memory left
while (currentFreeMemBytes > (startFreeMemBytes * .3))
{
archive.add(MegaByteAsset.newInstance(), pathPrefix + counter++);
@@ -270,7 +246,7 @@
Archive<?> archive = createArchiveWithNestedArchives();
// Export as Zip InputStream
- InputStream zipStream = archive.as(ZipExporter.class).exportZip().getContent();
+ InputStream zipStream = archive.as(ZipExporter.class).exportZip();
// Write out and retrieve Zip
ZipFile expectedZip = getExportedZipFile(NAME_ARCHIVE, zipStream, tempDirectory);
@@ -320,7 +296,7 @@
@Test(expected = ArchiveExportException.class)
public void testExportThrowsArchiveExceptionOnAssetWriteFailure() throws IOException
{
- log.info("testExportThrowsArchiveExcepitonOnAssetWriteFailure");
+ log.info("testExportThrowsArchiveExceptionOnAssetWriteFailure");
Archive<?> archive = createArchiveWithAssets();
archive.add(new Asset()
@@ -334,21 +310,17 @@
}, PATH_ONE);
// Export
- final ZipExportTask handle = archive.as(ZipExporter.class).exportZip();
+ final InputStream in = archive.as(ZipExporter.class).exportZip();
// Read in the full content (to in turn empty the underlying buffer and ensure we complete)
- final InputStream in = handle.getContent();
final OutputStream sink = new OutputStream()
{
-
@Override
public void write(int b) throws IOException
{
}
};
IOUtil.copyWithClose(in, sink);
- // Get access to the underlying exception
- handle.checkComplete();
}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2010-01-21 05:18:34 UTC (rev 3944)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2010-01-22 01:07:24 UTC (rev 3945)
@@ -114,7 +114,7 @@
File tempFile = new File("target/test.zip");
tempFile.deleteOnExit();
- InputStream zipStream = archive.as(ZipExporter.class).exportZip().getContent();
+ InputStream zipStream = archive.as(ZipExporter.class).exportZip();
IOUtil.copyWithClose(zipStream, new FileOutputStream(tempFile));
assertContent(archive, tempFile.toURI());
More information about the jboss-svn-commits
mailing list