]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryMemory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / util / binary / BinaryMemory.java
index 087a6a9da6e931f6c5627d3a317f34286db3f704..33ac55c5e91fd91c5945434fb52fbcd2bfae4063 100644 (file)
@@ -1,20 +1,20 @@
-/*******************************************************************************\r
- * Copyright (c) 2010, 2016 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2016 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
 package org.simantics.databoard.util.binary;
 
-import java.io.DataInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.nio.ByteBuffer;\r
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
 
 /**
  * Rancom access memory blob
@@ -35,20 +35,20 @@ public class BinaryMemory implements RandomAccessBinary {
                buf = ByteBuffer.allocate(16);
                increment = 16;
        }
-\r
-       /**\r
-        * New memory blob\r
-        */\r
-       public BinaryMemory(byte[] data) {\r
-               this.buf = ByteBuffer.wrap(data);\r
-       }\r
-       \r
-       /**\r
-        * New memory blob\r
-        */\r
-       public BinaryMemory(byte[] data, int offset, int length) {\r
-               this.buf = ByteBuffer.wrap(data, offset, length);\r
-       }\r
+
+       /**
+        * New memory blob
+        */
+       public BinaryMemory(byte[] data) {
+               this.buf = ByteBuffer.wrap(data);
+       }
+       
+       /**
+        * New memory blob
+        */
+       public BinaryMemory(byte[] data, int offset, int length) {
+               this.buf = ByteBuffer.wrap(data, offset, length);
+       }
        
        /**
         * New memory blob
@@ -88,18 +88,18 @@ public class BinaryMemory implements RandomAccessBinary {
        @Override
        public void close() throws IOException {
        }
-\r
-       @Override\r
-       public boolean isOpen() {\r
-               return true;\r
-       }\r
+
+       @Override
+       public boolean isOpen() {
+               return true;
+       }
        
        @Override
        public void flush() throws IOException {
-       }\r
-       \r
-       @Override\r
-       public void reset() throws IOException {\r
+       }
+       
+       @Override
+       public void reset() throws IOException {
        }
 
        @Override
@@ -109,63 +109,63 @@ public class BinaryMemory implements RandomAccessBinary {
                byte result = buf.get();
                pointer += 1;
                return result;
-       }\r
-       \r
-       int _read() {\r
-               if (pointer >= buf.limit()) return -1;\r
-               buf.position( (int) pointer );\r
-               byte result = buf.get();\r
-               pointer += 1;\r
-               return result & 0xff;\r
-       }       \r
-       \r
-    public final String readLine() throws IOException {\r
-       StringBuffer input = new StringBuffer();\r
-       int c = -1;\r
-       boolean eol = false;\r
-\r
-       while (!eol) {\r
-           switch (c = _read()) {\r
-           case -1:\r
-           case '\n':\r
-               eol = true;\r
-               break;\r
-           case '\r':\r
-               eol = true;\r
-               long cur = position();\r
-               if ((_read()) != '\n') {\r
-                   position(cur);\r
-               }\r
-               break;\r
-           default:\r
-               input.append((char)c);\r
-               break;\r
-           }\r
-       }\r
-\r
-       if ((c == -1) && (input.length() == 0)) {\r
-           return null;\r
-       }\r
-       return input.toString();\r
-    }  \r
-    \r
-    public final String readUTF() throws IOException {\r
-       return DataInputStream.readUTF(this);\r
-    }     \r
-       \r
-       @Override\r
-       public int readUnsignedByte() throws IOException {\r
-               return readByte() & 0x000000ff;\r
+       }
+       
+       int _read() {
+               if (pointer >= buf.limit()) return -1;
+               buf.position( (int) pointer );
+               byte result = buf.get();
+               pointer += 1;
+               return result & 0xff;
+       }       
+       
+    public final String readLine() throws IOException {
+       StringBuffer input = new StringBuffer();
+       int c = -1;
+       boolean eol = false;
+
+       while (!eol) {
+           switch (c = _read()) {
+           case -1:
+           case '\n':
+               eol = true;
+               break;
+           case '\r':
+               eol = true;
+               long cur = position();
+               if ((_read()) != '\n') {
+                   position(cur);
+               }
+               break;
+           default:
+               input.append((char)c);
+               break;
+           }
+       }
+
+       if ((c == -1) && (input.length() == 0)) {
+           return null;
+       }
+       return input.toString();
+    }  
+    
+    public final String readUTF() throws IOException {
+       return DataInputStream.readUTF(this);
+    }     
+       
+       @Override
+       public int readUnsignedByte() throws IOException {
+               return readByte() & 0x000000ff;
        }               
-\r
-       @Override\r
-       public boolean readBoolean() throws IOException {\r
-               assertHasReadableBytes(1);              \r
-               buf.position( (int) pointer );\r
-               byte result = buf.get();\r
-               pointer += 1;\r
-               return result!=0;\r
-       }\r
+
+       @Override
+       public boolean readBoolean() throws IOException {
+               assertHasReadableBytes(1);              
+               buf.position( (int) pointer );
+               byte result = buf.get();
+               pointer += 1;
+               return result!=0;
+       }
        
        @Override
        public void readFully(byte[] dst, int offset, int length) {
@@ -261,24 +261,24 @@ public class BinaryMemory implements RandomAccessBinary {
                short result = buf.getShort();
                pointer += 2;
                return result;
-       }\r
-       \r
-       @Override\r
-       public char readChar() {\r
-               assertHasReadableBytes(2);\r
-               buf.position( (int) pointer );\r
-               char result = buf.getChar();\r
-               pointer += 2;\r
-               return result;\r
-       }       \r
-       \r
-       @Override\r
-       public int readUnsignedShort() {\r
-               assertHasReadableBytes(2);\r
-               buf.position( (int) pointer );\r
-               int result = buf.getShort() & 0xffff;\r
-               pointer += 2;\r
-               return result;\r
+       }
+       
+       @Override
+       public char readChar() {
+               assertHasReadableBytes(2);
+               buf.position( (int) pointer );
+               char result = buf.getChar();
+               pointer += 2;
+               return result;
+       }       
+       
+       @Override
+       public int readUnsignedShort() {
+               assertHasReadableBytes(2);
+               buf.position( (int) pointer );
+               int result = buf.getShort() & 0xffff;
+               pointer += 2;
+               return result;
        }       
 
        @Override
@@ -302,22 +302,22 @@ public class BinaryMemory implements RandomAccessBinary {
                buf.position( (int) pointer );
                buf.put((byte) b);
                pointer += 1;
-       }\r
-       \r
-       @Override\r
-       public void writeByte(int b) throws IOException {\r
-               assertHasWritableBytes(1);\r
-               buf.position( (int) pointer );\r
-               buf.put((byte) b);\r
-               pointer += 1;\r
-       }       \r
-       \r
-       @Override\r
-       public void writeBoolean(boolean v) throws IOException {\r
-               assertHasWritableBytes(1);\r
-               buf.position( (int) pointer );\r
-               buf.put( (byte) (v ? 1 : 0) );\r
-               pointer += 1;\r
+       }
+       
+       @Override
+       public void writeByte(int b) throws IOException {
+               assertHasWritableBytes(1);
+               buf.position( (int) pointer );
+               buf.put((byte) b);
+               pointer += 1;
+       }       
+       
+       @Override
+       public void writeBoolean(boolean v) throws IOException {
+               assertHasWritableBytes(1);
+               buf.position( (int) pointer );
+               buf.put( (byte) (v ? 1 : 0) );
+               pointer += 1;
        }
 
        @Override
@@ -411,44 +411,44 @@ public class BinaryMemory implements RandomAccessBinary {
                buf.position( (int) pointer );
                buf.putShort( (short) value);
                pointer += 2;
-       }\r
-       \r
-       @Override\r
-       public void writeChar(int value) throws IOException {\r
-               assertHasWritableBytes(2);\r
-               buf.position( (int) pointer );\r
-               buf.putShort( (short) value);\r
-               pointer += 2;\r
-       }       \r
-       \r
-       @Override\r
-       public void writeBytes(String s) throws IOException {\r
-               int len = s.length();\r
-               assertHasWritableBytes(len);\r
-               buf.position( (int) pointer );\r
-               for (int i = 0 ; i < len ; i++) {\r
-                   buf.put((byte)s.charAt(i));\r
-               }\r
-               pointer += len;\r
-       }       \r
-       \r
-       @Override\r
-       public void writeChars(String s) throws IOException {\r
-        int len = s.length();\r
-               assertHasWritableBytes(len*2);\r
-        for (int i = 0 ; i < len ; i++) {\r
-            int v = s.charAt(i);\r
-            buf.put( (byte) ((v >>> 8) & 0xFF) ); \r
-            buf.put( (byte) ((v >>> 0) & 0xFF) ); \r
-        }\r
-               pointer += len*2;\r
-       }\r
-       \r
-       @Override\r
-       public void writeUTF(String s) throws IOException {\r
-               int len = UTF8.getModifiedUTF8EncodingByteLength(s);\r
-               writeShort(len);\r
-               UTF8.writeModifiedUTF(this, s);\r
+       }
+       
+       @Override
+       public void writeChar(int value) throws IOException {
+               assertHasWritableBytes(2);
+               buf.position( (int) pointer );
+               buf.putShort( (short) value);
+               pointer += 2;
+       }       
+       
+       @Override
+       public void writeBytes(String s) throws IOException {
+               int len = s.length();
+               assertHasWritableBytes(len);
+               buf.position( (int) pointer );
+               for (int i = 0 ; i < len ; i++) {
+                   buf.put((byte)s.charAt(i));
+               }
+               pointer += len;
+       }       
+       
+       @Override
+       public void writeChars(String s) throws IOException {
+        int len = s.length();
+               assertHasWritableBytes(len*2);
+        for (int i = 0 ; i < len ; i++) {
+            int v = s.charAt(i);
+            buf.put( (byte) ((v >>> 8) & 0xFF) ); 
+            buf.put( (byte) ((v >>> 0) & 0xFF) ); 
+        }
+               pointer += len*2;
+       }
+       
+       @Override
+       public void writeUTF(String s) throws IOException {
+               int len = UTF8.getModifiedUTF8EncodingByteLength(s);
+               writeShort(len);
+               UTF8.writeModifiedUTF(this, s);
        }       
 
        void assertHasReadableBytes(long count) {
@@ -554,15 +554,15 @@ public class BinaryMemory implements RandomAccessBinary {
 
        @Override
        public long skipBytes(long bytes) throws IOException {
-               pointer += bytes;\r
+               pointer += bytes;
+               return bytes;
+       }
+
+       @Override
+       public int skipBytes(int bytes) throws IOException {
+               pointer += bytes;
                return bytes;
        }
-\r
-       @Override\r
-       public int skipBytes(int bytes) throws IOException {\r
-               pointer += bytes;\r
-               return bytes;\r
-       }\r
        
        @Override
        public String toString() {