X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph.db%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fdb%2FStreamingTransferableGraphFileReader.java;h=8c82c23bc69bb8a8f37ff6855e577ea050a2cb16;hb=32a17a670cf4f9d459917495be5f4a504afac205;hp=86c3d2fcbb18c51bae4e8bfefbdcd7928de57611;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphFileReader.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphFileReader.java index 86c3d2fcb..8c82c23bc 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphFileReader.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphFileReader.java @@ -5,7 +5,6 @@ import java.io.DataInputStream; 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; @@ -25,39 +24,13 @@ import org.simantics.graph.representation.ByteFileReader; 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; @@ -135,9 +108,9 @@ final public class StreamingTransferableGraphFileReader extends ByteFileReader { Extensions extensions; int resourceCount; - private int identities; - private int stmLength; - private int valueLength; + private int identities = -1; + private int stmLength = -1; + private int valueLength = -1; public FileTransferableGraphSource() throws Exception { init(); @@ -176,33 +149,41 @@ final public class StreamingTransferableGraphFileReader extends ByteFileReader { @Override public int getIdentityCount() throws Exception { - identities = safeInt(); + if(identities == -1) { + identities = safeInt(); + } return identities; } @Override public int getStatementCount() throws Exception { - stmLength = safeInt(); + if(stmLength == -1) { + stmLength = safeInt(); + } return stmLength; } @Override public int getValueCount() throws Exception { - valueLength = safeInt(); + if(valueLength == -1) { + valueLength = safeInt(); + } return valueLength; } @Override public void forStatements(ReadGraph graph, TransferableGraphSourceProcedure procedure) throws Exception { - + int[] value = new int[4]; + int stmLength = getStatementCount(); + for(int stmIndex=0;stmIndex> 2; int allowed = Math.min(stmLength-stmIndex, avail); @@ -213,94 +194,100 @@ final public class StreamingTransferableGraphFileReader extends ByteFileReader { // statements[stmIndex++] = ((bytes[index++]&0xff)<<24) | ((bytes[index++]&0xff)<<16) | ((bytes[index++]&0xff)<<8) | ((bytes[index++]&0xff)); } byteIndex += allowed<<2; - + } - + } @Override public void forIdentities(ReadGraph graph, TransferableGraphSourceProcedure procedure) throws Exception { - + + int identities = getIdentityCount(); + for(int i=0;i procedure) throws Exception { - + + int valueLength = getValueCount(); + Serializer variantSerializer = Bindings.getSerializerUnchecked(Bindings.VARIANT); - + List idcontext = new ArrayList<>(); - + for(int i=0;i idContext = new ArrayList<>(); - + for(int i=0;i