This is an automated email from the ASF dual-hosted git repository.

nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 08e3e46f8e3 [MINOR] Move readString, writeString to CommonUtils 
(#12280)
08e3e46f8e3 is described below

commit 08e3e46f8e3502bc79c8786f9fac25cd4ee142bf
Author: Nikolay <[email protected]>
AuthorDate: Wed Aug 20 10:01:29 2025 +0300

    [MINOR] Move readString, writeString to CommonUtils (#12280)
---
 .../org/apache/ignite/marshaller/Marshallers.java  |  51 ++++
 .../apache/ignite/internal/util/CommonUtils.java   | 239 +++++++++++++++++++
 .../internal/binary/BinaryClassDescriptor.java     |   5 +-
 .../internal/binary/BinaryEnumObjectImpl.java      |   4 +-
 .../ignite/internal/binary/BinaryMetadata.java     |  17 +-
 .../ignite/internal/binary/BinaryReaderExImpl.java |   5 +-
 .../apache/ignite/internal/binary/BinaryUtils.java |   3 +-
 .../ignite/internal/binary/BinaryWriterExImpl.java |   9 +-
 .../apache/ignite/internal/util/IgniteUtils.java   | 262 +--------------------
 9 files changed, 313 insertions(+), 282 deletions(-)

diff --git 
a/modules/binary/api/src/main/java/org/apache/ignite/marshaller/Marshallers.java
 
b/modules/binary/api/src/main/java/org/apache/ignite/marshaller/Marshallers.java
index d590e1aaf8d..7323669e822 100644
--- 
a/modules/binary/api/src/main/java/org/apache/ignite/marshaller/Marshallers.java
+++ 
b/modules/binary/api/src/main/java/org/apache/ignite/marshaller/Marshallers.java
@@ -17,8 +17,10 @@
 
 package org.apache.ignite.marshaller;
 
+import java.io.OutputStream;
 import java.io.Serializable;
 import java.util.Iterator;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCommonsSystemProperties;
 import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
 import org.apache.ignite.internal.util.CommonUtils;
@@ -82,4 +84,53 @@ public class Marshallers {
     public static OptimizedMarshaller optimized(boolean requireSer) {
         return factory.optimized(requireSer);
     }
+
+    /**
+     * Marshals object to byte array.
+     * <p/>
+     * This method wraps marshaller invocations and guaranty throws {@link 
IgniteCheckedException} in fail case.
+     *
+     * @param marsh Marshaller.
+     * @param obj Object to marshal.
+     * @return Byte array.
+     * @throws IgniteCheckedException If marshalling failed.
+     */
+    public static byte[] marshal(Marshaller marsh, Object obj) throws 
IgniteCheckedException {
+        assert marsh != null;
+
+        try {
+            return marsh.marshal(obj);
+        }
+        catch (IgniteCheckedException e) {
+            throw e;
+        }
+        catch (Exception e) {
+            throw new IgniteCheckedException(e);
+        }
+    }
+
+    /**
+     * Marshals object to byte array.
+     * <p/>
+     * This method wraps marshaller invocations and guaranty throws {@link 
IgniteCheckedException} in fail case.
+     *
+     * @param marsh Marshaller.
+     * @param obj Object to marshal.
+     * @param out Output stream.
+     * @throws IgniteCheckedException If marshalling failed.
+     */
+    public static void marshal(Marshaller marsh, @Nullable Object obj, 
OutputStream out)
+        throws IgniteCheckedException {
+        assert marsh != null;
+
+        try {
+            marsh.marshal(obj, out);
+        }
+        catch (IgniteCheckedException e) {
+            throw e;
+        }
+        catch (Exception e) {
+            throw new IgniteCheckedException(e);
+        }
+    }
 }
diff --git 
a/modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java
 
b/modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java
index 891cdddc7a0..77612e671a2 100644
--- 
a/modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java
+++ 
b/modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java
@@ -22,6 +22,7 @@ import java.io.DataOutput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.UTFDataFormatException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -63,10 +64,21 @@ import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.jetbrains.annotations.Nullable;
 
+import static java.util.Objects.isNull;
+
 /**
  * Collection of utility methods used in 'ignite-commons' and throughout the 
system.
  */
 public abstract class CommonUtils {
+    /** */
+    public static final long KB = 1024L;
+
+    /** */
+    public static final long MB = 1024L * 1024;
+
+    /** */
+    public static final long GB = 1024L * 1024 * 1024;
+
     /** Dev only logging disabled. */
     private static final boolean devOnlyLogDisabled =
         
IgniteCommonsSystemProperties.getBoolean(IgniteCommonsSystemProperties.IGNITE_DEV_ONLY_LOGGING_DISABLED);
@@ -1347,6 +1359,233 @@ public abstract class CommonUtils {
         return s.startsWith("java.") || s.startsWith("javax.");
     }
 
+    /**
+     * Finds a non-static and non-abstract method from the class it parents.
+     *
+     * Method.getMethod() does not return non-public method.
+     *
+     * @param cls Target class.
+     * @param name Name of the method.
+     * @param paramTypes Method parameters.
+     * @return Method or {@code null}.
+     */
+    @Nullable public static Method findInheritableMethod(Class<?> cls, String 
name, Class<?>... paramTypes) {
+        Method mtd = null;
+
+        Class<?> cls0 = cls;
+
+        while (cls0 != null) {
+            try {
+                mtd = cls0.getDeclaredMethod(name, paramTypes);
+
+                break;
+            }
+            catch (NoSuchMethodException e) {
+                cls0 = cls0.getSuperclass();
+            }
+        }
+
+        if (mtd == null)
+            return null;
+
+        mtd.setAccessible(true);
+
+        int mods = mtd.getModifiers();
+
+        if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0)
+            return null;
+        else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0)
+            return mtd;
+        else if ((mods & Modifier.PRIVATE) != 0)
+            return cls == cls0 ? mtd : null;
+        else {
+            ClassLoader clsLdr = cls.getClassLoader();
+
+            ClassLoader clsLdr0 = cls0.getClassLoader();
+
+            return clsLdr == clsLdr0 && 
packageName(cls).equals(packageName(cls0)) ? mtd : null;
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @return Package name.
+     */
+    public static String packageName(Class<?> cls) {
+        Package pkg = cls.getPackage();
+
+        return pkg == null ? "" : pkg.getName();
+    }
+
+    /**
+     * Writes string to output stream accounting for {@code null} values.
+     * <p>
+     * Limitation for max string lenght of <code>65535</code> bytes is caused 
by {@link DataOutput#writeUTF}
+     * used under the hood to perform an actual write.
+     * </p>
+     * <p>
+     * If longer string is passes a {@link UTFDataFormatException} exception 
will be thrown.
+     * </p>
+     * <p>
+     * To write longer strings use {@link #writeLongString(DataOutput, 
String)} writes string as is converting it into binary array of UTF-8
+     * encoded characters.
+     * To read the value back {@link #readLongString(DataInput)} should be 
used.
+     * </p>
+     *
+     * @param out Output stream to write to.
+     * @param s String to write, possibly {@code null}.
+     * @throws IOException If write failed.
+     */
+    public static void writeString(DataOutput out, String s) throws 
IOException {
+        // Write null flag.
+        out.writeBoolean(s == null);
+
+        if (s != null)
+            out.writeUTF(s);
+    }
+
+    /**
+     * Reads string from input stream accounting for {@code null} values.
+     *
+     * Method enables to read strings shorter than <code>65535</code> bytes in 
UTF-8 otherwise an exception will be thrown.
+     *
+     * Strings written by {@link #writeString(DataOutput, String)} can be read 
by this method.
+     *
+     * @see #writeString(DataOutput, String) for more information about 
writing strings.
+     *
+     * @param in Stream to read from.
+     * @return Read string, possibly {@code null}.
+     * @throws IOException If read failed.
+     */
+    @Nullable public static String readString(DataInput in) throws IOException 
{
+        // If value is not null, then read it. Otherwise return null.
+        return !in.readBoolean() ? in.readUTF() : null;
+    }
+
+    /**
+     * Writes string to output stream accounting for {@code null} values. <br/>
+     *
+     * This method can write string of any length, limit of <code>65535</code> 
is not applied.
+     *
+     * @param out Output stream to write to.
+     * @param s String to write, possibly {@code null}.
+     * @throws IOException If write failed.
+     */
+    public static void writeLongString(DataOutput out, @Nullable String s) 
throws IOException {
+        // Write null flag.
+        out.writeBoolean(isNull(s));
+
+        if (isNull(s))
+            return;
+
+        int sLen = s.length();
+
+        // Write string length.
+        out.writeInt(sLen);
+
+        // Write byte array.
+        for (int i = 0; i < sLen; i++) {
+            char c = s.charAt(i);
+            int utfBytes = utfBytes(c);
+
+            if (utfBytes == 1)
+                out.writeByte((byte)c);
+            else if (utfBytes == 3) {
+                out.writeByte((byte)(0xE0 | (c >> 12) & 0x0F));
+                out.writeByte((byte)(0x80 | (c >> 6) & 0x3F));
+                out.writeByte((byte)(0x80 | (c & 0x3F)));
+            }
+            else {
+                out.writeByte((byte)(0xC0 | ((c >> 6) & 0x1F)));
+                out.writeByte((byte)(0x80 | (c & 0x3F)));
+            }
+        }
+    }
+
+    /**
+     * Reads string from input stream accounting for {@code null} values. <br/>
+     *
+     * This method can read string of any length, limit of <code>65535</code> 
is not applied.
+     *
+     * @param in Stream to read from.
+     * @return Read string, possibly {@code null}.
+     * @throws IOException If read failed.
+     */
+    @Nullable public static String readLongString(DataInput in) throws 
IOException {
+        // Check null value.
+        if (in.readBoolean())
+            return null;
+
+        // Read string length.
+        int sLen = in.readInt();
+
+        StringBuilder strBuilder = new StringBuilder(sLen);
+
+        // Read byte array.
+        for (int i = 0, b0, b1, b2; i < sLen; i++) {
+            b0 = in.readByte() & 0xff;
+
+            switch (b0 >> 4) {
+                case 0:
+                case 1:
+                case 2:
+                case 3:
+                case 4:
+                case 5:
+                case 6:
+                case 7:   // 1 byte format: 0xxxxxxx
+                    strBuilder.append((char)b0);
+                    break;
+
+                case 12:
+                case 13:  // 2 byte format: 110xxxxx 10xxxxxx
+                    b1 = in.readByte();
+
+                    if ((b1 & 0xC0) != 0x80)
+                        throw new UTFDataFormatException();
+
+                    strBuilder.append((char)(((b0 & 0x1F) << 6) | (b1 & 
0x3F)));
+                    break;
+
+                case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
+                    b1 = in.readByte();
+                    b2 = in.readByte();
+
+                    if ((b1 & 0xC0) != 0x80 || (b2 & 0xC0) != 0x80)
+                        throw new UTFDataFormatException();
+
+                    strBuilder.append((char)(((b0 & 0x0F) << 12) | ((b1 & 
0x3F) << 6) | (b2 & 0x3F)));
+                    break;
+
+                default:  // 10xx xxxx, 1111 xxxx
+                    throw new UTFDataFormatException();
+            }
+        }
+
+        return strBuilder.toString();
+    }
+
+    /**
+     * Get number of bytes for {@link DataOutput#writeUTF},
+     * depending on character: <br/>
+     *
+     * One byte - If a character <code>c</code> is in the range
+     * <code>&#92;u0001</code> through <code>&#92;u007f</code>.<br/>
+     *
+     * Two bytes - If a character <code>c</code> is <code>&#92;u0000</code> or
+     * is in the range <code>&#92;u0080</code> through <code>&#92;u07ff</code>.
+     * <br/>
+     *
+     * Three bytes - If a character <code>c</code> is in the range
+     * <code>&#92;u0800</code> through <code>uffff</code>.
+     *
+     * @param c Character.
+     * @return Number of bytes.
+     */
+    public static int utfBytes(char c) {
+        return (c >= 0x0001 && c <= 0x007F) ? 1 : (c > 0x07FF) ? 3 : 2;
+    }
+
     /**
      * Calculate a hashCode for an array.
      *
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 28470c3bd2b..ce3a05dd8d4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -51,7 +51,6 @@ import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.MarshallerExclusions;
 import org.jetbrains.annotations.Nullable;
 
@@ -402,9 +401,9 @@ class BinaryClassDescriptor {
         Method writeReplaceMthd;
 
         if (mode == BinaryWriteMode.BINARY || mode == BinaryWriteMode.OBJECT) {
-            readResolveMtd = U.findInheritableMethod(cls, "readResolve");
+            readResolveMtd = CommonUtils.findInheritableMethod(cls, 
"readResolve");
 
-            writeReplaceMthd = U.findInheritableMethod(cls, "writeReplace");
+            writeReplaceMthd = CommonUtils.findInheritableMethod(cls, 
"writeReplace");
         }
         else {
             readResolveMtd = null;
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index 6814a9e63ff..82db49e8383 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -333,7 +333,7 @@ class BinaryEnumObjectImpl implements BinaryObjectEx, 
Externalizable, CacheObjec
         if (valBytes != null)
             return valBytes;
 
-        valBytes = U.marshal(ctx.marshaller(), this);
+        valBytes = Marshallers.marshal(ctx.marshaller(), this);
 
         return valBytes;
     }
@@ -470,7 +470,7 @@ class BinaryEnumObjectImpl implements BinaryObjectEx, 
Externalizable, CacheObjec
     @Override public int size() {
         if (valBytes == null) {
             try {
-                valBytes = U.marshal(ctx.marshaller(), this);
+                valBytes = Marshallers.marshal(ctx.marshaller(), this);
             }
             catch (IgniteCheckedException e) {
                 throw U.convertException(e);
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
index effd80efe34..601550ea63b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
@@ -33,7 +33,6 @@ import java.util.Set;
 import org.apache.ignite.internal.util.CommonUtils;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -240,7 +239,7 @@ public class BinaryMetadata implements Externalizable {
         out.writeByte(VERSION);
         out.writeInt(typeId);
 
-        U.writeString(out, typeName);
+        CommonUtils.writeString(out, typeName);
 
         if (fields == null)
             out.writeInt(-1);
@@ -248,12 +247,12 @@ public class BinaryMetadata implements Externalizable {
             out.writeInt(fields.size());
 
             for (Map.Entry<String, BinaryFieldMetadata> fieldEntry : 
fields.entrySet()) {
-                U.writeString(out, fieldEntry.getKey());
+                CommonUtils.writeString(out, fieldEntry.getKey());
                 fieldEntry.getValue().writeTo(out);
             }
         }
 
-        U.writeString(out, affKeyFieldName);
+        CommonUtils.writeString(out, affKeyFieldName);
 
         if (schemas == null)
             out.writeInt(-1);
@@ -272,7 +271,7 @@ public class BinaryMetadata implements Externalizable {
             out.writeInt(map.size());
 
             for (Map.Entry<String, Integer> e : map.entrySet()) {
-                U.writeString(out, e.getKey());
+                CommonUtils.writeString(out, e.getKey());
 
                 out.writeInt(e.getValue());
             }
@@ -298,7 +297,7 @@ public class BinaryMetadata implements Externalizable {
         in.readByte(); //skip version
 
         typeId = in.readInt();
-        typeName = U.readString(in);
+        typeName = CommonUtils.readString(in);
 
         int fieldsSize = in.readInt();
 
@@ -308,7 +307,7 @@ public class BinaryMetadata implements Externalizable {
             fields = new HashMap<>();
 
             for (int i = 0; i < fieldsSize; i++) {
-                String fieldName = U.readString(in);
+                String fieldName = CommonUtils.readString(in);
 
                 BinaryFieldMetadata fieldMeta = new BinaryFieldMetadata();
                 fieldMeta.readFrom(in);
@@ -317,7 +316,7 @@ public class BinaryMetadata implements Externalizable {
             }
         }
 
-        affKeyFieldName = U.readString(in);
+        affKeyFieldName = CommonUtils.readString(in);
 
         int schemasSize = in.readInt();
 
@@ -352,7 +351,7 @@ public class BinaryMetadata implements Externalizable {
                 nameToOrdinal = new LinkedHashMap<>(size);
 
                 for (int idx = 0; idx < size; idx++) {
-                    String name = U.readString(in);
+                    String name = CommonUtils.readString(in);
 
                     int ord = in.readInt();
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
index 91604f0b7e1..9659c837ec1 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -35,6 +35,7 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawReader;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.util.CommonUtils;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -1702,13 +1703,13 @@ class BinaryReaderExImpl implements BinaryReaderEx {
     /** {@inheritDoc} */
     @Override public @Nullable Object deserialize() throws 
BinaryObjectException {
         String newName = ctx.igniteInstanceName();
-        String oldName = U.setCurrentIgniteName(newName);
+        String oldName = CommonUtils.setCurrentIgniteName(newName);
 
         try {
             return deserialize0();
         }
         finally {
-            U.restoreOldIgniteName(oldName, newName);
+            CommonUtils.restoreOldIgniteName(oldName, newName);
         }
     }
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index ed94e37d0e3..b1577095056 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -80,7 +80,6 @@ import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.MutableSingletonList;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.marshaller.Marshallers;
 import org.apache.ignite.platform.PlatformType;
@@ -2922,7 +2921,7 @@ public class BinaryUtils {
     public static BinaryWriterEx writer(BinaryContext ctx) {
         BinaryThreadLocalContext locCtx = BinaryThreadLocalContext.get();
 
-        return new BinaryWriterExImpl(ctx, 
BinaryStreams.outputStream((int)U.KB, locCtx.chunk()), locCtx.schemaHolder(), 
null);
+        return new BinaryWriterExImpl(ctx, 
BinaryStreams.outputStream((int)CommonUtils.KB, locCtx.chunk()), 
locCtx.schemaHolder(), null);
     }
 
     /**
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 63958a225d2..4ab8eadac60 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -34,8 +34,9 @@ import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawWriter;
 import org.apache.ignite.internal.UnregisteredClassException;
 import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+import org.apache.ignite.internal.util.CommonUtils;
 import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.Marshallers;
 import org.jetbrains.annotations.Nullable;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -130,13 +131,13 @@ class BinaryWriterExImpl implements BinaryWriterEx {
      */
     void marshal(Object obj, boolean enableReplace) throws 
BinaryObjectException {
         String newName = ctx.igniteInstanceName();
-        String oldName = U.setCurrentIgniteName(newName);
+        String oldName = CommonUtils.setCurrentIgniteName(newName);
 
         try {
             marshal0(obj, enableReplace);
         }
         finally {
-            U.restoreOldIgniteName(oldName, newName);
+            CommonUtils.restoreOldIgniteName(oldName, newName);
         }
     }
 
@@ -173,7 +174,7 @@ class BinaryWriterExImpl implements BinaryWriterEx {
             out.writeByte(GridBinaryMarshaller.OPTM_MARSH);
 
             try {
-                byte[] arr = U.marshal(ctx.optimizedMarsh(), obj);
+                byte[] arr = Marshallers.marshal(ctx.optimizedMarsh(), obj);
 
                 writeInt(arr.length);
 
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 ff611bc4d77..9b9bd0e01af 100755
--- 
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
@@ -38,7 +38,6 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Serializable;
 import java.io.StringWriter;
-import java.io.UTFDataFormatException;
 import java.lang.annotation.Annotation;
 import java.lang.management.CompilationMXBean;
 import java.lang.management.LockInfo;
@@ -247,7 +246,6 @@ import 
org.apache.ignite.transactions.TransactionTimeoutException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import static java.util.Objects.isNull;
 import static 
org.apache.ignite.IgniteSystemProperties.IGNITE_DISABLE_HOSTNAME_VERIFIER;
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_HOME;
 import static 
org.apache.ignite.IgniteSystemProperties.IGNITE_IGNORE_LOCAL_HOST_NAME;
@@ -283,15 +281,6 @@ public abstract class IgniteUtils extends CommonUtils {
     /** Logger. */
     private static final Logger log = 
Logger.getLogger(IgniteUtils.class.getName());
 
-    /** */
-    public static final long KB = 1024L;
-
-    /** */
-    public static final long MB = 1024L * 1024;
-
-    /** */
-    public static final long GB = 1024L * 1024 * 1024;
-
     /** Minimum checkpointing page buffer size (may be adjusted by Ignite). */
     public static final Long DFLT_MIN_CHECKPOINTING_PAGE_BUFFER_SIZE = GB / 4;
 
@@ -4147,51 +4136,6 @@ public abstract class IgniteUtils extends CommonUtils {
         return set;
     }
 
-    /**
-     * Writes string to output stream accounting for {@code null} values.
-     * <p>
-     * Limitation for max string lenght of <code>65535</code> bytes is caused 
by {@link DataOutput#writeUTF}
-     * used under the hood to perform an actual write.
-     * </p>
-     * <p>
-     * If longer string is passes a {@link UTFDataFormatException} exception 
will be thrown.
-     * </p>
-     * <p>
-     * To write longer strings use {@link #writeLongString(DataOutput, 
String)} writes string as is converting it into binary array of UTF-8
-     * encoded characters.
-     * To read the value back {@link #readLongString(DataInput)} should be 
used.
-     * </p>
-     *
-     * @param out Output stream to write to.
-     * @param s String to write, possibly {@code null}.
-     * @throws IOException If write failed.
-     */
-    public static void writeString(DataOutput out, String s) throws 
IOException {
-        // Write null flag.
-        out.writeBoolean(s == null);
-
-        if (s != null)
-            out.writeUTF(s);
-    }
-
-    /**
-     * Reads string from input stream accounting for {@code null} values.
-     *
-     * Method enables to read strings shorter than <code>65535</code> bytes in 
UTF-8 otherwise an exception will be thrown.
-     *
-     * Strings written by {@link #writeString(DataOutput, String)} can be read 
by this method.
-     *
-     * @see #writeString(DataOutput, String) for more information about 
writing strings.
-     *
-     * @param in Stream to read from.
-     * @return Read string, possibly {@code null}.
-     * @throws IOException If read failed.
-     */
-    @Nullable public static String readString(DataInput in) throws IOException 
{
-        // If value is not null, then read it. Otherwise return null.
-        return !in.readBoolean() ? in.readUTF() : null;
-    }
-
     /**
      * Writes enum to output stream accounting for {@code null} values.
      * Note: method writes only one byte for every enum. Therefore, this method
@@ -7050,64 +6994,6 @@ public abstract class IgniteUtils extends CommonUtils {
         return null;
     }
 
-    /**
-     * Finds a non-static and non-abstract method from the class it parents.
-     *
-     * Method.getMethod() does not return non-public method.
-     *
-     * @param cls Target class.
-     * @param name Name of the method.
-     * @param paramTypes Method parameters.
-     * @return Method or {@code null}.
-     */
-    @Nullable public static Method findInheritableMethod(Class<?> cls, String 
name, Class<?>... paramTypes) {
-        Method mtd = null;
-
-        Class<?> cls0 = cls;
-
-        while (cls0 != null) {
-            try {
-                mtd = cls0.getDeclaredMethod(name, paramTypes);
-
-                break;
-            }
-            catch (NoSuchMethodException e) {
-                cls0 = cls0.getSuperclass();
-            }
-        }
-
-        if (mtd == null)
-            return null;
-
-        mtd.setAccessible(true);
-
-        int mods = mtd.getModifiers();
-
-        if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0)
-            return null;
-        else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0)
-            return mtd;
-        else if ((mods & Modifier.PRIVATE) != 0)
-            return cls == cls0 ? mtd : null;
-        else {
-            ClassLoader clsLdr = cls.getClassLoader();
-
-            ClassLoader clsLdr0 = cls0.getClassLoader();
-
-            return clsLdr == clsLdr0 && 
packageName(cls).equals(packageName(cls0)) ? mtd : null;
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @return Package name.
-     */
-    public static String packageName(Class<?> cls) {
-        Package pkg = cls.getPackage();
-
-        return pkg == null ? "" : pkg.getName();
-    }
-
     /**
      * @param cls The class to search.
      * @param name Name of a field to get.
@@ -7436,17 +7322,7 @@ public abstract class IgniteUtils extends CommonUtils {
      * @throws IgniteCheckedException If marshalling failed.
      */
     public static byte[] marshal(Marshaller marsh, Object obj) throws 
IgniteCheckedException {
-        assert marsh != null;
-
-        try {
-            return marsh.marshal(obj);
-        }
-        catch (IgniteCheckedException e) {
-            throw e;
-        }
-        catch (Exception e) {
-            throw new IgniteCheckedException(e);
-        }
+        return Marshallers.marshal(marsh, obj);
     }
 
     /**
@@ -7461,17 +7337,7 @@ public abstract class IgniteUtils extends CommonUtils {
      */
     public static void marshal(Marshaller marsh, @Nullable Object obj, 
OutputStream out)
         throws IgniteCheckedException {
-        assert marsh != null;
-
-        try {
-            marsh.marshal(obj, out);
-        }
-        catch (IgniteCheckedException e) {
-            throw e;
-        }
-        catch (Exception e) {
-            throw new IgniteCheckedException(e);
-        }
+        Marshallers.marshal(marsh, obj, out);
     }
 
     /**
@@ -8301,130 +8167,6 @@ public abstract class IgniteUtils extends CommonUtils {
         }
     }
 
-    /**
-     * Writes string to output stream accounting for {@code null} values. <br/>
-     *
-     * This method can write string of any length, limit of <code>65535</code> 
is not applied.
-     *
-     * @param out Output stream to write to.
-     * @param s String to write, possibly {@code null}.
-     * @throws IOException If write failed.
-     */
-    public static void writeLongString(DataOutput out, @Nullable String s) 
throws IOException {
-        // Write null flag.
-        out.writeBoolean(isNull(s));
-
-        if (isNull(s))
-            return;
-
-        int sLen = s.length();
-
-        // Write string length.
-        out.writeInt(sLen);
-
-        // Write byte array.
-        for (int i = 0; i < sLen; i++) {
-            char c = s.charAt(i);
-            int utfBytes = utfBytes(c);
-
-            if (utfBytes == 1)
-                out.writeByte((byte)c);
-            else if (utfBytes == 3) {
-                out.writeByte((byte)(0xE0 | (c >> 12) & 0x0F));
-                out.writeByte((byte)(0x80 | (c >> 6) & 0x3F));
-                out.writeByte((byte)(0x80 | (c & 0x3F)));
-            }
-            else {
-                out.writeByte((byte)(0xC0 | ((c >> 6) & 0x1F)));
-                out.writeByte((byte)(0x80 | (c & 0x3F)));
-            }
-        }
-    }
-
-    /**
-     * Reads string from input stream accounting for {@code null} values. <br/>
-     *
-     * This method can read string of any length, limit of <code>65535</code> 
is not applied.
-     *
-     * @param in Stream to read from.
-     * @return Read string, possibly {@code null}.
-     * @throws IOException If read failed.
-     */
-    @Nullable public static String readLongString(DataInput in) throws 
IOException {
-        // Check null value.
-        if (in.readBoolean())
-            return null;
-
-        // Read string length.
-        int sLen = in.readInt();
-
-        StringBuilder strBuilder = new StringBuilder(sLen);
-
-        // Read byte array.
-        for (int i = 0, b0, b1, b2; i < sLen; i++) {
-            b0 = in.readByte() & 0xff;
-
-            switch (b0 >> 4) {
-                case 0:
-                case 1:
-                case 2:
-                case 3:
-                case 4:
-                case 5:
-                case 6:
-                case 7:   // 1 byte format: 0xxxxxxx
-                    strBuilder.append((char)b0);
-                    break;
-
-                case 12:
-                case 13:  // 2 byte format: 110xxxxx 10xxxxxx
-                    b1 = in.readByte();
-
-                    if ((b1 & 0xC0) != 0x80)
-                        throw new UTFDataFormatException();
-
-                    strBuilder.append((char)(((b0 & 0x1F) << 6) | (b1 & 
0x3F)));
-                    break;
-
-                case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
-                    b1 = in.readByte();
-                    b2 = in.readByte();
-
-                    if ((b1 & 0xC0) != 0x80 || (b2 & 0xC0) != 0x80)
-                        throw new UTFDataFormatException();
-
-                    strBuilder.append((char)(((b0 & 0x0F) << 12) | ((b1 & 
0x3F) << 6) | (b2 & 0x3F)));
-                    break;
-
-                default:  // 10xx xxxx, 1111 xxxx
-                    throw new UTFDataFormatException();
-            }
-        }
-
-        return strBuilder.toString();
-    }
-
-    /**
-     * Get number of bytes for {@link DataOutput#writeUTF},
-     * depending on character: <br/>
-     *
-     * One byte - If a character <code>c</code> is in the range
-     * <code>&#92;u0001</code> through <code>&#92;u007f</code>.<br/>
-     *
-     * Two bytes - If a character <code>c</code> is <code>&#92;u0000</code> or
-     * is in the range <code>&#92;u0080</code> through <code>&#92;u07ff</code>.
-     * <br/>
-     *
-     * Three bytes - If a character <code>c</code> is in the range
-     * <code>&#92;u0800</code> through <code>uffff</code>.
-     *
-     * @param c Character.
-     * @return Number of bytes.
-     */
-    public static int utfBytes(char c) {
-        return (c >= 0x0001 && c <= 0x007F) ? 1 : (c > 0x07FF) ? 3 : 2;
-    }
-
     /**
      * Reads string-to-string map written by {@link 
#writeStringMap(DataOutput, Map)}.
      *

Reply via email to