/** * Creates a compressor from the given compression type. * * @param compression the name of the compression algorithm e.g. "gz" or "bzip2". * @return a new {@link Compressor} instance for the given compression algorithm * @throws IllegalArgumentException if the compression type is unknown */ public static Compressor createCompressor(String compression) throws IllegalArgumentException { if (!CompressionType.isValidCompressionType(compression)) { throw new IllegalArgumentException("Unkonwn compression type " + compression); } return createCompressor(CompressionType.fromString(compression)); }
/** * Checks if the given compression type name is valid and known format. * * @param compression the compression algorithm name * @return true true if the given compression type is known to the factory, false otherwise */ public static boolean isValidCompressionType(String compression) { for (CompressionType type : values()) { if (compression.equalsIgnoreCase(type.getName())) { return true; } } return false; }
/** * @see {@link CompressorStreamFactory#createCompressorInputStream(String, java.io.InputStream)} */ static CompressorInputStream createCompressorInputStream(CompressionType compressionType, InputStream in) throws CompressorException { return compressorStreamFactory.createCompressorInputStream(compressionType.getName(), in); }
@Override public String getFilenameExtension() { return getCompressionType().getDefaultFileExtension(); }
/** * @see {@link CompressorStreamFactory#createCompressorInputStream(String, java.io.InputStream)} */ static CompressorInputStream createCompressorInputStream(CompressionType compressionType, InputStream in) throws CompressorException { return compressorStreamFactory.createCompressorInputStream(compressionType.getName(), in); }
@Override public String getFilenameExtension() { return getCompressionType().getDefaultFileExtension(); }
/** * Creates a compressor from the given compression type. * * @param compression the name of the compression algorithm e.g. "gz" or "bzip2". * @return a new {@link Compressor} instance for the given compression algorithm * @throws IllegalArgumentException if the compression type is unknown */ public static Compressor createCompressor(String compression) throws IllegalArgumentException { if (!CompressionType.isValidCompressionType(compression)) { throw new IllegalArgumentException("Unkonwn compression type " + compression); } return createCompressor(CompressionType.fromString(compression)); }
/** * Checks if the given compression type name is valid and known format. * * @param compression the compression algorithm name * @return true true if the given compression type is known to the factory, false otherwise */ public static boolean isValidCompressionType(String compression) { for (CompressionType type : values()) { if (compression.equalsIgnoreCase(type.getName())) { return true; } } return false; }
static CompressorOutputStream createCompressorOutputStream(CompressionType compressionType, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressionType.getName(), new FileOutputStream(destination)); }
/** * Creates an Archiver for the given archive format that uses compression. * * @param archiveFormat the archive format e.g. "tar" or "zip" * @param compression the compression algorithm name e.g. "gz" * @return a new Archiver instance that also handles compression * @throws IllegalArgumentException if the archive format or the compression type is unknown */ public static Archiver createArchiver(String archiveFormat, String compression) throws IllegalArgumentException { if (!ArchiveFormat.isValidArchiveFormat(archiveFormat)) { throw new IllegalArgumentException("Unknown archive format " + archiveFormat); } if (!CompressionType.isValidCompressionType(compression)) { throw new IllegalArgumentException("Unknown compression type " + compression); } return createArchiver(ArchiveFormat.fromString(archiveFormat), CompressionType.fromString(compression)); }
/** * Attempts to return the {@link CompressionType} instance from a possible given string representation. Ignores * case. * * @param compression string representation of the compression type. E.g. "GZIP". * @return the compression type enum * @throws IllegalArgumentException if the given compression type is unknown. */ public static CompressionType fromString(String compression) { for (CompressionType type : values()) { if (compression.equalsIgnoreCase(type.getName())) { return type; } } throw new IllegalArgumentException("Unknown compression type " + compression); } }
static CompressorOutputStream createCompressorOutputStream(CompressionType compressionType, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressionType.getName(), new FileOutputStream(destination)); }
/** * Creates an Archiver for the given archive format that uses compression. * * @param archiveFormat the archive format e.g. "tar" or "zip" * @param compression the compression algorithm name e.g. "gz" * @return a new Archiver instance that also handles compression * @throws IllegalArgumentException if the archive format or the compression type is unknown */ public static Archiver createArchiver(String archiveFormat, String compression) throws IllegalArgumentException { if (!ArchiveFormat.isValidArchiveFormat(archiveFormat)) { throw new IllegalArgumentException("Unknown archive format " + archiveFormat); } if (!CompressionType.isValidCompressionType(compression)) { throw new IllegalArgumentException("Unknown compression type " + compression); } return createArchiver(ArchiveFormat.fromString(archiveFormat), CompressionType.fromString(compression)); }
/** * Attempts to return the {@link CompressionType} instance from a possible given string representation. Ignores * case. * * @param compression string representation of the compression type. E.g. "GZIP". * @return the compression type enum * @throws IllegalArgumentException if the given compression type is unknown. */ public static CompressionType fromString(String compression) { for (CompressionType type : values()) { if (compression.equalsIgnoreCase(type.getName())) { return type; } } throw new IllegalArgumentException("Unknown compression type " + compression); } }