import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import org.simantics.graph.representation.Extensions;
import org.simantics.graph.representation.External;
import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.InputChannel;
import org.simantics.graph.representation.Internal;
import org.simantics.graph.representation.Root;
import org.simantics.graph.representation.Value;
final public class StreamingTransferableGraphFileReader extends ByteFileReader {
-
- final static class InputChannel implements ReadableByteChannel {
-
- final private InputStream stream;
-
- public InputChannel(InputStream stream) {
- this.stream = stream;
- }
-
- @Override
- public boolean isOpen() {
- return true;
- }
-
- @Override
- public void close() throws IOException {
- }
-
- @Override
- public int read(ByteBuffer dst) throws IOException {
- int pos = dst.position();
- int limit = dst.limit();
- int i=stream.read(dst.array(), pos, limit-pos);
- return i;
- }
-
- }
private static boolean init = true;
--- /dev/null
+package org.simantics.graph.representation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+
+public class InputChannel implements ReadableByteChannel {
+
+ private final InputStream stream;
+
+ public InputChannel(InputStream stream) {
+ this.stream = stream;
+ }
+
+ @Override
+ public boolean isOpen() {
+ return true;
+ }
+
+ @Override
+ public void close() throws IOException {
+ // NOTE: it is an intentional choice not to close the underlying stream here
+ // InputStreams given directly to TransferableGraphFileReader are expected to
+ // be closed outside of this implementation.
+ }
+
+ @Override
+ public int read(ByteBuffer dst) throws IOException {
+ int nRead;
+ int size = 0;
+ int position = dst.position();
+ int limit = dst.limit();
+ // The users of this channel expect that the data is fully read at this point
+ while ((nRead = stream.read(dst.array(), position, limit - position)) != -1 && limit - position > 0) {
+ size += nRead;
+ position += nRead;
+ }
+ return size;
+ }
+
+}
\ No newline at end of file
}
};
-
-
- final static class InputChannel implements ReadableByteChannel {
-
- final private InputStream stream;
-
- public InputChannel(InputStream stream) {
- this.stream = stream;
- }
-
- @Override
- public boolean isOpen() {
- return true;
- }
-
- @Override
- public void close() throws IOException {
- // NOTE: it is an intentional choice not to close the underlying stream here
- // InputStreams given directly to TransferableGraphFileReader are expected to
- // be closed outside of this implementation.
- }
-
- @Override
- public int read(ByteBuffer dst) throws IOException {
- int nRead;
- int size = 0;
- int position = dst.position();
- int limit = dst.limit();
- // The users of this channel expect that the data is fully read at this point
- while ((nRead = stream.read(dst.array(), position, limit - position)) != -1 && limit - position > 0) {
- size += nRead;
- position += nRead;
- }
- return size;
- }
- }
-
private static boolean init = true;
-
+
final private static int SIZE = 1<<18;
final private static int HEADER = headerSize();
final private int header;