Package ca.cgjennings.algo.compression
Enum CompressorFactory
- java.lang.Object
-
- java.lang.Enum<CompressorFactory>
-
- ca.cgjennings.algo.compression.CompressorFactory
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<CompressorFactory>
public enum CompressorFactory extends java.lang.Enum<CompressorFactory>
Compressor factory supports programmatic selection and creation ofCompressor
instances. For example, it can return a compressor that is suited to a particular file type.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CompressorFactory
choose(boolean small, boolean fast, boolean standard)
Chooses a compressor for a specific application.static CompressorFactory
forExtension(java.lang.String name)
Returns a factory that matches a name, ornull
if no factory matches.java.lang.String[]
getAllExtensions()
Returns an array of all known extensions for this algorithm.Compressor
getCompressor()
Returns aCompressor
for this algorithm.java.lang.String
getExtension()
Returns the most common file extension for this algorithm.boolean
matchesExtension(java.lang.String name)
Returnstrue
if one of this algorithm's extensions matches the given name.static CompressorFactory
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static CompressorFactory[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
DEFLATE
public static final CompressorFactory DEFLATE
The deflate (GZIP with no header or footer) compressor factory.
-
GZIP
public static final CompressorFactory GZIP
The GZIP compressor factory.
-
BZIP2
public static final CompressorFactory BZIP2
The BZip2 compressor factory.
-
LZMA
public static final CompressorFactory LZMA
The LZMA compressor factory.
-
-
Method Detail
-
values
public static CompressorFactory[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CompressorFactory c : CompressorFactory.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CompressorFactory valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getCompressor
public Compressor getCompressor()
Returns aCompressor
for this algorithm.- Returns:
- a compressor instance
-
getExtension
public java.lang.String getExtension()
Returns the most common file extension for this algorithm.- Returns:
- the suggested file extension for compressed files
-
getAllExtensions
public java.lang.String[] getAllExtensions()
Returns an array of all known extensions for this algorithm.- Returns:
- an array of suitable file extensions
-
matchesExtension
public boolean matchesExtension(java.lang.String name)
Returnstrue
if one of this algorithm's extensions matches the given name. If name contains a dot, then only the text after the final dot is considered when matching extensions.- Parameters:
name
- a name with an extension to match against this algorithm's extensions- Returns:
true
if the name's extension is a known extension for this algorithm- Throws:
java.lang.NullPointerException
- if the name isnull
-
choose
public static CompressorFactory choose(boolean small, boolean fast, boolean standard)
Chooses a compressor for a specific application. The parameters allow you to specify which performance aspects of the resulting compressor are most important you, and returns a factory to suit your that satisfies- Parameters:
small
- iftrue
, small compressed output (high compression ratios) is importantfast
- iftrue
, fast decompression is importantstandard
- iftrue
, being able to decompress data with common command line tools is important- Returns:
- a factory that will create a compressor that satisfies as many of your needs as possible
-
forExtension
public static CompressorFactory forExtension(java.lang.String name)
Returns a factory that matches a name, ornull
if no factory matches. If name contains a dot, then only the text after the final dot is considered when matching extensions.- Parameters:
name
- the file name or extension to match- Returns:
- a compressor factory that creates compressors for the matched
file type, or
null
if no match was found - Throws:
java.lang.NullPointerException
- if the name isnull
- See Also:
matchesExtension(java.lang.String)
-
-