public interface Transformation
With an encryption transformation for example, the apply(global.namespace.fun.io.api.Socket<java.io.OutputStream>) method would decorate the loaned output streams
with a new CipherOutputStream in order to encrypt the data before writing it to the underlying
output stream.
Likewise, the unapply(global.namespace.fun.io.api.Socket<java.io.InputStream>) method would decorate the loaned input streams with a new
CipherInputStream in order to decrypt the data after reading it from the underlying input
stream.
As another example, with a compression transformation the apply method would decorate the loaned output
streams with a new DeflaterOutputStream in order to compress the data before writing it to the
underlying output stream.
Likewise, the unapply method would decorate the loaned input streams with a new
InflaterInputStream in order to decompress the data after reading it from the underlying input
stream.
The benefit of this interface is that you can easily chain the apply and unapply methods in order to
from rich decorators without needing to know anything about the implementation of the transformations.
For example, depending on the previous examples, the following test code would assert the round-trip processing of
the string "Hello world!" using the composition of some compression and encryption transformations on
some store:
Transformation compression = ...;
Transformation encryption = ...;
Store store = ...;
Socket<OutputStream> compressAndEncryptData = compression.apply(encryption.apply(store.output()));
Socket<InputStream> decryptAndDecompressData = compression.unapply(encryption.unapply(store.input()));
compressAndEncryptData.map(PrintWriter::new).accept(writer -> writer.println("Hello world!"));
decryptAndDecompressData.map(InputStreamReader::new).map(BufferedReader::new).accept(reader ->
assertTrue("Hello world!".equals(reader.readLine())));
| Modifier and Type | Field | Description |
|---|---|---|
static Transformation |
IDENTITY |
The identity transformation.
|
| Modifier and Type | Method | Description |
|---|---|---|
default Transformation |
andThen(Transformation after) |
Returns a transformation which applies the given transformation after this transformation.
|
Socket<java.io.OutputStream> |
apply(Socket<java.io.OutputStream> output) |
Returns an output stream socket which decorates the given output stream socket.
|
default Transformation |
compose(Transformation before) |
Returns a transformation which applies the given transformation before this transformation.
|
Transformation |
inverse() |
Returns the inverse of this transformation (optional operation).
|
Socket<java.io.InputStream> |
unapply(Socket<java.io.InputStream> input) |
Returns an input stream socket which decorates the given input stream socket.
|
static final Transformation IDENTITY
Socket<java.io.OutputStream> apply(Socket<java.io.OutputStream> output)
Socket<java.io.InputStream> unapply(Socket<java.io.InputStream> input)
Transformation inverse()
UnsupportedOperationException if inverting this transformation
is not supported.
However, it's strongly encouraged to provide a proper implementation of this operation because it's trivially
possible to invert any transformation by buffering its entire content.java.lang.UnsupportedOperationException - if inverting this transformation is not supported.default Transformation compose(Transformation before)
default Transformation andThen(Transformation after)