public interface Transformation
OutputStreams and
InputStreams which are provided by sinks
and sources.
For example, in an encryption transformation, the method apply(net.java.truelicense.core.io.Sink)
could decorate the output streams provided by the given sink with a new
CipherOutputStream in order to encrypt the data before
writing it to the underlying output stream.
Likewise, the method unapply(net.java.truelicense.core.io.Source) could decorate the input streams
provided by the given source with a new
CipherInputStream in order to decrypt the data after
reading it from the underlying input stream.
As another example, in a compression transformation, the apply method could
decorate the output streams provided by the given sink with a new
DeflaterOutputStream in order to compress the data
before writing it to the underlying output stream.
Likewise, the unapply method could decorate the input streams provided by the
given source 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 create rich decorators for the underlying sinks and sources 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 = ...;
Sink compressAndEncryptData = compression.apply(encryption.apply(store));
Source decryptAndDecompressData = compression.unapply(encryption.unapply(store));
try (PrintWriter writer = new PrintWriter(compressAndEncryptData.output())) {
writer.println("Hello world!");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(decryptAndDecompressData.input()))) {
assertTrue("Hello world!".equals(reader.readLine()));
}
| Modifier and Type | Method and Description |
|---|---|
Sink |
apply(Sink sink)
Returns a sink which decorates the output streams provided by the given
sink.
|
Source |
unapply(Source source)
Returns a source which decorates the input streams provided by the given
source.
|
Copyright © 2005–2017 Schlichtherle IT Services. All rights reserved.