
org.jboss.shrinkwrap.api.asset.ArchiveAsset Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shrinkwrap-api Show documentation
Show all versions of shrinkwrap-api Show documentation
Client View of the ShrinkWrap Project
The newest version!
/*
* 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.api.asset;
import java.io.InputStream;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.exporter.StreamExporter;
/**
* An {@link Asset} representing an {@link Archive}; a specified {@link StreamExporter} type will be used to fulfill the
* {@link Asset#openStream()} contract.
*
* @author John Bailey
* @author ALR
* @version $Revision: $
*/
public class ArchiveAsset implements Asset {
// -------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||
/**
* The archive this asset represents
*/
private final Archive> archive;
/**
* Exporter used to represent this archive as a {@link InputStream}
*/
private final Class extends StreamExporter> exporter;
// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||
/**
* Creates a new instance wrapping the specified {@link Archive}, which will use the specified
* {@link StreamExporter} to represent the archive as an {@link InputStream} in {@link Asset#openStream()}.
*
* @param archive
* The {@link Archive} to wrap. Must not be {@code null}.
* @param exporter
* The {@link StreamExporter} class used to export the archive as an {@link InputStream}.
* Must not be {@code null}.
* @throws IllegalArgumentException
* If either argument is not specified
*/
public ArchiveAsset(final Archive> archive, final Class extends StreamExporter> exporter) {
if (archive == null) {
throw new IllegalArgumentException("archive must be specified");
}
if (exporter == null) {
throw new IllegalArgumentException("exporter must be specified");
}
this.archive = archive;
this.exporter = exporter;
}
// -------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
// -------------------------------------------------------------------------------------||
/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.asset.Asset#openStream()
*/
@Override
public InputStream openStream() {
// Export via the specified exporter
return this.getArchive().as(this.exporter).exportAsInputStream();
}
/**
* Returns the archive this asset represents
*/
public Archive> getArchive() {
return archive;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy