X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.utils%2Fsrc%2Forg%2Fsimantics%2Futils%2Fbytes%2FLEString.java;h=d909377f0385acd1e1caa758cd0fdc25ee99af9e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=c88e08d84356a5d918d80b65ec202d418bf9aabd;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/bytes/LEString.java b/bundles/org.simantics.utils/src/org/simantics/utils/bytes/LEString.java index c88e08d84..d909377f0 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/bytes/LEString.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/bytes/LEString.java @@ -1,185 +1,185 @@ -/******************************************************************************* - * 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; - -import org.simantics.utils.strings.EString; - -/** - * Byte array <-> string conversions - * - * All conversions have length in the beginning (32-bit integer) and - * followed by actual chars - * - * the length is in Little Endian - * - * @author Toni Kalajainen - */ -public class LEString { - - public static byte[] toBytes(String s) { - int size = s.length(); - byte array[] = new byte[size + 4]; - // write length - LEInt.write(size, array); - // write chars - for (int i=0; iarray.length) - throw new IndexOutOfBoundsException(); - LEInt.write(size, array, offset); - for (int i=0; iarray.length) - throw new IndexOutOfBoundsException(); - LEInt.write(size, array); - for (int i=0; iarray.length) - throw new IndexOutOfBoundsException(); - // read size - int size = LEInt.toInt(array, offset); - if (offset+4+size>array.length) - throw new IndexOutOfBoundsException(); - // read chars - //return new String(array, 4+offset, size); - char chars[] = new char[size]; - for (int i=0; iarray.length) - throw new IndexOutOfBoundsException(); - // read size - int size = LEInt.toInt(array); - if (4+size>array.length) - throw new IndexOutOfBoundsException(); - // read chars - //return new String(array, 4, size); - char chars[] = new char[size]; - for (int i=0; i>4) & 0xF] + result; - value >>= 8; - } - return result; - } - - public static void printByteArray(byte array[]) { - for (int i=0; i string conversions + * + * All conversions have length in the beginning (32-bit integer) and + * followed by actual chars + * + * the length is in Little Endian + * + * @author Toni Kalajainen + */ +public class LEString { + + public static byte[] toBytes(String s) { + int size = s.length(); + byte array[] = new byte[size + 4]; + // write length + LEInt.write(size, array); + // write chars + for (int i=0; iarray.length) + throw new IndexOutOfBoundsException(); + LEInt.write(size, array, offset); + for (int i=0; iarray.length) + throw new IndexOutOfBoundsException(); + LEInt.write(size, array); + for (int i=0; iarray.length) + throw new IndexOutOfBoundsException(); + // read size + int size = LEInt.toInt(array, offset); + if (offset+4+size>array.length) + throw new IndexOutOfBoundsException(); + // read chars + //return new String(array, 4+offset, size); + char chars[] = new char[size]; + for (int i=0; iarray.length) + throw new IndexOutOfBoundsException(); + // read size + int size = LEInt.toInt(array); + if (4+size>array.length) + throw new IndexOutOfBoundsException(); + // read chars + //return new String(array, 4, size); + char chars[] = new char[size]; + for (int i=0; i>4) & 0xF] + result; + value >>= 8; + } + return result; + } + + public static void printByteArray(byte array[]) { + for (int i=0; i