]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Remove duplicate InputChannel inner classes 82/1982/4
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 3 Aug 2018 07:48:11 +0000 (10:48 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 3 Aug 2018 11:52:02 +0000 (11:52 +0000)
gitlab #73

Change-Id: I5ef3948f8b3437345536bd7e121cb3443d8fe26f

bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphFileReader.java
bundles/org.simantics.graph/src/org/simantics/graph/representation/InputChannel.java [new file with mode: 0644]
bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphFileReader.java

index 68a94e304581f71d55d1c57d9e3220a5da6bac3c..8c82c23bc69bb8a8f37ff6855e577ea050a2cb16 100644 (file)
@@ -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;
        
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/InputChannel.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/InputChannel.java
new file mode 100644 (file)
index 0000000..1eb00c2
--- /dev/null
@@ -0,0 +1,42 @@
+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
index 56a112e4d02e7a7e768375618bf687bab437b3ef..6fc7ac5516f5cc9efb7da5f8cd3a4f588565fb54 100644 (file)
@@ -53,46 +53,9 @@ final public class TransferableGraphFileReader 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 {
-                       // 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;