CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jboss-shrinkwrap--shrinkwrap-impl-base

Common base implementations for the ShrinkWrap project enabling declarative assembly of Java archives (JAR, WAR, EAR, RAR) in code

Pending
Overview
Eval results
Files

import-export.mddocs/

Import and Export

The import and export system provides comprehensive support for converting archives to and from various formats including ZIP, TAR (with compression options), and exploded directory structures.

Export Implementations

Abstract Base Classes

AbstractStreamExporterImpl

Base implementation for all stream-based exporters.

public abstract class AbstractStreamExporterImpl implements StreamExporter

Key Methods:

public InputStream exportAsInputStream()
public void exportTo(OutputStream outputStream)
public void exportTo(File file)

AbstractExporterDelegate<T>

Delegation pattern base for custom exporters.

public abstract class AbstractExporterDelegate<T> implements Exporter<T>

ZIP Format Exporters

ZipExporterImpl

Standard ZIP format exporter with compression.

public class ZipExporterImpl extends AbstractStreamExporterImpl implements ZipExporter

Key Features:

  • DEFLATE compression algorithm
  • Preserves directory structure
  • Handles file permissions and timestamps
  • Supports ZIP64 format for large archives

Usage:

Archive<?> archive = // ... create archive
InputStream zipStream = archive.as(ZipExporter.class).exportAsInputStream();

// Export to file
File zipFile = new File("archive.zip");
archive.as(ZipExporter.class).exportTo(zipFile);

ZipStoredExporterImpl

Uncompressed ZIP format exporter for faster processing.

public class ZipStoredExporterImpl extends AbstractStreamExporterImpl implements ZipExporter

Key Features:

  • No compression (STORED method)
  • Faster processing for large files
  • Same structure as compressed ZIP
  • Larger file sizes

Usage:

// Export without compression for speed
archive.as(ZipStoredExporter.class).exportTo(outputStream);

TAR Format Exporters

TarExporterImpl

Standard TAR format exporter.

public class TarExporterImpl extends AbstractStreamExporterImpl implements TarExporter

Key Features:

  • POSIX TAR format
  • Preserves Unix file permissions
  • Handles long filenames
  • Supports symbolic links

TarGzExporterImpl

GZIP-compressed TAR format exporter.

public class TarGzExporterImpl extends AbstractStreamExporterImpl implements TarGzExporter

Key Features:

  • GZIP compression
  • Standard .tar.gz format
  • Good compression ratio
  • Cross-platform compatibility

TarBz2ExporterImpl

BZIP2-compressed TAR format exporter.

public class TarBz2ExporterImpl extends AbstractStreamExporterImpl implements TarBz2Exporter

Key Features:

  • BZIP2 compression
  • Better compression ratio than GZIP
  • Slower compression speed
  • .tar.bz2 format

Usage Examples:

// Standard TAR
archive.as(TarExporter.class).exportTo("archive.tar");

// GZIP compressed
archive.as(TarGzExporter.class).exportTo("archive.tar.gz");

// BZIP2 compressed  
archive.as(TarBz2Exporter.class).exportTo("archive.tar.bz2");

Directory Export

ExplodedExporterImpl

Exports archives to exploded directory structure.

public class ExplodedExporterImpl implements ExplodedExporter

Key Methods:

public File exportExploded(File directory)
public void exportExploded(File directory, Filter<ArchivePath> filter)

Usage:

// Export to directory
File explodedDir = new File("exploded-archive");
archive.as(ExplodedExporter.class).exportExploded(explodedDir);

// Export with filtering
archive.as(ExplodedExporter.class)
       .exportExploded(explodedDir, Filters.exclude(".*\\.tmp"));

Import Implementations

ZIP Format Importers

ZipImporterImpl

Imports archives from ZIP format streams and files.

public class ZipImporterImpl implements ZipImporter

Key Methods:

public Archive<?> importFrom(File file)
public Archive<?> importFrom(InputStream inputStream)
public Archive<?> importFrom(InputStream inputStream, String archiveName)

Usage:

// Import from file
Archive<?> archive = ShrinkWrap.create(ZipImporter.class)
    .importFrom(new File("source.zip"))
    .as(GenericArchive.class);

// Import from stream
InputStream zipStream = // ... get stream
Archive<?> archive = ShrinkWrap.create(ZipImporter.class)
    .importFrom(zipStream, "imported.zip")
    .as(JavaArchive.class);

TAR Format Importers

TarImporterImpl

Standard TAR format importer.

public class TarImporterImpl implements TarImporter

TarGzImporterImpl

GZIP-compressed TAR format importer.

public class TarGzImporterImpl implements TarGzImporter

TarBz2ImporterImpl

BZIP2-compressed TAR format importer.

public class TarBz2ImporterImpl implements TarBz2Importer

Usage Examples:

// Standard TAR
Archive<?> archive = ShrinkWrap.create(TarImporter.class)
    .importFrom(new File("archive.tar"))
    .as(GenericArchive.class);

// GZIP compressed
Archive<?> archive = ShrinkWrap.create(TarGzImporter.class)
    .importFrom(new File("archive.tar.gz"))
    .as(JavaArchive.class);

// BZIP2 compressed
Archive<?> archive = ShrinkWrap.create(TarBz2Importer.class)
    .importFrom(new File("archive.tar.bz2"))
    .as(WebArchive.class);

Directory Import

ExplodedImporterImpl

Imports archives from exploded directory structures.

public class ExplodedImporterImpl implements ExplodedImporter

Key Methods:

public Archive<?> importDirectory(File directory)
public Archive<?> importDirectory(File directory, Filter<ArchivePath> filter)

Usage:

// Import entire directory
Archive<?> archive = ShrinkWrap.create(ExplodedImporter.class)
    .importDirectory(new File("exploded-webapp"))
    .as(WebArchive.class);

// Import with filtering
Archive<?> archive = ShrinkWrap.create(ExplodedImporter.class)
    .importDirectory(sourceDir, Filters.exclude(".*\\.bak"))
    .as(JavaArchive.class);

Advanced Import/Export Features

Streaming Operations

All importers and exporters support streaming for memory efficiency:

// Stream-based export
try (OutputStream out = new FileOutputStream("archive.zip")) {
    archive.as(ZipExporter.class).exportTo(out);
}

// Stream-based import
try (InputStream in = new FileInputStream("source.zip")) {
    Archive<?> archive = ShrinkWrap.create(ZipImporter.class)
        .importFrom(in, "imported")
        .as(GenericArchive.class);
}

Filtering Support

Import and export operations support content filtering:

// Export with filtering
Filter<ArchivePath> filter = Filters.exclude(".*\\.tmp", ".*\\.log");
archive.as(ExplodedExporter.class).exportExploded(targetDir, filter);

// Import with filtering  
Archive<?> filtered = ShrinkWrap.create(ExplodedImporter.class)
    .importDirectory(sourceDir, Filters.include(".*\\.class", ".*\\.xml"))
    .as(JavaArchive.class);

Format Detection

Automatic format detection based on file extensions and content:

// Automatic format detection
File unknownFile = new File("archive.unknown");
Archive<?> archive = ArchiveFactory.importFrom(unknownFile);

Compression Options

TAR exporters support compression level configuration:

// Configure compression level
TarGzExporter exporter = archive.as(TarGzExporter.class);
exporter.setCompressionLevel(9); // Maximum compression
exporter.exportTo("highly-compressed.tar.gz");

Metadata Preservation

Import/export operations preserve important metadata:

  • File timestamps
  • File permissions (on Unix systems)
  • Directory structure
  • Archive entry comments
  • Extended attributes (where supported)

Error handling

Common error scenarios and handling:

try {
    archive.as(ZipExporter.class).exportTo(file);
} catch (ArchiveExportException e) {
    // Handle export errors
    logger.error("Export failed: " + e.getMessage(), e);
} catch (IOException e) {
    // Handle I/O errors
    logger.error("I/O error during export: " + e.getMessage(), e);
}

Performance Considerations

  • Memory Usage: Streaming operations minimize memory footprint
  • Compression Speed: Choose appropriate compression algorithms based on needs
  • I/O Optimization: Buffered streams used internally for optimal performance
  • Parallel Processing: Large archives can be processed with parallel streams where appropriate

Install with Tessl CLI

npx tessl i tessl/maven-org-jboss-shrinkwrap--shrinkwrap-impl-base

docs

archive-bases.md

assets.md

containers.md

import-export.md

index.md

specifications.md

utilities.md

tile.json