bt.net.DelegatingMessageReaderWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bt-core Show documentation
Show all versions of bt-core Show documentation
BitTorrent Client Library (Core)
package bt.net;
import bt.protocol.Message;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
class DelegatingMessageReaderWriter implements MessageReaderWriter {
private final Supplier reader;
private final Consumer writer;
public DelegatingMessageReaderWriter(Supplier reader, Consumer writer) {
this.reader = reader;
this.writer = writer;
}
@Override
public Optional readMessage() {
return Optional.ofNullable(reader.get());
}
@Override
public void writeMessage(Message message) {
writer.accept(message);
}
}