Skip to content

Commit

Permalink
Refactors Store, Codec and Filter so that all transformations are
Browse files Browse the repository at this point in the history
encapsulated in the `Filter` interface and its implementations.
Removes `Buffer`.
  • Loading branch information
christian-schlichtherle committed Oct 14, 2018
1 parent 40bfe5d commit 9d17491
Show file tree
Hide file tree
Showing 31 changed files with 514 additions and 434 deletions.
133 changes: 0 additions & 133 deletions api/src/main/java/global/namespace/fun/io/api/Buffer.java

This file was deleted.

52 changes: 25 additions & 27 deletions api/src/main/java/global/namespace/fun/io/api/Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,29 @@
*/
public interface Codec {

/** Returns an encoder which writes object graphs to the given output stream socket. */
/**
* Returns an encoder which writes object graphs to the given output stream socket.
*/
Encoder encoder(Socket<OutputStream> output);

/** Returns an encoder which writes object graphs to the given sink. */
default Encoder encoder(Sink sink) { return encoder(sink.output()); }
/**
* Returns an encoder which writes object graphs to the given sink.
*/
default Encoder encoder(Sink sink) {
return encoder(sink.output());
}

/** Returns a decoder which reads object graphs from the given input stream socket. */
/**
* Returns a decoder which reads object graphs from the given input stream socket.
*/
Decoder decoder(Socket<InputStream> input);

/** Returns a decoder which reads object graphs from the given source. */
default Decoder decoder(Source source) { return decoder(source.input()); }
/**
* Returns a decoder which reads object graphs from the given source.
*/
default Decoder decoder(Source source) {
return decoder(source.input());
}

/**
* Returns a deep clone of the given object by encoding it to a temporary store obtained from the given supplier and
Expand All @@ -51,32 +63,18 @@ default <T> T clone(final T t, final XSupplier<Store> storeSupplier) throws Exce
}

/**
* Returns a deep clone of the given object by encoding it to a loaned buffer and decoding it again.
*
* @deprecated The {@link Buffer} interface is redundant since the introduction of {@link Store#deleteIfExists()} in
* Fun I/O 1.4.0.
* Connects this codec to the given store.
*/
@Deprecated
default <T> T clone(T t, Socket<Buffer> bufferSocket) throws Exception {
return bufferSocket.apply(buffer -> connect(buffer).clone(t));
default ConnectedCodec connect(Store store) {
return Internal.connect(this, requireNonNull(store));
}

/** Connects this codec to the given store. */
default ConnectedCodec connect(Store store) { return Internal.connect(this, requireNonNull(store)); }

/**
* Returns a codec which applies the given filter to the I/O streams loaned to this codec.
* Returns a codec which applies the given filter to this codec.
*
* @param t the filter to apply to the I/O streams loaned to this codec.
* @param f the filter to apply to this codec.
*/
default Codec map(Filter t) {
return new Codec() {

@Override
public Encoder encoder(Socket<OutputStream> output) { return Codec.this.encoder(t.apply(output)); }

@Override
public Decoder decoder(Socket<InputStream> input) { return Codec.this.decoder(t.unapply(input)); }
};
default Codec map(Filter f) {
return f.codec(this);
}
}
Loading

0 comments on commit 9d17491

Please sign in to comment.