http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteByteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteByteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteByteUtils.java new file mode 100644 index 0000000..793f7ce --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteByteUtils.java @@ -0,0 +1,705 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.ignite.internal.util; + + +import org.apache.ignite.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.nio.*; +import java.util.*; +import java.util.zip.*; + +/** + * Collection of utility methods used throughout the system. + */ +public class IgniteByteUtils { + /** + * Writes collection of byte arrays to data output. + * + * @param out Output to write to. + * @param bytes Collection with byte arrays. + * @throws java.io.IOException If write failed. + */ + public static void writeBytesCollection(DataOutput out, Collection<byte[]> bytes) throws IOException { + if (bytes != null) { + out.writeInt(bytes.size()); + + for (byte[] b : bytes) + writeByteArray(out, b); + } + else + out.writeInt(-1); + } + + /** + * Reads collection of byte arrays from data input. + * + * @param in Data input to read from. + * @return List of byte arrays. + * @throws java.io.IOException If read failed. + */ + public static List<byte[]> readBytesList(DataInput in) throws IOException { + int size = in.readInt(); + + if (size < 0) + return null; + + List<byte[]> res = new ArrayList<>(size); + + for (int i = 0; i < size; i++) + res.add(readByteArray(in)); + + return res; + } + + /** + * Writes byte array to output stream accounting for <tt>null</tt> values. + * + * @param out Output stream to write to. + * @param arr Array to write, possibly <tt>null</tt>. + * @throws java.io.IOException If write failed. + */ + public static void writeByteArray(DataOutput out, @Nullable byte[] arr) throws IOException { + if (arr == null) + out.writeInt(-1); + else { + out.writeInt(arr.length); + + out.write(arr); + } + } + + /** + * Writes byte array to output stream accounting for <tt>null</tt> values. + * + * @param out Output stream to write to. + * @param arr Array to write, possibly <tt>null</tt>. + * @throws java.io.IOException If write failed. + */ + public static void writeByteArray(DataOutput out, @Nullable byte[] arr, int maxLen) throws IOException { + if (arr == null) + out.writeInt(-1); + else { + int len = Math.min(arr.length, maxLen); + + out.writeInt(len); + + out.write(arr, 0, len); + } + } + + /** + * Reads byte array from input stream accounting for <tt>null</tt> values. + * + * @param in Stream to read from. + * @return Read byte array, possibly <tt>null</tt>. + * @throws java.io.IOException If read failed. + */ + @Nullable public static byte[] readByteArray(DataInput in) throws IOException { + int len = in.readInt(); + + if (len == -1) + return null; // Value "-1" indicates null. + + byte[] res = new byte[len]; + + in.readFully(res); + + return res; + } + + /** + * Reads byte array from given buffers (changing buffer positions). + * + * @param bufs Byte buffers. + * @return Byte array. + */ + public static byte[] readByteArray(ByteBuffer... bufs) { + assert !F.isEmpty(bufs); + + int size = 0; + + for (ByteBuffer buf : bufs) + size += buf.remaining(); + + byte[] res = new byte[size]; + + int off = 0; + + for (ByteBuffer buf : bufs) { + int len = buf.remaining(); + + if (len != 0) { + buf.get(res, off, len); + + off += len; + } + } + + assert off == res.length; + + return res; + } + + /** + * // FIXME: added for DR dataCenterIds, review if it is needed after GG-6879. + * + * @param out Output. + * @param col Set to write. + * @throws java.io.IOException If write failed. + */ + public static void writeByteCollection(DataOutput out, Collection<Byte> col) throws IOException { + if (col != null) { + out.writeInt(col.size()); + + for (Byte i : col) + out.writeByte(i); + } + else + out.writeInt(-1); + } + + /** + * // FIXME: added for DR dataCenterIds, review if it is needed after GG-6879. + * + * @param in Input. + * @return Deserialized list. + * @throws java.io.IOException If deserialization failed. + */ + @Nullable public static List<Byte> readByteList(DataInput in) throws IOException { + int size = in.readInt(); + + // Check null flag. + if (size == -1) + return null; + + List<Byte> col = new ArrayList<>(size); + + for (int i = 0; i < size; i++) + col.add(in.readByte()); + + return col; + } + + /** + * Join byte arrays into single one. + * + * @param bufs list of byte arrays to concatenate. + * @return Concatenated byte's array. + */ + public static byte[] join(byte[]... bufs) { + int size = 0; + for (byte[] buf : bufs) { + size += buf.length; + } + + byte[] res = new byte[size]; + int position = 0; + for (byte[] buf : bufs) { + IgniteUtils.arrayCopy(buf, 0, res, position, buf.length); + position += buf.length; + } + + return res; + } + + /** + * Converts byte array to formatted string. If calling: + * <pre name="code" class="java"> + * ... + * byte[] data = {10, 20, 30, 40, 50, 60, 70, 80, 90}; + * + * U.byteArray2String(data, "0x%02X", ",0x%02X") + * ... + * </pre> + * the result will be: + * <pre name="code" class="java"> + * ... + * 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50, 0x5A + * ... + * </pre> + * + * @param arr Array of byte. + * @param hdrFmt C-style string format for the first element. + * @param bodyFmt C-style string format for second and following elements, if any. + * @return String with converted bytes. + */ + public static String byteArray2String(byte[] arr, String hdrFmt, String bodyFmt) { + assert arr != null; + assert hdrFmt != null; + assert bodyFmt != null; + + SB sb = new SB(); + + sb.a('{'); + + boolean first = true; + + for (byte b : arr) + if (first) { + sb.a(String.format(hdrFmt, b)); + + first = false; + } + else + sb.a(String.format(bodyFmt, b)); + + sb.a('}'); + + return sb.toString(); + } + + /** + * Convert string with hex values to byte array. + * + * @param hex Hexadecimal string to convert. + * @return array of bytes defined as hex in string. + * @throws IllegalArgumentException If input character differs from certain hex characters. + */ + public static byte[] hexString2ByteArray(String hex) throws IllegalArgumentException { + // If Hex string has odd character length. + if (hex.length() % 2 != 0) + hex = '0' + hex; + + char[] chars = hex.toCharArray(); + + byte[] bytes = new byte[chars.length / 2]; + + int byteCnt = 0; + + for (int i = 0; i < chars.length; i += 2) { + int newByte = 0; + + newByte |= hexCharToByte(chars[i]); + + newByte <<= 4; + + newByte |= hexCharToByte(chars[i + 1]); + + bytes[byteCnt] = (byte)newByte; + + byteCnt++; + } + + return bytes; + } + + /** + * Return byte value for certain character. + * + * @param ch Character + * @return Byte value. + * @throws IllegalArgumentException If input character differ from certain hex characters. + */ + @SuppressWarnings({"UnnecessaryFullyQualifiedName", "fallthrough"}) + private static byte hexCharToByte(char ch) throws IllegalArgumentException { + switch (ch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return (byte)(ch - '0'); + + case 'a': + case 'A': + return 0xa; + + case 'b': + case 'B': + return 0xb; + + case 'c': + case 'C': + return 0xc; + + case 'd': + case 'D': + return 0xd; + + case 'e': + case 'E': + return 0xe; + + case 'f': + case 'F': + return 0xf; + + default: + throw new IllegalArgumentException("Hex decoding wrong input character [character=" + ch + ']'); + } + } + + /** + * Converts primitive double to byte array. + * + * @param d Double to convert. + * @return Byte array. + */ + public static byte[] doubleToBytes(double d) { + return longToBytes(Double.doubleToLongBits(d)); + } + + /** + * Converts primitive {@code double} type to byte array and stores + * it in the specified byte array. + * + * @param d Double to convert. + * @param bytes Array of bytes. + * @param off Offset. + * @return New offset. + */ + public static int doubleToBytes(double d, byte[] bytes, int off) { + return longToBytes(Double.doubleToLongBits(d), bytes, off); + } + + /** + * Converts primitive float to byte array. + * + * @param f Float to convert. + * @return Array of bytes. + */ + public static byte[] floatToBytes(float f) { + return intToBytes(Float.floatToIntBits(f)); + } + + /** + * Converts primitive float to byte array. + * + * @param f Float to convert. + * @param bytes Array of bytes. + * @param off Offset. + * @return New offset. + */ + public static int floatToBytes(float f, byte[] bytes, int off) { + return intToBytes(Float.floatToIntBits(f), bytes, off); + } + + /** + * Converts primitive {@code long} type to byte array. + * + * @param l Long value. + * @return Array of bytes. + */ + public static byte[] longToBytes(long l) { + return GridClientByteUtils.longToBytes(l); + } + + /** + * Converts primitive {@code long} type to byte array and stores it in specified + * byte array. + * + * @param l Long value. + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Number of bytes overwritten in {@code bytes} array. + */ + public static int longToBytes(long l, byte[] bytes, int off) { + return off + GridClientByteUtils.longToBytes(l, bytes, off); + } + + /** + * Converts primitive {@code int} type to byte array. + * + * @param i Integer value. + * @return Array of bytes. + */ + public static byte[] intToBytes(int i) { + return GridClientByteUtils.intToBytes(i); + } + + /** + * Converts primitive {@code int} type to byte array and stores it in specified + * byte array. + * + * @param i Integer value. + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Number of bytes overwritten in {@code bytes} array. + */ + public static int intToBytes(int i, byte[] bytes, int off) { + return off + GridClientByteUtils.intToBytes(i, bytes, off); + } + + /** + * Converts primitive {@code short} type to byte array. + * + * @param s Short value. + * @return Array of bytes. + */ + public static byte[] shortToBytes(short s) { + return GridClientByteUtils.shortToBytes(s); + } + + /** + * Converts primitive {@code short} type to byte array and stores it in specified + * byte array. + * + * @param s Short value. + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Number of bytes overwritten in {@code bytes} array. + */ + public static int shortToBytes(short s, byte[] bytes, int off) { + return off + GridClientByteUtils.shortToBytes(s, bytes, off); + } + + /** + * Encodes {@link java.util.UUID} into a sequence of bytes using the {@link java.nio.ByteBuffer}, + * storing the result into a new byte array. + * + * @param uuid Unique identifier. + * @param arr Byte array to fill with result. + * @param off Offset in {@code arr}. + * @return Number of bytes overwritten in {@code bytes} array. + */ + public static int uuidToBytes(@Nullable UUID uuid, byte[] arr, int off) { + return off + GridClientByteUtils.uuidToBytes(uuid, arr, off); + } + + /** + * Converts an UUID to byte array. + * + * @param uuid UUID value. + * @return Encoded into byte array {@link java.util.UUID}. + */ + public static byte[] uuidToBytes(@Nullable UUID uuid) { + return GridClientByteUtils.uuidToBytes(uuid); + } + + /** + * Constructs {@code short} from byte array. + * + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Short value. + */ + public static short bytesToShort(byte[] bytes, int off) { + assert bytes != null; + + int bytesCnt = Short.SIZE >> 3; + + if (off + bytesCnt > bytes.length) + // Just use the remainder. + bytesCnt = bytes.length - off; + + short res = 0; + + for (int i = 0; i < bytesCnt; i++) { + int shift = bytesCnt - i - 1 << 3; + + res |= (0xffL & bytes[off++]) << shift; + } + + return res; + } + + /** + * Constructs {@code int} from byte array. + * + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Integer value. + */ + public static int bytesToInt(byte[] bytes, int off) { + assert bytes != null; + + int bytesCnt = Integer.SIZE >> 3; + + if (off + bytesCnt > bytes.length) + // Just use the remainder. + bytesCnt = bytes.length - off; + + int res = 0; + + for (int i = 0; i < bytesCnt; i++) { + int shift = bytesCnt - i - 1 << 3; + + res |= (0xffL & bytes[off++]) << shift; + } + + return res; + } + + /** + * Constructs {@code long} from byte array. + * + * @param bytes Array of bytes. + * @param off Offset in {@code bytes} array. + * @return Long value. + */ + public static long bytesToLong(byte[] bytes, int off) { + assert bytes != null; + + int bytesCnt = Long.SIZE >> 3; + + if (off + bytesCnt > bytes.length) + bytesCnt = bytes.length - off; + + long res = 0; + + for (int i = 0; i < bytesCnt; i++) { + int shift = bytesCnt - i - 1 << 3; + + res |= (0xffL & bytes[off++]) << shift; + } + + return res; + } + + /** + * Reads an {@link java.util.UUID} form byte array. + * If given array contains all 0s then {@code null} will be returned. + * + * @param bytes array of bytes. + * @param off Offset in {@code bytes} array. + * @return UUID value or {@code null}. + */ + public static UUID bytesToUuid(byte[] bytes, int off) { + return GridClientByteUtils.bytesToUuid(bytes, off); + } + + /** + * Constructs double from byte array. + * + * @param bytes Byte array. + * @param off Offset in {@code bytes} array. + * @return Double value. + */ + public static double bytesToDouble(byte[] bytes, int off) { + return Double.longBitsToDouble(bytesToLong(bytes, off)); + } + + /** + * Constructs float from byte array. + * + * @param bytes Byte array. + * @param off Offset in {@code bytes} array. + * @return Float value. + */ + public static float bytesToFloat(byte[] bytes, int off) { + return Float.intBitsToFloat(bytesToInt(bytes, off)); + } + + /** + * Compares fragments of byte arrays. + * + * @param a First array. + * @param aOff First array offset. + * @param b Second array. + * @param bOff Second array offset. + * @param len Length of fragments. + * @return {@code true} if fragments are equal, {@code false} otherwise. + */ + public static boolean bytesEqual(byte[] a, int aOff, byte[] b, int bOff, int len) { + if (aOff + len > a.length || bOff + len > b.length) + return false; + else { + for (int i = 0; i < len; i++) + if (a[aOff + i] != b[bOff + i]) + return false; + + return true; + } + } + + /** + * Converts an array of characters representing hexidecimal values into an + * array of bytes of those same values. The returned array will be half the + * length of the passed array, as it takes two characters to represent any + * given byte. An exception is thrown if the passed char array has an odd + * number of elements. + * + * @param data An array of characters containing hexidecimal digits + * @return A byte array containing binary data decoded from + * the supplied char array. + * @throws org.apache.ignite.IgniteCheckedException Thrown if an odd number or illegal of characters is supplied. + */ + public static byte[] decodeHex(char[] data) throws IgniteCheckedException { + + int len = data.length; + + if ((len & 0x01) != 0) + throw new IgniteCheckedException("Odd number of characters."); + + byte[] out = new byte[len >> 1]; + + // Two characters form the hex value. + for (int i = 0, j = 0; j < len; i++) { + int f = IgniteUtils.toDigit(data[j], j) << 4; + + j++; + + f |= IgniteUtils.toDigit(data[j], j); + + j++; + + out[i] = (byte)(f & 0xFF); + } + + return out; + } + + /** + * Zips byte array. + * + * @param input Input bytes. + * @return Zipped byte array. + * @throws java.io.IOException If failed. + */ + public static byte[] zipBytes(byte[] input) throws IOException { + return zipBytes(input, 4096); + } + + /** + * Zips byte array. + * + * @param input Input bytes. + * @param initBufSize Initial buffer size. + * @return Zipped byte array. + * @throws java.io.IOException If failed. + */ + public static byte[] zipBytes(byte[] input, int initBufSize) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(initBufSize); + + try (ZipOutputStream zos = new ZipOutputStream(bos)) { + ZipEntry entry = new ZipEntry(""); + + try { + entry.setSize(input.length); + + zos.putNextEntry(entry); + + zos.write(input); + } finally { + zos.closeEntry(); + } + } + + return bos.toByteArray(); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index ea73ca6..d0158ed 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -240,7 +240,7 @@ public abstract class IgniteUtils { indexOf('.', IgniteUtils.class.getName().indexOf('.') + 1)); /** Network packet header. */ - public static final byte[] IGNITE_HEADER = U.intToBytes(0x00004747); + public static final byte[] IGNITE_HEADER = IgniteByteUtils.intToBytes(0x00004747); /** Default buffer size = 4K. */ private static final int BUF_SIZE = 4096; @@ -1291,45 +1291,6 @@ public abstract class IgniteUtils { } /** - * Writes collection of byte arrays to data output. - * - * @param out Output to write to. - * @param bytes Collection with byte arrays. - * @throws IOException If write failed. - */ - public static void writeBytesCollection(DataOutput out, Collection<byte[]> bytes) throws IOException { - if (bytes != null) { - out.writeInt(bytes.size()); - - for (byte[] b : bytes) - writeByteArray(out, b); - } - else - out.writeInt(-1); - } - - /** - * Reads collection of byte arrays from data input. - * - * @param in Data input to read from. - * @return List of byte arrays. - * @throws IOException If read failed. - */ - public static List<byte[]> readBytesList(DataInput in) throws IOException { - int size = in.readInt(); - - if (size < 0) - return null; - - List<byte[]> res = new ArrayList<>(size); - - for (int i = 0; i < size; i++) - res.add(readByteArray(in)); - - return res; - } - - /** * * @param out Output. * @param col Set to write. @@ -2571,74 +2532,6 @@ public abstract class IgniteUtils { } /** - * Join byte arrays into single one. - * - * @param bufs list of byte arrays to concatenate. - * @return Concatenated byte's array. - */ - public static byte[] join(byte[]... bufs) { - int size = 0; - for (byte[] buf : bufs) { - size += buf.length; - } - - byte[] res = new byte[size]; - int position = 0; - for (byte[] buf : bufs) { - arrayCopy(buf, 0, res, position, buf.length); - position += buf.length; - } - - return res; - } - - /** - * Converts byte array to formatted string. If calling: - * <pre name="code" class="java"> - * ... - * byte[] data = {10, 20, 30, 40, 50, 60, 70, 80, 90}; - * - * U.byteArray2String(data, "0x%02X", ",0x%02X") - * ... - * </pre> - * the result will be: - * <pre name="code" class="java"> - * ... - * 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50, 0x5A - * ... - * </pre> - * - * @param arr Array of byte. - * @param hdrFmt C-style string format for the first element. - * @param bodyFmt C-style string format for second and following elements, if any. - * @return String with converted bytes. - */ - public static String byteArray2String(byte[] arr, String hdrFmt, String bodyFmt) { - assert arr != null; - assert hdrFmt != null; - assert bodyFmt != null; - - SB sb = new SB(); - - sb.a('{'); - - boolean first = true; - - for (byte b : arr) - if (first) { - sb.a(String.format(hdrFmt, b)); - - first = false; - } - else - sb.a(String.format(bodyFmt, b)); - - sb.a('}'); - - return sb.toString(); - } - - /** * Converts byte array to hex string. * * @param arr Array of bytes. @@ -2654,365 +2547,6 @@ public abstract class IgniteUtils { } /** - * Convert string with hex values to byte array. - * - * @param hex Hexadecimal string to convert. - * @return array of bytes defined as hex in string. - * @throws IllegalArgumentException If input character differs from certain hex characters. - */ - public static byte[] hexString2ByteArray(String hex) throws IllegalArgumentException { - // If Hex string has odd character length. - if (hex.length() % 2 != 0) - hex = '0' + hex; - - char[] chars = hex.toCharArray(); - - byte[] bytes = new byte[chars.length / 2]; - - int byteCnt = 0; - - for (int i = 0; i < chars.length; i += 2) { - int newByte = 0; - - newByte |= hexCharToByte(chars[i]); - - newByte <<= 4; - - newByte |= hexCharToByte(chars[i + 1]); - - bytes[byteCnt] = (byte)newByte; - - byteCnt++; - } - - return bytes; - } - - /** - * Return byte value for certain character. - * - * @param ch Character - * @return Byte value. - * @throws IllegalArgumentException If input character differ from certain hex characters. - */ - @SuppressWarnings({"UnnecessaryFullyQualifiedName", "fallthrough"}) - private static byte hexCharToByte(char ch) throws IllegalArgumentException { - switch (ch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return (byte)(ch - '0'); - - case 'a': - case 'A': - return 0xa; - - case 'b': - case 'B': - return 0xb; - - case 'c': - case 'C': - return 0xc; - - case 'd': - case 'D': - return 0xd; - - case 'e': - case 'E': - return 0xe; - - case 'f': - case 'F': - return 0xf; - - default: - throw new IllegalArgumentException("Hex decoding wrong input character [character=" + ch + ']'); - } - } - - /** - * Converts primitive double to byte array. - * - * @param d Double to convert. - * @return Byte array. - */ - public static byte[] doubleToBytes(double d) { - return longToBytes(Double.doubleToLongBits(d)); - } - - /** - * Converts primitive {@code double} type to byte array and stores - * it in the specified byte array. - * - * @param d Double to convert. - * @param bytes Array of bytes. - * @param off Offset. - * @return New offset. - */ - public static int doubleToBytes(double d, byte[] bytes, int off) { - return longToBytes(Double.doubleToLongBits(d), bytes, off); - } - - /** - * Converts primitive float to byte array. - * - * @param f Float to convert. - * @return Array of bytes. - */ - public static byte[] floatToBytes(float f) { - return intToBytes(Float.floatToIntBits(f)); - } - - /** - * Converts primitive float to byte array. - * - * @param f Float to convert. - * @param bytes Array of bytes. - * @param off Offset. - * @return New offset. - */ - public static int floatToBytes(float f, byte[] bytes, int off) { - return intToBytes(Float.floatToIntBits(f), bytes, off); - } - - /** - * Converts primitive {@code long} type to byte array. - * - * @param l Long value. - * @return Array of bytes. - */ - public static byte[] longToBytes(long l) { - return GridClientByteUtils.longToBytes(l); - } - - /** - * Converts primitive {@code long} type to byte array and stores it in specified - * byte array. - * - * @param l Long value. - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Number of bytes overwritten in {@code bytes} array. - */ - public static int longToBytes(long l, byte[] bytes, int off) { - return off + GridClientByteUtils.longToBytes(l, bytes, off); - } - - /** - * Converts primitive {@code int} type to byte array. - * - * @param i Integer value. - * @return Array of bytes. - */ - public static byte[] intToBytes(int i) { - return GridClientByteUtils.intToBytes(i); - } - - /** - * Converts primitive {@code int} type to byte array and stores it in specified - * byte array. - * - * @param i Integer value. - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Number of bytes overwritten in {@code bytes} array. - */ - public static int intToBytes(int i, byte[] bytes, int off) { - return off + GridClientByteUtils.intToBytes(i, bytes, off); - } - - /** - * Converts primitive {@code short} type to byte array. - * - * @param s Short value. - * @return Array of bytes. - */ - public static byte[] shortToBytes(short s) { - return GridClientByteUtils.shortToBytes(s); - } - - /** - * Converts primitive {@code short} type to byte array and stores it in specified - * byte array. - * - * @param s Short value. - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Number of bytes overwritten in {@code bytes} array. - */ - public static int shortToBytes(short s, byte[] bytes, int off) { - return off + GridClientByteUtils.shortToBytes(s, bytes, off); - } - - /** - * Encodes {@link java.util.UUID} into a sequence of bytes using the {@link java.nio.ByteBuffer}, - * storing the result into a new byte array. - * - * @param uuid Unique identifier. - * @param arr Byte array to fill with result. - * @param off Offset in {@code arr}. - * @return Number of bytes overwritten in {@code bytes} array. - */ - public static int uuidToBytes(@Nullable UUID uuid, byte[] arr, int off) { - return off + GridClientByteUtils.uuidToBytes(uuid, arr, off); - } - - /** - * Converts an UUID to byte array. - * - * @param uuid UUID value. - * @return Encoded into byte array {@link java.util.UUID}. - */ - public static byte[] uuidToBytes(@Nullable UUID uuid) { - return GridClientByteUtils.uuidToBytes(uuid); - } - - /** - * Constructs {@code short} from byte array. - * - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Short value. - */ - public static short bytesToShort(byte[] bytes, int off) { - assert bytes != null; - - int bytesCnt = Short.SIZE >> 3; - - if (off + bytesCnt > bytes.length) - // Just use the remainder. - bytesCnt = bytes.length - off; - - short res = 0; - - for (int i = 0; i < bytesCnt; i++) { - int shift = bytesCnt - i - 1 << 3; - - res |= (0xffL & bytes[off++]) << shift; - } - - return res; - } - - /** - * Constructs {@code int} from byte array. - * - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Integer value. - */ - public static int bytesToInt(byte[] bytes, int off) { - assert bytes != null; - - int bytesCnt = Integer.SIZE >> 3; - - if (off + bytesCnt > bytes.length) - // Just use the remainder. - bytesCnt = bytes.length - off; - - int res = 0; - - for (int i = 0; i < bytesCnt; i++) { - int shift = bytesCnt - i - 1 << 3; - - res |= (0xffL & bytes[off++]) << shift; - } - - return res; - } - - /** - * Constructs {@code long} from byte array. - * - * @param bytes Array of bytes. - * @param off Offset in {@code bytes} array. - * @return Long value. - */ - public static long bytesToLong(byte[] bytes, int off) { - assert bytes != null; - - int bytesCnt = Long.SIZE >> 3; - - if (off + bytesCnt > bytes.length) - bytesCnt = bytes.length - off; - - long res = 0; - - for (int i = 0; i < bytesCnt; i++) { - int shift = bytesCnt - i - 1 << 3; - - res |= (0xffL & bytes[off++]) << shift; - } - - return res; - } - - /** - * Reads an {@link UUID} form byte array. - * If given array contains all 0s then {@code null} will be returned. - * - * @param bytes array of bytes. - * @param off Offset in {@code bytes} array. - * @return UUID value or {@code null}. - */ - public static UUID bytesToUuid(byte[] bytes, int off) { - return GridClientByteUtils.bytesToUuid(bytes, off); - } - - /** - * Constructs double from byte array. - * - * @param bytes Byte array. - * @param off Offset in {@code bytes} array. - * @return Double value. - */ - public static double bytesToDouble(byte[] bytes, int off) { - return Double.longBitsToDouble(bytesToLong(bytes, off)); - } - - /** - * Constructs float from byte array. - * - * @param bytes Byte array. - * @param off Offset in {@code bytes} array. - * @return Float value. - */ - public static float bytesToFloat(byte[] bytes, int off) { - return Float.intBitsToFloat(bytesToInt(bytes, off)); - } - - /** - * Compares fragments of byte arrays. - * - * @param a First array. - * @param aOff First array offset. - * @param b Second array. - * @param bOff Second array offset. - * @param len Length of fragments. - * @return {@code true} if fragments are equal, {@code false} otherwise. - */ - public static boolean bytesEqual(byte[] a, int aOff, byte[] b, int bOff, int len) { - if (aOff + len > a.length || bOff + len > b.length) - return false; - else { - for (int i = 0; i < len; i++) - if (a[aOff + i] != b[bOff + i]) - return false; - - return true; - } - } - - /** * Checks for containment of the value in the array. * Both array cells and value may be {@code null}. Two {@code null}s are considered equal. * @@ -4431,9 +3965,9 @@ public abstract class IgniteUtils { public static void igniteUuidToBytes(IgniteUuid uuid, byte[] out, int off) { assert uuid != null; - U.longToBytes(uuid.globalId().getMostSignificantBits(), out, off); - U.longToBytes(uuid.globalId().getLeastSignificantBits(), out, off + 8); - U.longToBytes(uuid.localId(), out, off + 16); + IgniteByteUtils.longToBytes(uuid.globalId().getMostSignificantBits(), out, off); + IgniteByteUtils.longToBytes(uuid.globalId().getLeastSignificantBits(), out, off + 8); + IgniteByteUtils.longToBytes(uuid.localId(), out, off + 16); } /** @@ -4444,70 +3978,14 @@ public abstract class IgniteUtils { * @return GridUuid instance. */ public static IgniteUuid bytesToIgniteUuid(byte[] in, int off) { - long most = U.bytesToLong(in, off); - long least = U.bytesToLong(in, off + 8); - long locId = U.bytesToLong(in, off + 16); + long most = IgniteByteUtils.bytesToLong(in, off); + long least = IgniteByteUtils.bytesToLong(in, off + 8); + long locId = IgniteByteUtils.bytesToLong(in, off + 16); return new IgniteUuid(IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)), locId); } /** - * Writes byte array to output stream accounting for <tt>null</tt> values. - * - * @param out Output stream to write to. - * @param arr Array to write, possibly <tt>null</tt>. - * @throws IOException If write failed. - */ - public static void writeByteArray(DataOutput out, @Nullable byte[] arr) throws IOException { - if (arr == null) - out.writeInt(-1); - else { - out.writeInt(arr.length); - - out.write(arr); - } - } - - /** - * Writes byte array to output stream accounting for <tt>null</tt> values. - * - * @param out Output stream to write to. - * @param arr Array to write, possibly <tt>null</tt>. - * @throws IOException If write failed. - */ - public static void writeByteArray(DataOutput out, @Nullable byte[] arr, int maxLen) throws IOException { - if (arr == null) - out.writeInt(-1); - else { - int len = Math.min(arr.length, maxLen); - - out.writeInt(len); - - out.write(arr, 0, len); - } - } - - /** - * Reads byte array from input stream accounting for <tt>null</tt> values. - * - * @param in Stream to read from. - * @return Read byte array, possibly <tt>null</tt>. - * @throws IOException If read failed. - */ - @Nullable public static byte[] readByteArray(DataInput in) throws IOException { - int len = in.readInt(); - - if (len == -1) - return null; // Value "-1" indicates null. - - byte[] res = new byte[len]; - - in.readFully(res); - - return res; - } - - /** * Writes boolean array to output stream accounting for <tt>null</tt> values. * * @param out Output stream to write to. @@ -4586,39 +4064,6 @@ public abstract class IgniteUtils { } /** - * Reads byte array from given buffers (changing buffer positions). - * - * @param bufs Byte buffers. - * @return Byte array. - */ - public static byte[] readByteArray(ByteBuffer... bufs) { - assert !F.isEmpty(bufs); - - int size = 0; - - for (ByteBuffer buf : bufs) - size += buf.remaining(); - - byte[] res = new byte[size]; - - int off = 0; - - for (ByteBuffer buf : bufs) { - int len = buf.remaining(); - - if (len != 0) { - buf.get(res, off, len); - - off += len; - } - } - - assert off == res.length; - - return res; - } - - /** * Calculates hash code for the given byte buffers contents. Compatible with {@link Arrays#hashCode(byte[])} * with the same content. Does not change buffers positions. * @@ -4893,46 +4338,6 @@ public abstract class IgniteUtils { } /** - * // FIXME: added for DR dataCenterIds, review if it is needed after GG-6879. - * - * @param out Output. - * @param col Set to write. - * @throws IOException If write failed. - */ - public static void writeByteCollection(DataOutput out, Collection<Byte> col) throws IOException { - if (col != null) { - out.writeInt(col.size()); - - for (Byte i : col) - out.writeByte(i); - } - else - out.writeInt(-1); - } - - /** - * // FIXME: added for DR dataCenterIds, review if it is needed after GG-6879. - * - * @param in Input. - * @return Deserialized list. - * @throws IOException If deserialization failed. - */ - @Nullable public static List<Byte> readByteList(DataInput in) throws IOException { - int size = in.readInt(); - - // Check null flag. - if (size == -1) - return null; - - List<Byte> col = new ArrayList<>(size); - - for (int i = 0; i < size; i++) - col.add(in.readByte()); - - return col; - } - - /** * @param in Input. * @return Deserialized set. * @throws IOException If deserialization failed. @@ -8057,45 +7462,6 @@ public abstract class IgniteUtils { } /** - * Zips byte array. - * - * @param input Input bytes. - * @return Zipped byte array. - * @throws IOException If failed. - */ - public static byte[] zipBytes(byte[] input) throws IOException { - return zipBytes(input, 4096); - } - - /** - * Zips byte array. - * - * @param input Input bytes. - * @param initBufSize Initial buffer size. - * @return Zipped byte array. - * @throws IOException If failed. - */ - public static byte[] zipBytes(byte[] input, int initBufSize) throws IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(initBufSize); - - try (ZipOutputStream zos = new ZipOutputStream(bos)) { - ZipEntry entry = new ZipEntry(""); - - try { - entry.setSize(input.length); - - zos.putNextEntry(entry); - - zos.write(input); - } finally { - zos.closeEntry(); - } - } - - return bos.toByteArray(); - } - - /** * @return PID of the current JVM or {@code -1} if it can't be determined. */ public static int jvmPid() { @@ -8619,43 +7985,6 @@ public abstract class IgniteUtils { } /** - * Converts an array of characters representing hexidecimal values into an - * array of bytes of those same values. The returned array will be half the - * length of the passed array, as it takes two characters to represent any - * given byte. An exception is thrown if the passed char array has an odd - * number of elements. - * - * @param data An array of characters containing hexidecimal digits - * @return A byte array containing binary data decoded from - * the supplied char array. - * @throws IgniteCheckedException Thrown if an odd number or illegal of characters is supplied. - */ - public static byte[] decodeHex(char[] data) throws IgniteCheckedException { - - int len = data.length; - - if ((len & 0x01) != 0) - throw new IgniteCheckedException("Odd number of characters."); - - byte[] out = new byte[len >> 1]; - - // Two characters form the hex value. - for (int i = 0, j = 0; j < len; i++) { - int f = toDigit(data[j], j) << 4; - - j++; - - f |= toDigit(data[j], j); - - j++; - - out[i] = (byte)(f & 0xFF); - } - - return out; - } - - /** * Converts a hexadecimal character to an integer. * * @param ch A character to convert to an integer digit http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridConnectionBytesVerifyFilter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridConnectionBytesVerifyFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridConnectionBytesVerifyFilter.java index 8bee151..a01683d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridConnectionBytesVerifyFilter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridConnectionBytesVerifyFilter.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.internal.*; import java.nio.*; @@ -104,7 +105,7 @@ public class GridConnectionBytesVerifyFilter extends GridNioFilterAdapter { ses.addMeta(MAGIC_META_KEY, cnt + magicRead); ses.addMeta(MAGIC_BUF_KEY, magicBuf); } - else if (U.bytesEqual(magicBuf, 0, U.IGNITE_HEADER, 0, U.IGNITE_HEADER.length)) { + else if (IgniteByteUtils.bytesEqual(magicBuf, 0, U.IGNITE_HEADER, 0, U.IGNITE_HEADER.length)) { // Magic bytes read and equal to IGNITE_HEADER. ses.removeMeta(MAGIC_BUF_KEY); ses.addMeta(MAGIC_META_KEY, U.IGNITE_HEADER.length); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java index 72c20f8..b529929 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpCommunicationClient.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.util.nio; import org.apache.ignite.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.plugin.extensions.communication.*; @@ -520,7 +521,7 @@ public class GridTcpCommunicationClient extends GridAbstractCommunicationClient assert off == 0; assert resBuf.length >= resOff + len + 4; - U.intToBytes(len, resBuf, resOff); + IgniteByteUtils.intToBytes(len, resBuf, resOff); U.arrayCopy(b, off, resBuf, resOff + 4, len); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java index 348ed33..e8951a1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java @@ -25,6 +25,7 @@ import org.apache.ignite.cache.eviction.random.*; import org.apache.ignite.cluster.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.processors.igfs.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.visor.event.*; @@ -575,7 +576,7 @@ public class VisorTaskUtils { boolean zipped = buf.length > 512; - return new VisorFileBlock(file.getPath(), pos, fSz, fLastModified, zipped, zipped ? U.zipBytes(buf) : buf); + return new VisorFileBlock(file.getPath(), pos, fSz, fLastModified, zipped, zipped ? IgniteByteUtils.zipBytes(buf) : buf); } } finally { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java index e5f865d..22e08f8 100644 --- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java +++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java @@ -18,6 +18,7 @@ package org.apache.ignite.lang; import org.apache.ignite.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; @@ -220,7 +221,7 @@ public class IgniteProductVersion implements Comparable<IgniteProductVersion>, E out.writeByte(minor); out.writeByte(maintenance); out.writeLong(revTs); - U.writeByteArray(out, revHash); + IgniteByteUtils.writeByteArray(out, revHash); } /** {@inheritDoc} */ @@ -229,7 +230,7 @@ public class IgniteProductVersion implements Comparable<IgniteProductVersion>, E minor = in.readByte(); maintenance = in.readByte(); revTs = in.readLong(); - revHash = U.readByteArray(in); + revHash = IgniteByteUtils.readByteArray(in); } /** {@inheritDoc} */ @@ -277,7 +278,7 @@ public class IgniteProductVersion implements Comparable<IgniteProductVersion>, E byte[] revHash = null; if (match.group(9) != null) - revHash = U.decodeHex(match.group(10).toCharArray()); + revHash = IgniteByteUtils.decodeHex(match.group(10).toCharArray()); return new IgniteProductVersion(major, minor, maintenance, stage, revTs, revHash); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index ad9f688..c3c2b1f 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -305,7 +305,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter assert ses.accepted(); if (msg instanceof NodeIdMessage) - sndId = U.bytesToUuid(((NodeIdMessage)msg).nodeIdBytes, 0); + sndId = IgniteByteUtils.bytesToUuid(((NodeIdMessage) msg).nodeIdBytes, 0); else { assert msg instanceof HandshakeMessage : msg; @@ -2196,7 +2196,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter i += read; } - UUID rmtNodeId0 = U.bytesToUuid(buf.array(), 1); + UUID rmtNodeId0 = IgniteByteUtils.bytesToUuid(buf.array(), 1); if (!rmtNodeId.equals(rmtNodeId0)) throw new IgniteCheckedException("Remote node ID is not as expected [expected=" + rmtNodeId + @@ -2950,7 +2950,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter } // First 4 bytes are for length. - UUID id = U.bytesToUuid(b, 1); + UUID id = IgniteByteUtils.bytesToUuid(b, 1); if (!rmtNodeId.equals(id)) throw new IgniteCheckedException("Remote node ID is not as expected [expected=" + rmtNodeId + @@ -3049,7 +3049,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter buf.put(HANDSHAKE_MSG_TYPE); - byte[] bytes = U.uuidToBytes(nodeId); + byte[] bytes = IgniteByteUtils.uuidToBytes(nodeId); assert bytes.length == 16 : bytes.length; @@ -3071,7 +3071,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter buf.get(nodeIdBytes); - nodeId = U.bytesToUuid(nodeIdBytes, 0); + nodeId = IgniteByteUtils.bytesToUuid(nodeIdBytes, 0); rcvCnt = buf.getLong(); @@ -3189,7 +3189,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter * @param nodeId Node ID. */ private NodeIdMessage(UUID nodeId) { - nodeIdBytes = U.uuidToBytes(nodeId); + nodeIdBytes = IgniteByteUtils.uuidToBytes(nodeId); nodeIdBytesWithType = new byte[nodeIdBytes.length + 1]; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java index 7501a66..3d2b4dc 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java @@ -4534,7 +4534,7 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov } } - if (!U.bytesEqual(buf, 0, U.IGNITE_HEADER, 0, 4)) { + if (!IgniteByteUtils.bytesEqual(buf, 0, U.IGNITE_HEADER, 0, 4)) { if (log.isDebugEnabled()) log.debug("Unknown connection detected (is some other software connecting to " + "this Ignite port?) " + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java index dfb30b7..9ea562a 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java @@ -19,6 +19,7 @@ package org.apache.ignite.spi.discovery.tcp.internal; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; @@ -401,7 +402,7 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements Cluste ClusterMetricsSnapshot.serialize(mtr, 0, metrics); } - U.writeByteArray(out, mtr); + IgniteByteUtils.writeByteArray(out, mtr); out.writeLong(order); out.writeLong(intOrder); @@ -422,7 +423,7 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements Cluste consistentId = U.consistentId(addrs, discPort); - byte[] mtr = U.readByteArray(in); + byte[] mtr = IgniteByteUtils.readByteArray(in); if (mtr != null) metrics = ClusterMetricsSnapshot.deserialize(mtr, 0); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java index 3ff4157..49924e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java @@ -19,6 +19,7 @@ package org.apache.ignite.spi.discovery.tcp.ipfinder.multicast; import org.apache.ignite.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -437,7 +438,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder { byte[] data = resPckt.getData(); - if (!U.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length)) { + if (!IgniteByteUtils.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length)) { U.error(log, "Failed to verify message header."); continue; @@ -557,7 +558,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder { * @throws IgniteCheckedException If unmarshalling failed. */ private AddressResponse(byte[] data) throws IgniteCheckedException { - assert U.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length); + assert IgniteByteUtils.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length); this.data = data; @@ -705,7 +706,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder { sock.receive(pckt); - if (!U.bytesEqual(U.IGNITE_HEADER, 0, reqData, 0, U.IGNITE_HEADER.length)) { + if (!IgniteByteUtils.bytesEqual(U.IGNITE_HEADER, 0, reqData, 0, U.IGNITE_HEADER.length)) { U.error(log, "Failed to verify message header."); continue; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAuthFailedMessage.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAuthFailedMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAuthFailedMessage.java index 2d20be9..a2aa024 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAuthFailedMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAuthFailedMessage.java @@ -17,6 +17,7 @@ package org.apache.ignite.spi.discovery.tcp.messages; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.internal.*; import java.io.*; @@ -63,14 +64,14 @@ public class TcpDiscoveryAuthFailedMessage extends TcpDiscoveryAbstractMessage { @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); - U.writeByteArray(out, addr.getAddress()); + IgniteByteUtils.writeByteArray(out, addr.getAddress()); } /** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); - addr = InetAddress.getByAddress(U.readByteArray(in)); + addr = InetAddress.getByAddress(IgniteByteUtils.readByteArray(in)); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java index 65eea9f..834ccc0 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryHeartbeatMessage.java @@ -19,6 +19,7 @@ package org.apache.ignite.spi.discovery.tcp.messages; import org.apache.ignite.cluster.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -215,8 +216,8 @@ public class TcpDiscoveryHeartbeatMessage extends TcpDiscoveryAbstractMessage { byte[] buf = new byte[16 + ClusterMetricsSnapshot.METRICS_SIZE]; - U.longToBytes(nodeId.getMostSignificantBits(), buf, 0); - U.longToBytes(nodeId.getLeastSignificantBits(), buf, 8); + IgniteByteUtils.longToBytes(nodeId.getMostSignificantBits(), buf, 0); + IgniteByteUtils.longToBytes(nodeId.getLeastSignificantBits(), buf, 8); ClusterMetricsSnapshot.serialize(buf, 16, metrics); @@ -264,7 +265,7 @@ public class TcpDiscoveryHeartbeatMessage extends TcpDiscoveryAbstractMessage { public Collection<T2<UUID, ClusterMetrics>> clientMetrics() { return F.viewReadOnly(clientMetrics, new C1<byte[], T2<UUID, ClusterMetrics>>() { @Override public T2<UUID, ClusterMetrics> apply(byte[] bytes) { - UUID nodeId = new UUID(U.bytesToLong(bytes, 0), U.bytesToLong(bytes, 8)); + UUID nodeId = new UUID(IgniteByteUtils.bytesToLong(bytes, 0), IgniteByteUtils.bytesToLong(bytes, 8)); return new T2<>(nodeId, ClusterMetricsSnapshot.deserialize(bytes, 16)); } @@ -287,19 +288,19 @@ public class TcpDiscoveryHeartbeatMessage extends TcpDiscoveryAbstractMessage { /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { - U.writeByteArray(out, metrics); + IgniteByteUtils.writeByteArray(out, metrics); out.writeInt(clientMetrics != null ? clientMetrics.size() : -1); if (clientMetrics != null) { for (byte[] arr : clientMetrics) - U.writeByteArray(out, arr); + IgniteByteUtils.writeByteArray(out, arr); } } /** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - metrics = U.readByteArray(in); + metrics = IgniteByteUtils.readByteArray(in); int clientMetricsSize = in.readInt(); @@ -307,7 +308,7 @@ public class TcpDiscoveryHeartbeatMessage extends TcpDiscoveryAbstractMessage { clientMetrics = new ArrayList<>(clientMetricsSize); for (int i = 0; i < clientMetricsSize; i++) - clientMetrics.add(U.readByteArray(in)); + clientMetrics.add(IgniteByteUtils.readByteArray(in)); } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDataManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDataManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDataManagerSelfTest.java index 2af01bf..19cbfa1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDataManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDataManagerSelfTest.java @@ -24,8 +24,8 @@ import org.apache.ignite.igfs.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.transactions.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; @@ -284,7 +284,7 @@ public class IgfsDataManagerSelfTest extends IgfsCommonAbstractTest { assert txs.isEmpty() : "Incomplete transactions: " + txs; } - byte[] concat = U.join(remainder, data, remainder2); + byte[] concat = IgniteByteUtils.join(remainder, data, remainder2); // Validate data stored in cache. for (int pos = 0, block = 0; pos < info.length(); block++) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java index 5fefc48..5436c59 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java @@ -121,7 +121,7 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { */ public void testByteArray2String() throws Exception { assertEquals("{0x0A,0x14,0x1E,0x28,0x32,0x3C,0x46,0x50,0x5A}", - U.byteArray2String(new byte[] {10, 20, 30, 40, 50, 60, 70, 80, 90}, "0x%02X", ",0x%02X")); + IgniteByteUtils.byteArray2String(new byte[]{10, 20, 30, 40, 50, 60, 70, 80, 90}, "0x%02X", ",0x%02X")); } /** @@ -474,7 +474,7 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { for (int i = 0; i < 100; i++) { UUID id = UUID.randomUUID(); - byte[] bytes = IgniteUtils.uuidToBytes(id); + byte[] bytes = IgniteByteUtils.uuidToBytes(id); BigInteger n = new BigInteger(bytes); assert n.shiftRight(Long.SIZE).longValue() == id.getMostSignificantBits(); @@ -487,8 +487,8 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { */ @SuppressWarnings("ZeroLengthArrayAllocation") public void testReadByteArray() { - assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0)))); - assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.allocate(0)))); + assertTrue(Arrays.equals(new byte[0], IgniteByteUtils.readByteArray(ByteBuffer.allocate(0)))); + assertTrue(Arrays.equals(new byte[0], IgniteByteUtils.readByteArray(ByteBuffer.allocate(0), ByteBuffer.allocate(0)))); Random rnd = new Random(); @@ -496,9 +496,9 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { rnd.nextBytes(bytes); - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes)))); - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes), ByteBuffer.allocate(0)))); - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.wrap(bytes)))); + assertTrue(Arrays.equals(bytes, IgniteByteUtils.readByteArray(ByteBuffer.wrap(bytes)))); + assertTrue(Arrays.equals(bytes, IgniteByteUtils.readByteArray(ByteBuffer.wrap(bytes), ByteBuffer.allocate(0)))); + assertTrue(Arrays.equals(bytes, IgniteByteUtils.readByteArray(ByteBuffer.allocate(0), ByteBuffer.wrap(bytes)))); for (int i = 0; i < 1000; i++) { int n = rnd.nextInt(100); @@ -519,7 +519,7 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { bufs[bufs.length - 1] = (ByteBuffer)ByteBuffer.wrap(bytes).position(x).limit(n); - assertTrue(Arrays.equals(bytes, U.readByteArray(bufs))); + assertTrue(Arrays.equals(bytes, IgniteByteUtils.readByteArray(bufs))); } } @@ -544,7 +544,7 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest { bufs[j] = ByteBuffer.wrap(bytes); } - assertEquals(U.hashCode(bufs), Arrays.hashCode(U.readByteArray(bufs))); + assertEquals(U.hashCode(bufs), Arrays.hashCode(IgniteByteUtils.readByteArray(bufs))); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioSelfTest.java index 83729fc..f6157ad 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridNioSelfTest.java @@ -1144,7 +1144,7 @@ public class GridNioSelfTest extends GridCommonAbstractTest { private byte[] createMessageWithSize() { byte[] msg = new byte[MSG_SIZE]; - U.intToBytes(MSG_SIZE - 4, msg, 0); + IgniteByteUtils.intToBytes(MSG_SIZE - 4, msg, 0); return msg; } @@ -1329,7 +1329,7 @@ public class GridNioSelfTest extends GridCommonAbstractTest { * @throws IOException If send failed. */ public void sendMessage(byte[] data, int len) throws IOException { - out.write(U.intToBytes(len)); + out.write(IgniteByteUtils.intToBytes(len)); out.write(data, 0, len); } @@ -1353,7 +1353,7 @@ public class GridNioSelfTest extends GridCommonAbstractTest { idx += read; } - int len = U.bytesToInt(prefix, 0); + int len = IgniteByteUtils.bytesToInt(prefix, 0); byte[] res = new byte[len]; idx = 0; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridRoundTripTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridRoundTripTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridRoundTripTest.java index bd0a652..69efd29 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridRoundTripTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/GridRoundTripTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.util.nio; import junit.framework.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.internal.*; import java.io.*; @@ -180,7 +181,7 @@ public class GridRoundTripTest extends TestCase { tmp.write(symbol); } - int length = U.bytesToInt(tmp.toByteArray(), 0); + int length = IgniteByteUtils.bytesToInt(tmp.toByteArray(), 0); tmp.reset(); @@ -205,7 +206,7 @@ public class GridRoundTripTest extends TestCase { * @throws IOException If error occurs. */ private static void writeMessage(OutputStream out, byte[] msg) throws IOException { - out.write(U.intToBytes(msg.length)); + out.write(IgniteByteUtils.intToBytes(msg.length)); out.write(msg); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java index 8ec97f9..d59282c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/offheap/GridOffHeapMapAbstractSelfTest.java @@ -19,10 +19,10 @@ package org.apache.ignite.internal.util.offheap; import org.apache.ignite.*; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.offheap.unsafe.*; import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.testframework.junits.common.*; import org.jdk8.backport.*; @@ -699,7 +699,7 @@ public abstract class GridOffHeapMapAbstractSelfTest extends GridCommonAbstractT int valSize = rnd.nextInt(50) + 1; for (int i = 0; i < size; i++) - map.put(i, U.intToBytes(i), new byte[valSize]); + map.put(i, IgniteByteUtils.intToBytes(i), new byte[valSize]); } } catch (InterruptedException e) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/lang/GridByteArrayListSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridByteArrayListSelfTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridByteArrayListSelfTest.java index c4c3280..25396b9 100644 --- a/modules/core/src/test/java/org/apache/ignite/lang/GridByteArrayListSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/lang/GridByteArrayListSelfTest.java @@ -91,7 +91,7 @@ public class GridByteArrayListSelfTest extends GridCommonAbstractTest { assert list.size() == 4; - assert Arrays.equals(list.array(), U.intToBytes(num)); + assert Arrays.equals(list.array(), IgniteByteUtils.intToBytes(num)); int num2 = 2; @@ -105,8 +105,8 @@ public class GridByteArrayListSelfTest extends GridCommonAbstractTest { byte[] arr2 = new byte[8]; - U.arrayCopy(U.intToBytes(num), 0, arr2, 0, 4); - U.arrayCopy(U.intToBytes(num3), 0, arr2, 4, 4); + U.arrayCopy(IgniteByteUtils.intToBytes(num), 0, arr2, 0, 4); + U.arrayCopy(IgniteByteUtils.intToBytes(num3), 0, arr2, 4, 4); assert Arrays.equals(list.array(), arr2); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java index 22ee3c3..9fd952f 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java @@ -17,6 +17,7 @@ package org.apache.ignite.loadtests.communication; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.plugin.extensions.communication.*; @@ -95,7 +96,7 @@ class GridTestMessage implements Message, Externalizable { out.writeLong(field1); out.writeLong(field2); U.writeString(out, str); - U.writeByteArray(out, bytes); + IgniteByteUtils.writeByteArray(out, bytes); } /** {@inheritDoc} */ @@ -104,7 +105,7 @@ class GridTestMessage implements Message, Externalizable { field1 = in.readLong(); field2 = in.readLong(); str = U.readString(in); - bytes = U.readByteArray(in); + bytes = IgniteByteUtils.readByteArray(in); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java index ceabb18..598c278 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java @@ -18,8 +18,8 @@ package org.apache.ignite.spi.swapspace.file; import org.apache.ignite.internal.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.swapspace.*; @@ -103,7 +103,7 @@ public class GridFileSwapSpaceSpiSelfTest extends GridSwapSpaceSpiAbstractSelfTe * @return Swap key. */ private SwapKey key(int i) { - return new SwapKey(i, i % 11, U.intToBytes(i)); + return new SwapKey(i, i % 11, IgniteByteUtils.intToBytes(i)); } /** @@ -339,7 +339,7 @@ public class GridFileSwapSpaceSpiSelfTest extends GridSwapSpaceSpiAbstractSelfTe while (iter.hasNext()) { Map.Entry<byte[], byte[]> entry = iter.next(); - hash1 += U.bytesToInt(entry.getKey(), 0) * Arrays.hashCode(entry.getValue()); + hash1 += IgniteByteUtils.bytesToInt(entry.getKey(), 0) * Arrays.hashCode(entry.getValue()); cnt++; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/hadoop/src/main/java/org/apache/ignite/internal/igfs/hadoop/IgfsHadoopIpcIo.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/igfs/hadoop/IgfsHadoopIpcIo.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/igfs/hadoop/IgfsHadoopIpcIo.java index d07f34d..e159c9d 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/internal/igfs/hadoop/IgfsHadoopIpcIo.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/igfs/hadoop/IgfsHadoopIpcIo.java @@ -397,8 +397,8 @@ public class IgfsHadoopIpcIo implements IgfsHadoopIo { byte[] hdr = IgfsMarshaller.createHeader(-1, IgfsIpcCommand.WRITE_BLOCK); - U.longToBytes(req.streamId(), hdr, 12); - U.intToBytes(req.length(), hdr, 20); + IgniteByteUtils.longToBytes(req.streamId(), hdr, 12); + IgniteByteUtils.intToBytes(req.length(), hdr, 20); synchronized (this) { out.write(hdr); @@ -479,7 +479,7 @@ public class IgfsHadoopIpcIo implements IgfsHadoopIo { while (!Thread.currentThread().isInterrupted()) { dis.readFully(hdr); - long reqId = U.bytesToLong(hdr, 0); + long reqId = IgniteByteUtils.bytesToLong(hdr, 0); // We don't wait for write responses, therefore reqId is -1. if (reqId == -1) { @@ -513,7 +513,7 @@ public class IgfsHadoopIpcIo implements IgfsHadoopIo { } else { try { - IgfsIpcCommand cmd = IgfsIpcCommand.valueOf(U.bytesToInt(hdr, 8)); + IgfsIpcCommand cmd = IgfsIpcCommand.valueOf(IgniteByteUtils.bytesToInt(hdr, 8)); if (log.isDebugEnabled()) log.debug("Received IGFS response [reqId=" + reqId + ", cmd=" + cmd + ']'); @@ -534,7 +534,7 @@ public class IgfsHadoopIpcIo implements IgfsHadoopIo { IgfsControlResponse.throwError(errCode, errMsg); } - int blockLen = U.bytesToInt(msgHdr, 5); + int blockLen = IgniteByteUtils.bytesToInt(msgHdr, 5); int readLen = Math.min(blockLen, fut.outputLength()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/GridHadoopShuffleMessage.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/GridHadoopShuffleMessage.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/GridHadoopShuffleMessage.java index f68ec7e..8b25836 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/GridHadoopShuffleMessage.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/GridHadoopShuffleMessage.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.hadoop.shuffle; import org.apache.ignite.*; import org.apache.ignite.internal.processors.hadoop.*; import org.apache.ignite.internal.processors.hadoop.message.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.tostring.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -201,7 +202,7 @@ public class GridHadoopShuffleMessage implements GridHadoopMessage { out.writeLong(msgId); out.writeInt(reducer); out.writeInt(off); - U.writeByteArray(out, buf); + IgniteByteUtils.writeByteArray(out, buf); } /** {@inheritDoc} */ @@ -212,7 +213,7 @@ public class GridHadoopShuffleMessage implements GridHadoopMessage { msgId = in.readLong(); reducer = in.readInt(); off = in.readInt(); - buf = U.readByteArray(in); + buf = IgniteByteUtils.readByteArray(in); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/GridHadoopSplitWrapper.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/GridHadoopSplitWrapper.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/GridHadoopSplitWrapper.java index 791f90b..4129e58 100644 --- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/GridHadoopSplitWrapper.java +++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/v2/GridHadoopSplitWrapper.java @@ -18,7 +18,7 @@ package org.apache.ignite.internal.processors.hadoop.v2; import org.apache.ignite.internal.processors.hadoop.*; -import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.internal.util.*; import java.io.*; @@ -73,7 +73,7 @@ public class GridHadoopSplitWrapper extends GridHadoopInputSplit { out.writeInt(id); out.writeUTF(clsName); - U.writeByteArray(out, bytes); + IgniteByteUtils.writeByteArray(out, bytes); } /** @@ -96,7 +96,7 @@ public class GridHadoopSplitWrapper extends GridHadoopInputSplit { id = in.readInt(); clsName = in.readUTF(); - bytes = U.readByteArray(in); + bytes = IgniteByteUtils.readByteArray(in); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c1a7df/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java ---------------------------------------------------------------------- diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java index 0807669..5a0a0f2 100644 --- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java +++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java @@ -22,6 +22,7 @@ import net.sf.json.processors.*; import org.apache.ignite.*; import org.apache.ignite.internal.processors.rest.*; import org.apache.ignite.internal.processors.rest.request.*; +import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; @@ -475,7 +476,7 @@ public class GridJettyRestHandler extends AbstractHandler { try { if (sesTokStr != null) - restReq.sessionToken(U.hexString2ByteArray(sesTokStr)); + restReq.sessionToken(IgniteByteUtils.hexString2ByteArray(sesTokStr)); } catch (IllegalArgumentException ignored) { // Ignore invalid session token.