Package org.syncany.chunk
Class Transformer
- java.lang.Object
-
- org.syncany.chunk.Transformer
-
- Direct Known Subclasses:
CipherTransformer
,GzipTransformer
,NoTransformer
public abstract class Transformer extends java.lang.Object
A transformer combines one or many stream-transformingOutputStream
s andInputStream
s. Implementations might provide functionality to encrypt or compress output streams, and to decrypt or uncompress a corresponding input stream.Transformers can be chained in order to allow multiple consecutive output-/input stream transformers to be applied to a stream.
A transformer can be instantiated using its implementation-specific constructor, or by calling its default constructor and initializing it using the
init()
method. Depending on the implementation, varying settings must be passed.
-
-
Field Summary
Fields Modifier and Type Field Description protected Transformer
nextTransformer
-
Constructor Summary
Constructors Constructor Description Transformer()
Creates a new transformer object (no next transformer)Transformer(Transformer nextTransformer)
Create a new transformer, with a nested/chained transformer that will be be applied after this transformer.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.io.InputStream
createInputStream(java.io.InputStream in)
Creates a strea-transformingInputStream
.abstract java.io.OutputStream
createOutputStream(java.io.OutputStream out)
Create a stream-transformingOutputStream
.static Transformer
getInstance(java.lang.String type)
Instantiates a transformer by its name using the default constructor.abstract void
init(java.util.Map<java.lang.String,java.lang.String> settings)
If a transformer is instantiated via the default constructor (e.g.void
setNextTransformer(Transformer nextTransformer)
abstract java.lang.String
toString()
An implementation of a transformer must override this method to identify the type of transformer and/or its settings.
-
-
-
Field Detail
-
nextTransformer
protected Transformer nextTransformer
-
-
Constructor Detail
-
Transformer
public Transformer()
Creates a new transformer object (no next transformer)
-
Transformer
public Transformer(Transformer nextTransformer)
Create a new transformer, with a nested/chained transformer that will be be applied after this transformer.- Parameters:
nextTransformer
- The next transformer (to be applied after this transformer)
-
-
Method Detail
-
init
public abstract void init(java.util.Map<java.lang.String,java.lang.String> settings) throws java.lang.Exception
If a transformer is instantiated via the default constructor (e.g. via a config file), it must be initialized using this method. The settings passed to the method depend on the implementation of the transformer.- Parameters:
settings
- Implementation-specific setting map- Throws:
java.lang.Exception
- If the given settings are invalid or insufficient for instantiation
-
createOutputStream
public abstract java.io.OutputStream createOutputStream(java.io.OutputStream out) throws java.io.IOException
Create a stream-transformingOutputStream
. Depending on the implementation, the bytes written to the output stream might be encrypted, compressed, etc.- Parameters:
out
- Original output stream which is transformed by this transformer- Returns:
- Returns a transformed output stream
- Throws:
java.io.IOException
- If an exception occurs when instantiating or writing to the stream
-
createInputStream
public abstract java.io.InputStream createInputStream(java.io.InputStream in) throws java.io.IOException
Creates a strea-transformingInputStream
. Depending on the implementation, the bytes read from the input stream are uncompressed, decrypted, etc.- Parameters:
in
- Original input stream which is transformed by this transformer- Returns:
- Returns a transformed input stream
- Throws:
java.io.IOException
- If an exception occurs when instantiating or reading from the stream
-
toString
public abstract java.lang.String toString()
An implementation of a transformer must override this method to identify the type of transformer and/or its settings.- Overrides:
toString
in classjava.lang.Object
-
getInstance
public static Transformer getInstance(java.lang.String type) throws java.lang.Exception
Instantiates a transformer by its name using the default constructor. After creating a new transformer, it must be initialized using theinit()
method.The given type attribute is mapped to fully qualified class name (FQCN) of the form
org.syncany.chunk.XTransformer
, whereX
is the camel-cased type attribute.- Parameters:
type
- Type/name of the transformer (corresponds to its camel case class name)- Returns:
- Returns a new transformer
- Throws:
java.lang.Exception
- If the FQCN cannot be found or the class cannot be instantiated
-
setNextTransformer
public void setNextTransformer(Transformer nextTransformer)
-
-