1 package org.simantics.graph.representation;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.nio.ByteBuffer;
6 import java.nio.channels.ReadableByteChannel;
8 public class InputChannel implements ReadableByteChannel {
10 private final InputStream stream;
12 public InputChannel(InputStream stream) {
17 public boolean isOpen() {
22 public void close() throws IOException {
23 // NOTE: it is an intentional choice not to close the underlying stream here
24 // InputStreams given directly to TransferableGraphFileReader are expected to
25 // be closed outside of this implementation.
29 public int read(ByteBuffer dst) throws IOException {
32 int position = dst.position();
33 int limit = dst.limit();
34 // The users of this channel expect that the data is fully read at this point
35 while ((nRead = stream.read(dst.array(), position, limit - position)) != -1 && limit - position > 0) {