[jboss-svn-commits] JBoss Common SVN: r3526 - in shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base: asset and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 16 19:22:39 EDT 2009
Author: johnbailey
Date: 2009-09-16 19:22:39 -0400 (Wed, 16 Sep 2009)
New Revision: 3526
Added:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveInputStreamFactory.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java
Modified:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ArchiveAsset.java
Log:
[SHRINKWRAP-10] - Updated ArchiveAsset to use an ArchiveInputStreamFactory to lazily get an InputStream for an archive.
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java 2009-09-16 02:31:52 UTC (rev 3525)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java 2009-09-16 23:22:39 UTC (rev 3526)
@@ -16,7 +16,6 @@
*/
package org.jboss.shrinkwrap.impl.base;
-import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
@@ -26,9 +25,7 @@
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.AssetNotFoundException;
import org.jboss.shrinkwrap.api.Path;
-import org.jboss.shrinkwrap.api.export.ZipExporter;
import org.jboss.shrinkwrap.impl.base.asset.ArchiveAsset;
-import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
/**
@@ -158,14 +155,8 @@
final String archiveName = archive.getName();
final Path contentPath = new BasicPath(path, archiveName);
- // Get archive input stream
- InputStream inputStream = ZipExporter.exportZip(archive);
-
- // Get the bytes for the archive
- byte[] archiveBytes = IOUtil.asByteArray(inputStream);
-
// Create ArchiveAsset
- ArchiveAsset archiveAsset = new ArchiveAsset(archive, archiveBytes);
+ ArchiveAsset archiveAsset = new ArchiveAsset(archive);
// Delegate
return add(contentPath, archiveAsset);
Added: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveInputStreamFactory.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveInputStreamFactory.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveInputStreamFactory.java 2009-09-16 23:22:39 UTC (rev 3526)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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;
+
+import java.io.InputStream;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.impl.base.export.ZipArchiveInputStreamFactory;
+
+/**
+ * ArchiveInputStreamFactory
+ *
+ * Factory used create an input stream from an Archive.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public abstract class ArchiveInputStreamFactory
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Current instance. Should be replaced with some other structure (MAP) when we support multiple concrete implementations.
+ */
+ private static ArchiveInputStreamFactory instance;
+
+ //-------------------------------------------------------------------------------------||
+ // Class Methods ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create an InputStream from an Archive instance.
+ *
+ * @throws IllegalArgumentException if the Archive is null
+ */
+ public static InputStream getInputStream(Archive<?> archive)
+ {
+ Validate.notNull(archive, "archive was not provided");
+
+ // Get the concrete factory to handle this archive
+ ArchiveInputStreamFactory factory = getInstance(archive);
+
+ // Delegate to concrete impl
+ return factory.doGetInputStream(archive);
+ }
+
+ /**
+ * Gets an instance of the {@link ArchiveInputStreamFactory}
+ *
+ * @param archive archive to determine which impl to use
+ * @return {@link ArchiveInputStreamFactory} instance
+ */
+ private synchronized static ArchiveInputStreamFactory getInstance(Archive<?> archive)
+ {
+ if (instance == null)
+ {
+ // TODO - Use the archive to determine the correct implementation to use.
+ instance = new ZipArchiveInputStreamFactory();
+ }
+ return instance;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Template method required to create an InputStream from an Archive instance.
+ *
+ * @param archive to create the InputStream from
+ * @return InputStream for the Archive
+ */
+ protected abstract InputStream doGetInputStream(Archive<?> archive);
+
+}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ArchiveAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ArchiveAsset.java 2009-09-16 02:31:52 UTC (rev 3525)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ArchiveAsset.java 2009-09-16 23:22:39 UTC (rev 3526)
@@ -16,8 +16,11 @@
*/
package org.jboss.shrinkwrap.impl.base.asset;
+import java.io.InputStream;
+
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.impl.base.ArchiveInputStreamFactory;
import org.jboss.shrinkwrap.impl.base.Validate;
/**
@@ -28,7 +31,7 @@
* @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
* @version $Revision: $
*/
-public class ArchiveAsset extends ByteArrayAsset implements Asset
+public class ArchiveAsset implements Asset
{
//-------------------------------------------------------------------------------------||
@@ -48,14 +51,28 @@
* Creates an ArchiveAsset with and archive and a byte array of archive contents
* @throws IllegalArgumentException if no archive is provided
*/
- public ArchiveAsset(Archive<?> archive, byte[] archiveContent)
+ public ArchiveAsset(Archive<?> archive)
{
- super(archiveContent);
Validate.notNull(archive, "archive must be specified");
this.archive = archive;
}
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /*
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.Asset#getStream()
+ */
+ @Override
+ public InputStream getStream()
+ {
+ // Get the input stream from the ArchiveInputStreamFactory
+ return ArchiveInputStreamFactory.getInputStream(getArchive());
+ }
+
/**
* Returns the archive this asset represents
* @return
Added: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipArchiveInputStreamFactory.java 2009-09-16 23:22:39 UTC (rev 3526)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.export;
+
+import java.io.InputStream;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.export.ZipExporter;
+import org.jboss.shrinkwrap.impl.base.ArchiveInputStreamFactory;
+
+/**
+ * ZipArchiveInputStreamFactory
+ *
+ * Factory used create an InputStream from an Archive by exporting the archive as a Zip.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class ZipArchiveInputStreamFactory extends ArchiveInputStreamFactory
+{
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - ArchiveInputStreamFactory ------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.impl.base.ArchiveInputStreamFactory#doGetInputStream(Archive)
+ */
+ @Override
+ protected InputStream doGetInputStream(Archive<?> archive)
+ {
+ // Get InputStream from the ZipExporter
+ final InputStream inputStream = ZipExporter.exportZip(archive);
+ // Return input stream
+ return inputStream;
+ }
+
+}
More information about the jboss-svn-commits
mailing list