]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/serialization/impl/LongArraySerializer.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / serialization / impl / LongArraySerializer.java
index 003b175fd7457e85014b1001a0e4ceefabce7179..af5342d004f11833aeb076d945a9ecb82db91fdf 100644 (file)
-package org.simantics.databoard.serialization.impl;\r
-\r
-import java.io.DataInput;\r
-import java.io.DataOutput;\r
-import java.io.IOException;\r
-import java.util.List;\r
-\r
-import org.simantics.databoard.binding.ArrayBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.serialization.SerializationException;\r
-import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;\r
-import org.simantics.databoard.type.ArrayType;\r
-import org.simantics.databoard.util.Range;\r
-\r
-public class LongArraySerializer extends NonRecursiveSerializer {\r
-\r
-       Range length;\r
-       Integer fixedLength, fixedSize;\r
-       \r
-       public LongArraySerializer(ArrayBinding binding)\r
-       {\r
-               ArrayType arrayType = (ArrayType) binding.type();\r
-               this.length = arrayType.getLength();\r
-               if (length!=null && length.getLower().equals(length.getUpper()) && length.getLower().getValue()!=null)\r
-               {\r
-                       fixedLength = length.getLower().getValue().intValue();\r
-                       fixedSize = fixedLength * 8;\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public Object deserialize(DataInput in)\r
-       throws IOException \r
-       {\r
-               int length = fixedSize != null ? fixedLength : in.readInt();                    \r
-               if (length<0) throw new SerializationException("Cannot use negative array length");\r
-               assertRemainingBytes(in, length*8L);                                    \r
-\r
-               long[] array = new long[length];\r
-               for(int i=0;i<array.length;++i)\r
-                       array[i] = in.readLong();\r
-               return array;\r
-       }\r
-       \r
-       public Object deserializeToTry(DataInput in, List<Object> identities, Object obj) throws IOException\r
-       {\r
-               int length = fixedLength != null ? fixedLength : in.readInt();\r
-               long[] array = (long[]) obj;\r
-               if (length!=array.length) array = new long[ length ];\r
-               assertRemainingBytes(in, length*8L);                                    \r
-               \r
-               for (int i=0; i<array.length;i++)\r
-                       array[i] = in.readLong();\r
-               \r
-               return array;\r
-       }\r
-       \r
-\r
-       @Override\r
-       public void deserializeTo(DataInput in, Object obj) throws IOException {\r
-               try {\r
-                       int length = fixedLength != null ? fixedLength : in.readInt();\r
-                       long[] array = (long[]) obj;\r
-                       if (length!=array.length) throw new BindingException("primitive array is size immutable");\r
-                       assertRemainingBytes(in, length*8L);                                    \r
-                       for (int i=0; i<array.length;i++)\r
-                               array[i] = in.readLong();\r
-               } catch (BindingException e) {\r
-                       throw new IOException( e ); \r
-               }\r
-       }\r
-\r
-       @Override\r
-       public void skip(DataInput in)\r
-       throws IOException {\r
-               int length = fixedSize != null ? fixedLength : in.readInt();                    \r
-               in.skipBytes(8* length);                        \r
-       }\r
-       \r
-       @Override\r
-       public void serialize(DataOutput out, Object obj)\r
-       throws IOException \r
-       {\r
-               long[] array = (long[])obj;\r
-               if (fixedSize==null) \r
-                       out.writeInt(array.length);\r
-               for(long f : array)\r
-                       out.writeLong(f);\r
-       }\r
-\r
-       @Override\r
-       public Integer getConstantSize() {\r
-               return fixedSize;\r
-       }\r
-\r
-       @Override\r
-       public int getSize(Object obj) {\r
-               if (fixedSize!=null) return fixedSize;\r
-               long[] array = (long[])obj;                     \r
-               return 4 + 8 * array.length;\r
-       }\r
-       \r
-       @Override\r
-       public int getMinSize() {\r
-               return fixedSize != null ? fixedSize : 4;\r
-       }\r
-       \r
-}\r
+package org.simantics.databoard.serialization.impl;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+
+import org.simantics.databoard.binding.ArrayBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.serialization.SerializationException;
+import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
+import org.simantics.databoard.type.ArrayType;
+import org.simantics.databoard.util.Range;
+
+public class LongArraySerializer extends NonRecursiveSerializer {
+
+       Range length;
+       Integer fixedLength, fixedSize;
+       
+       public LongArraySerializer(ArrayBinding binding)
+       {
+               ArrayType arrayType = (ArrayType) binding.type();
+               this.length = arrayType.getLength();
+               if (length!=null && length.getLower().equals(length.getUpper()) && length.getLower().getValue()!=null)
+               {
+                       fixedLength = length.getLower().getValue().intValue();
+                       fixedSize = fixedLength * 8;
+               }
+       }
+       
+       @Override
+       public Object deserialize(DataInput in)
+       throws IOException 
+       {
+               int length = fixedSize != null ? fixedLength : in.readInt();                    
+               if (length<0) throw new SerializationException("Cannot use negative array length");
+               assertRemainingBytes(in, length*8L);                                    
+
+               long[] array = new long[length];
+               for(int i=0;i<array.length;++i)
+                       array[i] = in.readLong();
+               return array;
+       }
+       
+       public Object deserializeToTry(DataInput in, List<Object> identities, Object obj) throws IOException
+       {
+               int length = fixedLength != null ? fixedLength : in.readInt();
+               long[] array = (long[]) obj;
+               if (length!=array.length) array = new long[ length ];
+               assertRemainingBytes(in, length*8L);                                    
+               
+               for (int i=0; i<array.length;i++)
+                       array[i] = in.readLong();
+               
+               return array;
+       }
+       
+
+       @Override
+       public void deserializeTo(DataInput in, Object obj) throws IOException {
+               try {
+                       int length = fixedLength != null ? fixedLength : in.readInt();
+                       long[] array = (long[]) obj;
+                       if (length!=array.length) throw new BindingException("primitive array is size immutable");
+                       assertRemainingBytes(in, length*8L);                                    
+                       for (int i=0; i<array.length;i++)
+                               array[i] = in.readLong();
+               } catch (BindingException e) {
+                       throw new IOException( e ); 
+               }
+       }
+
+       @Override
+       public void skip(DataInput in)
+       throws IOException {
+               int length = fixedSize != null ? fixedLength : in.readInt();                    
+               in.skipBytes(8* length);                        
+       }
+       
+       @Override
+       public void serialize(DataOutput out, Object obj)
+       throws IOException 
+       {
+               long[] array = (long[])obj;
+               if (fixedSize==null) 
+                       out.writeInt(array.length);
+               for(long f : array)
+                       out.writeLong(f);
+       }
+
+       @Override
+       public Integer getConstantSize() {
+               return fixedSize;
+       }
+
+       @Override
+       public int getSize(Object obj) {
+               if (fixedSize!=null) return fixedSize;
+               long[] array = (long[])obj;                     
+               return 4 + 8 * array.length;
+       }
+       
+       @Override
+       public int getMinSize() {
+               return fixedSize != null ? fixedSize : 4;
+       }
+       
+}