]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/bytes/LELong.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / bytes / LELong.java
index 7dcf96ff5810995d586ed2992c7e02b6777ab992..fdbda1fc13f073a25ea18f1d6b7afcca9142bc50 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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
-/*\r
- * Created on Jan 21, 2005\r
- * \r
- * Copyright Toni Kalajainen\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.simantics.utils.bytes;\r
-\r
-/**\r
- * Little Endian long <-> byte array conversions\r
- * Intel order\r
- *\r
- * @author Toni Kalajainen\r
- */\r
-public class LELong {\r
-\r
-        /**\r
-         * Convert long to byte array\r
-         * @param value long value\r
-         * @return byte array\r
-         */\r
-        public static byte[] toBytes(long value)\r
-        {\r
-                byte array[] = new byte[8];\r
-                array[7] = (byte) (value & 0xff);\r
-                array[6] = (byte) ((value >> 8) & 0xff);\r
-                array[5] = (byte) ((value >> 16) & 0xff);\r
-                array[4] = (byte) ((value >> 24) & 0xff);\r
-                array[3] = (byte) ((value >> 32) & 0xff);\r
-                array[2] = (byte) ((value >> 40) & 0xff);\r
-                array[1] = (byte) ((value >> 48) & 0xff);\r
-                array[0] = (byte) ((value >> 56) & 0xff);\r
-                return array;\r
-        }\r
-\r
-        /**\r
-         * Write long value to byte array\r
-         * @param value the long value\r
-         * @param array the byte array\r
-         * @param offset the offset\r
-         */\r
-        public static void write(long value, byte array[], int offset)\r
-        {\r
-                if (offset+8>array.length)\r
-                        throw new IndexOutOfBoundsException();\r
-                array[7 + offset] = (byte) (value & 0xff);\r
-                array[6 + offset] = (byte) (value >> 8);\r
-                array[5 + offset] = (byte) (value >> 16);\r
-                array[4 + offset] = (byte) (value >> 24);\r
-                array[3 + offset] = (byte) (value >> 32);\r
-                array[2 + offset] = (byte) (value >> 40);\r
-                array[1 + offset] = (byte) (value >> 48);\r
-                array[0 + offset] = (byte) (value >> 56);\r
-        }\r
-\r
-        /**\r
-         * Write long value to byte array\r
-         * @param value the long value\r
-         * @param array the byte array\r
-         */\r
-        public static void write(long value, byte array[])\r
-        {\r
-                if (array.length<8)\r
-                        throw new IndexOutOfBoundsException();\r
-                array[7] = (byte) (value & 0xff);\r
-                array[6] = (byte) (value >> 8);\r
-                array[5] = (byte) (value >> 16);\r
-                array[4] = (byte) (value >> 24);\r
-                array[3] = (byte) (value >> 32);\r
-                array[2] = (byte) (value >> 40);\r
-                array[1] = (byte) (value >> 48);\r
-                array[0] = (byte) (value >> 56);\r
-        }\r
-        \r
-        /**\r
-         * read long value from byte array\r
-         * @param array the array\r
-         * @param offset offset\r
-         * @return the value\r
-         */\r
-        public static long toLong(byte array[], int offset)\r
-        {\r
-                if (offset+8>array.length)\r
-                        throw new IndexOutOfBoundsException();\r
-                long value =\r
-                        ( ((long) array[7 + offset] & 0xFF) ) |\r
-                        ( ((long) array[6 + offset] & 0xFF) << 8) |\r
-                        ( ((long) array[5 + offset] & 0xFF) << 16) |\r
-                        ( ((long) array[4 + offset] & 0xFF) << 24) |\r
-                        ( ((long) array[3 + offset] & 0xFF) << 32) |\r
-                        ( ((long) array[2 + offset] & 0xFF) << 40) |\r
-                        ( ((long) array[1 + offset] & 0xFF) << 48) |\r
-                        ( ((long) array[0 + offset] & 0xFF) << 56);\r
-                return value;\r
-        }\r
-\r
-        /**\r
-         * read long value from byte array\r
-         * @param array the array\r
-         * @return the value\r
-         */\r
-        public static long toLong(byte array[])\r
-        {\r
-                if (8>array.length)\r
-                        throw new IndexOutOfBoundsException();\r
-                long value =\r
-                        ( ((long) array[7] & 0xFF) ) |\r
-                        ( ((long) array[6] & 0xFF) << 8) |\r
-                        ( ((long) array[5] & 0xFF) << 16) |\r
-                        ( ((long) array[4] & 0xFF) << 24) |\r
-                        ( ((long) array[3] & 0xFF) << 32) |\r
-                        ( ((long) array[2] & 0xFF) << 40) |\r
-                        ( ((long) array[1] & 0xFF) << 48) |\r
-                        ( ((long) array[0] & 0xFF) << 56);\r
-                return value;\r
-        }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.
+ * 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
+ *******************************************************************************/
+/*
+ * Created on Jan 21, 2005
+ * 
+ * Copyright Toni Kalajainen
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.simantics.utils.bytes;
+
+/**
+ * Little Endian long <-> byte array conversions
+ * Intel order
+ *
+ * @author Toni Kalajainen
+ */
+public class LELong {
+
+        /**
+         * Convert long to byte array
+         * @param value long value
+         * @return byte array
+         */
+        public static byte[] toBytes(long value)
+        {
+                byte array[] = new byte[8];
+                array[7] = (byte) (value & 0xff);
+                array[6] = (byte) ((value >> 8) & 0xff);
+                array[5] = (byte) ((value >> 16) & 0xff);
+                array[4] = (byte) ((value >> 24) & 0xff);
+                array[3] = (byte) ((value >> 32) & 0xff);
+                array[2] = (byte) ((value >> 40) & 0xff);
+                array[1] = (byte) ((value >> 48) & 0xff);
+                array[0] = (byte) ((value >> 56) & 0xff);
+                return array;
+        }
+
+        /**
+         * Write long value to byte array
+         * @param value the long value
+         * @param array the byte array
+         * @param offset the offset
+         */
+        public static void write(long value, byte array[], int offset)
+        {
+                if (offset+8>array.length)
+                        throw new IndexOutOfBoundsException();
+                array[7 + offset] = (byte) (value & 0xff);
+                array[6 + offset] = (byte) (value >> 8);
+                array[5 + offset] = (byte) (value >> 16);
+                array[4 + offset] = (byte) (value >> 24);
+                array[3 + offset] = (byte) (value >> 32);
+                array[2 + offset] = (byte) (value >> 40);
+                array[1 + offset] = (byte) (value >> 48);
+                array[0 + offset] = (byte) (value >> 56);
+        }
+
+        /**
+         * Write long value to byte array
+         * @param value the long value
+         * @param array the byte array
+         */
+        public static void write(long value, byte array[])
+        {
+                if (array.length<8)
+                        throw new IndexOutOfBoundsException();
+                array[7] = (byte) (value & 0xff);
+                array[6] = (byte) (value >> 8);
+                array[5] = (byte) (value >> 16);
+                array[4] = (byte) (value >> 24);
+                array[3] = (byte) (value >> 32);
+                array[2] = (byte) (value >> 40);
+                array[1] = (byte) (value >> 48);
+                array[0] = (byte) (value >> 56);
+        }
+        
+        /**
+         * read long value from byte array
+         * @param array the array
+         * @param offset offset
+         * @return the value
+         */
+        public static long toLong(byte array[], int offset)
+        {
+                if (offset+8>array.length)
+                        throw new IndexOutOfBoundsException();
+                long value =
+                        ( ((long) array[7 + offset] & 0xFF) ) |
+                        ( ((long) array[6 + offset] & 0xFF) << 8) |
+                        ( ((long) array[5 + offset] & 0xFF) << 16) |
+                        ( ((long) array[4 + offset] & 0xFF) << 24) |
+                        ( ((long) array[3 + offset] & 0xFF) << 32) |
+                        ( ((long) array[2 + offset] & 0xFF) << 40) |
+                        ( ((long) array[1 + offset] & 0xFF) << 48) |
+                        ( ((long) array[0 + offset] & 0xFF) << 56);
+                return value;
+        }
+
+        /**
+         * read long value from byte array
+         * @param array the array
+         * @return the value
+         */
+        public static long toLong(byte array[])
+        {
+                if (8>array.length)
+                        throw new IndexOutOfBoundsException();
+                long value =
+                        ( ((long) array[7] & 0xFF) ) |
+                        ( ((long) array[6] & 0xFF) << 8) |
+                        ( ((long) array[5] & 0xFF) << 16) |
+                        ( ((long) array[4] & 0xFF) << 24) |
+                        ( ((long) array[3] & 0xFF) << 32) |
+                        ( ((long) array[2] & 0xFF) << 40) |
+                        ( ((long) array[1] & 0xFF) << 48) |
+                        ( ((long) array[0] & 0xFF) << 56);
+                return value;
+        }
+}