diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinariesFactory.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinariesFactory.java
index 5b3462941be6f..135e1ad08978f 100644
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinariesFactory.java
+++ b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinariesFactory.java
@@ -21,6 +21,7 @@
import java.util.Map;
import java.util.function.ToIntFunction;
import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.internal.binary.streams.BinaryInputStream;
import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
@@ -35,42 +36,31 @@ public interface BinariesFactory {
*
* @param ctx Context.
* @param in Input stream.
- * @param ldr Class loader.
+ * @param ldr Custom class loader or {@code null} to use {@link BinaryContext#classLoader()}.
+ * @param hnds Reader handles or {@code null} to start a new handles context.
+ * @param skipHdrCheck Whether to skip header check.
* @param forUnmarshal {@code True} if reader is needed to unmarshal object.
*/
- public BinaryReaderEx reader(BinaryContext ctx, BinaryInputStream in, ClassLoader ldr, boolean forUnmarshal);
+ public BinaryReaderEx reader(
+ BinaryContext ctx,
+ BinaryInputStream in,
+ @Nullable ClassLoader ldr,
+ @Nullable BinaryReaderHandles hnds,
+ boolean skipHdrCheck,
+ boolean forUnmarshal
+ );
/**
- * Creates reader instance.
+ * Unmarshals object from the input stream without deserialization of user types.
*
- * @param ctx Context.
* @param in Input stream.
- * @param ldr Class loader.
- * @param hnds Context.
- * @param forUnmarshal {@code True} if reader is needed to unmarshal object.
- */
- public BinaryReaderEx reader(BinaryContext ctx,
- BinaryInputStream in,
- ClassLoader ldr,
- @Nullable BinaryReaderHandles hnds,
- boolean forUnmarshal);
-
- /**
- * Constructor.
- *
* @param ctx Context.
- * @param in Input stream.
* @param ldr Class loader.
- * @param hnds Context.
- * @param skipHdrCheck Whether to skip header check.
- * @param forUnmarshal {@code True} if reader is needed to unmarshal object.
+ * @return Unmarshalled object.
+ * @throws BinaryObjectException In case of error.
*/
- public BinaryReaderEx reader(BinaryContext ctx,
- BinaryInputStream in,
- ClassLoader ldr,
- @Nullable BinaryReaderHandles hnds,
- boolean skipHdrCheck,
- boolean forUnmarshal);
+ @Nullable public Object unmarshal(BinaryInputStream in, BinaryContext ctx, @Nullable ClassLoader ldr)
+ throws BinaryObjectException;
/**
* @param ctx Context.
@@ -129,6 +119,14 @@ public BinaryReaderEx reader(BinaryContext ctx,
*/
public BinaryObjectEx binaryOffheapObject(BinaryContext ctx, long ptr, int start, int size);
+ /**
+ * @param ctx Context
+ * @param compCls Component class.
+ * @param arr Data.
+ * @return Binary array instance.
+ */
+ public BinaryObjectEx binaryArray(BinaryContext ctx, Class> compCls, Object[] arr);
+
/**
* @return Binary enum class.
*/
@@ -139,6 +137,16 @@ public BinaryReaderEx reader(BinaryContext ctx,
*/
public Class> binaryObjectImplClass();
+ /**
+ * @return Binary array class.
+ */
+ public Class> binaryArrayClass();
+
+ /**
+ * @return Binary enum array class.
+ */
+ public Class> binaryEnumArrayClass();
+
/**
* @return Map of predefined types.
*/
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index 64450ca2b2182..6185eea136b99 100644
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -25,6 +25,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -54,7 +55,6 @@
import org.apache.ignite.binary.BinaryIdMapper;
import org.apache.ignite.binary.BinaryInvalidTypeException;
import org.apache.ignite.binary.BinaryNameMapper;
-import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryReflectiveSerializer;
import org.apache.ignite.binary.BinarySerializer;
@@ -80,11 +80,22 @@
/**
* Binary context.
+ *
+ *
Class loaders
+ * Binary code deals with exactly two kinds of class loaders:
+ *
+ *
Default loader - {@link #classLoader()}. It is the loader set via
+ * {@code IgniteConfiguration#getClassLoader()} or, when none is configured, the loader Ignite itself was
+ * loaded by ({@link CommonUtils#gridClassLoader()}). Classes resolved through it are cached.
+ *
Custom loader - a deployment (peer class loading) or user supplied loader passed explicitly
+ * into a binary API call. Such loaders can be undeployed (see {@link #onUndeploy(ClassLoader)}),
+ * so classes resolved through them are never cached.
+ *
+ * A {@code null} loader anywhere in the binary API means "use the default loader".
+ * Use {@link #resolveClassLoader(ClassLoader)} to turn a caller supplied loader into the one to actually use and
+ * {@link #isCustomLoader(ClassLoader)} to decide whether caching must be bypassed.
*/
public class BinaryContext {
- /** System loader. */
- private static final ClassLoader sysLdr = CommonUtils.gridClassLoader();
-
/** */
private static final BinaryInternalMapper DFLT_MAPPER =
new BinaryInternalMapper(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(true), false);
@@ -126,14 +137,14 @@ public class BinaryContext {
/** Node name. */
private final @Nullable String igniteInstanceName;
- /** Class loader. */
- private final @Nullable ClassLoader clsLdr;
+ /** Default class loader. Configured loader or the loader Ignite was loaded by. Never {@code null}. */
+ private final ClassLoader clsLdr;
/** Actual marshaller. */
- private BinaryMarshaller marsh;
+ private final BinaryMarshaller marsh;
/** */
- private MarshallerContext marshCtx;
+ private final MarshallerContext marshCtx;
/** */
private final @Nullable BinarySerializer dfltSerializer;
@@ -160,7 +171,7 @@ public class BinaryContext {
* @param metaHnd Meta data handler.
* @param marsh Binary marshaller.
* @param igniteInstanceName Ignite instance name.
- * @param clsLdr Class loader.
+ * @param clsLdr Configured class loader or {@code null} to use the loader Ignite was loaded by.
* @param dfltSerializer Binary serializer.
* @param idMapper Binary id mapper.
* @param nameMapper Binary name mapper.
@@ -189,7 +200,7 @@ public BinaryContext(
this.metaHnd = metaHnd;
this.igniteInstanceName = igniteInstanceName;
- this.clsLdr = clsLdr;
+ this.clsLdr = clsLdr != null ? clsLdr : CommonUtils.gridClassLoader();
this.dfltSerializer = dfltSerializer;
if (idMapper != null || nameMapper != null || !F.isEmpty(typeCfgs))
@@ -260,8 +271,6 @@ public BinaryContext(
registerPredefinedType(BinaryMetadata.class, 0);
registerPredefinedType(BinaryTreeMap.class, 0);
- registerPredefinedType(BinaryArray.class, 0);
- registerPredefinedType(BinaryEnumArray.class, 0);
BinaryUtils.binariesFactory.predefinedTypes().forEach(this::registerPredefinedType);
@@ -279,8 +288,7 @@ public BinaryContext(
if (marsh != null) {
this.marsh = marsh;
-
- marshCtx = marsh.getContext();
+ this.marshCtx = marsh.getContext();
assert marshCtx != null;
@@ -288,6 +296,10 @@ public BinaryContext(
configure(nameMapper, idMapper, dfltSerializer, typeCfgs, affFlds);
}
+ else {
+ this.marsh = null;
+ this.marshCtx = null;
+ }
}
/**
@@ -328,12 +340,43 @@ public String igniteInstanceName() {
}
/**
- * @return Class loader.
+ * @return Default class loader. Configured loader or the loader Ignite was loaded by. Never {@code null}.
*/
public ClassLoader classLoader() {
return clsLdr;
}
+ /**
+ * @param ldr Caller supplied class loader or {@code null}.
+ * @return {@code ldr} if it is a custom loader, default loader otherwise.
+ * @see #isCustomLoader(ClassLoader)
+ */
+ public ClassLoader resolveClassLoader(@Nullable ClassLoader ldr) {
+ return isCustomLoader(ldr) ? ldr : clsLdr;
+ }
+
+ /**
+ * @param ldr Caller supplied class loader or {@code null}.
+ * @return {@code true} if {@code ldr} is a custom (deployment or user supplied) loader,
+ * {@code false} if it is {@code null}, the default loader or the loader Ignite was loaded by.
+ */
+ public boolean isCustomLoader(@Nullable ClassLoader ldr) {
+ return ldr != null && ldr != clsLdr && ldr != CommonUtils.gridClassLoader();
+ }
+
+ /**
+ * @param clsName Class name.
+ * @return Class loaded by {@link #classLoader()} or {@code null} if it is not available to it.
+ */
+ @Nullable private Class> loadClassOrNull(String clsName) {
+ try {
+ return clsLdr.loadClass(clsName);
+ }
+ catch (ClassNotFoundException | NoClassDefFoundError ignored) {
+ return null;
+ }
+ }
+
/**
* @param globalNameMapper Name mapper.
* @param globalIdMapper ID mapper.
@@ -373,7 +416,7 @@ private void configure(
String affField = affFields.remove(clsName0);
if (affField == null) {
- Class> cls = ClassLoaderUtils.classForName(clsName0);
+ Class> cls = loadClassOrNull(clsName0);
if (cls != null)
affField = affFldNameProvider.apply(cls);
@@ -387,7 +430,7 @@ private void configure(
String affField = affFields.remove(clsName);
if (affField == null) {
- Class> cls = ClassLoaderUtils.classForName(clsName);
+ Class> cls = loadClassOrNull(clsName);
if (cls != null)
affField = affFldNameProvider.apply(cls);
@@ -462,20 +505,24 @@ public static BinaryNameMapper defaultNameMapper() {
}
/**
+ * Lists classes of the package visible on the classpath of {@link #classLoader()}.
+ * When a custom loader is configured, the classpath Ignite itself was loaded from is scanned as well.
+ *
* @param pkgName Package name.
* @return Class names.
*/
@SuppressWarnings("ConstantConditions")
- private static Iterable classesInPackage(String pkgName) {
+ private Iterable classesInPackage(String pkgName) {
assert pkgName != null;
Collection clsNames = new ArrayList<>();
- ClassLoader ldr = CommonUtils.gridClassLoader();
-
String pkgPath = pkgName.replaceAll("\\.", "/");
- URL[] urls = CommonUtils.classLoaderUrls(ldr);
+ Collection urls = new LinkedHashSet<>(Arrays.asList(CommonUtils.classLoaderUrls(clsLdr)));
+
+ if (clsLdr != CommonUtils.gridClassLoader())
+ urls.addAll(Arrays.asList(CommonUtils.classLoaderUrls(CommonUtils.gridClassLoader())));
for (URL url : urls) {
String proto = url.getProtocol().toLowerCase();
@@ -706,14 +753,14 @@ private BinaryClassDescriptor systemClassDescriptor(Class> cls, String clsName
/**
* @param userType User type or not.
* @param typeId Type ID.
- * @param ldr Class loader.
+ * @param ldr Custom class loader or {@code null} to use {@link #classLoader()}.
* @param registerMeta If {@code true}, then metadata will be registered along with the type descriptor.
* @return Class descriptor.
*/
BinaryClassDescriptor descriptorForTypeId(
boolean userType,
int typeId,
- ClassLoader ldr,
+ @Nullable ClassLoader ldr,
boolean registerMeta
) {
assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
@@ -724,8 +771,7 @@ BinaryClassDescriptor descriptorForTypeId(
if (desc != null)
return desc;
- if (ldr == null)
- ldr = sysLdr;
+ ldr = resolveClassLoader(ldr);
Class cls;
@@ -752,15 +798,23 @@ BinaryClassDescriptor descriptorForTypeId(
}
catch (ClassNotFoundException e) {
// Class might have been loaded by default class loader.
- if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, registerMeta)) != null)
+ if (userType
+ && ldr != null
+ && !ldr.equals(CommonUtils.gridClassLoader())
+ && (desc = descriptorForTypeId(true, typeId, null, registerMeta)) != null) {
return desc;
+ }
throw new BinaryInvalidTypeException(e);
}
catch (IgniteCheckedException e) {
// Class might have been loaded by default class loader.
- if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, registerMeta)) != null)
+ if (userType
+ && ldr != null
+ && !ldr.equals(CommonUtils.gridClassLoader())
+ && (desc = descriptorForTypeId(true, typeId, null, registerMeta)) != null) {
return desc;
+ }
throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
}
@@ -1115,14 +1169,7 @@ public void registerUserType(String clsName,
@Nullable Map enumMap) throws BinaryObjectException {
assert mapper != null;
- Class> cls = null;
-
- try {
- cls = CommonUtils.resolveClassLoader(null, classLoader()).loadClass(clsName);
- }
- catch (ClassNotFoundException | NoClassDefFoundError ignored) {
- // No-op.
- }
+ Class> cls = loadClassOrNull(clsName);
String typeName = mapper.typeName(clsName);
@@ -1512,34 +1559,6 @@ Collection predefinedTypes() {
return Collections.unmodifiableCollection(predefinedTypes.values());
}
- /** Creates instance of {@link BinaryArray}. */
- public BinaryObject createBinaryArray(Class> compCls, Object[] pArr) {
- boolean isBinaryArr = BinaryObject.class.isAssignableFrom(compCls);
-
- String compClsName = isBinaryArr ? Object.class.getName() : compCls.getName();
-
- // In case of interface or multidimensional array rely on class name.
- // Interfaces and array not registered as binary types.
- BinaryClassDescriptor desc = descriptorForClass(compCls);
-
- if (compCls.isEnum() || compCls == BinaryUtils.binariesFactory.binaryEnumClass()) {
- return new BinaryEnumArray(
- this,
- desc.registered() ? desc.typeId() : GridBinaryMarshaller.UNREGISTERED_TYPE_ID,
- compClsName,
- pArr
- );
- }
- else {
- return new BinaryArray(
- this,
- desc.registered() ? desc.typeId() : GridBinaryMarshaller.UNREGISTERED_TYPE_ID,
- compClsName,
- pArr
- );
- }
- }
-
/**
* Type descriptors.
*/
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
index f5d8d61d62e47..6dc99ed91b0d9 100644
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
+++ b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -68,6 +68,11 @@ public default Object[] array() {
throw new UnsupportedOperationException("Not array");
}
+ /** @return {@code true} if binary object stores array. */
+ public default boolean isArray() {
+ return false;
+ }
+
/**
* @return Enum class name.
*/
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderEx.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderEx.java
index 9b6c6688fb31d..8cf141fbd3839 100644
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderEx.java
+++ b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderEx.java
@@ -27,7 +27,7 @@
/**
* Extended reader interface.
*/
-public interface BinaryReaderEx extends BinaryReader, BinaryRawReader, BinaryReaderHandlesHolder, ObjectInput {
+public interface BinaryReaderEx extends BinaryReader, BinaryRawReader, ObjectInput {
/**
* @return Object.
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java
deleted file mode 100644
index 5308d9e0766c4..0000000000000
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.binary;
-
-/**
- * Holder for handles.
- */
-interface BinaryReaderHandlesHolder {
- /**
- * Set handle.
- *
- * @param obj Object.
- * @param pos Position.
- */
- public void setHandle(Object obj, int pos);
-
- /**
- * Get handle.
- *
- * @param pos Position.
- * @return Handle.
- */
- public Object getHandle(int pos);
-
- /**
- * Get all handles.
- *
- * @return Handles.
- */
- public BinaryReaderHandles handles();
-
- /** */
- public boolean isEmpty();
-}
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java
deleted file mode 100644
index 6adb2f2f1a747..0000000000000
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.binary;
-
-/**
- * Simple holder for handles.
- */
-class BinaryReaderHandlesHolderImpl implements BinaryReaderHandlesHolder {
- /** Handles. */
- private BinaryReaderHandles hnds;
-
- /** {@inheritDoc} */
- @Override public void setHandle(Object obj, int pos) {
- handles().put(pos, obj);
- }
-
- /** {@inheritDoc} */
- @Override public Object getHandle(int pos) {
- return hnds != null ? hnds.get(pos) : null;
- }
-
- /** {@inheritDoc} */
- @Override public BinaryReaderHandles handles() {
- if (hnds == null)
- hnds = new BinaryReaderHandles();
-
- return hnds;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isEmpty() {
- return hnds == null || hnds.isEmpty();
- }
-}
diff --git a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index 274d8addced0c..414341748c3a7 100644
--- a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -18,7 +18,6 @@
package org.apache.ignite.internal.binary;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
@@ -26,14 +25,11 @@
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.lang.reflect.Array;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.sql.Time;
import java.sql.Timestamp;
@@ -60,14 +56,10 @@
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
-import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteCommonsSystemProperties;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.binary.BinaryCollectionFactory;
import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryMapFactory;
import org.apache.ignite.binary.BinaryNameMapper;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectException;
@@ -79,7 +71,6 @@
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.internal.binary.streams.BinaryInputStream;
import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
-import org.apache.ignite.internal.marshaller.ClassLoaderUtils;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.util.CommonUtils;
import org.apache.ignite.internal.util.MutableSingletonList;
@@ -88,7 +79,6 @@
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.logger.NullLogger;
-import org.apache.ignite.marshaller.Marshallers;
import org.apache.ignite.platform.PlatformType;
import org.jetbrains.annotations.Nullable;
@@ -355,10 +345,10 @@ public static byte typeByClass(Class> cls) {
return cls.getComponentType().isEnum() || cls.getComponentType() == Enum.class ?
GridBinaryMarshaller.ENUM_ARR : GridBinaryMarshaller.OBJ_ARR;
- if (cls == BinaryArray.class)
+ if (cls == binariesFactory.binaryArrayClass())
return GridBinaryMarshaller.OBJ_ARR;
- if (cls == BinaryEnumArray.class)
+ if (cls == binariesFactory.binaryEnumArrayClass())
return GridBinaryMarshaller.ENUM_ARR;
if (isSpecialCollection(cls))
@@ -489,27 +479,6 @@ else if (cls == SINGLETON_LIST_CLS)
return null;
}
- /**
- * Check protocol version.
- *
- * @param protoVer Protocol version.
- */
- public static void checkProtocolVersion(byte protoVer) {
- if (GridBinaryMarshaller.PROTO_VER != protoVer)
- throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
- }
-
- /**
- * Get binary object length.
- *
- * @param in Input stream.
- * @param start Start position.
- * @return Length.
- */
- public static int length(BinaryPositionReadable in, int start) {
- return in.readIntPositioned(start + GridBinaryMarshaller.TOTAL_LEN_POS);
- }
-
/**
* Merge old and new metas.
*
@@ -721,9 +690,9 @@ else if (cls == Time[].class)
return BinaryWriteMode.TIME_ARR;
else if (cls.isArray())
return cls.getComponentType().isEnum() ? BinaryWriteMode.ENUM_ARR : BinaryWriteMode.OBJECT_ARR;
- else if (cls == BinaryArray.class)
+ else if (cls == binariesFactory.binaryArrayClass())
return BinaryWriteMode.OBJECT_ARR;
- else if (cls == BinaryEnumArray.class)
+ else if (cls == binariesFactory.binaryEnumArrayClass())
return BinaryWriteMode.ENUM_ARR;
else if (cls == binariesFactory.binaryObjectImplClass())
return BinaryWriteMode.BINARY_OBJ;
@@ -742,787 +711,94 @@ else if (cls == Class.class)
else if (Proxy.class.isAssignableFrom(cls))
return BinaryWriteMode.PROXY;
else
- return BinaryWriteMode.OBJECT;
- }
-
- /**
- * Check if class represents a collection which must be treated specially.
- *
- * @param cls Class.
- * @return {@code True} if this is a special collection class.
- */
- public static boolean isSpecialCollection(Class cls) {
- return ArrayList.class.equals(cls) || LinkedList.class.equals(cls) || SINGLETON_LIST_CLS.equals(cls) ||
- HashSet.class.equals(cls) || LinkedHashSet.class.equals(cls);
- }
-
- /**
- * Check if class represents a map which must be treated specially.
- *
- * @param cls Class.
- * @return {@code True} if this is a special map class.
- */
- public static boolean isSpecialMap(Class cls) {
- return HashMap.class.equals(cls) || LinkedHashMap.class.equals(cls);
- }
-
- /**
- * @return Value.
- */
- static byte[] doReadByteArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readByteArray(len);
- }
-
- /**
- * @return Value.
- */
- static boolean[] doReadBooleanArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readBooleanArray(len);
- }
-
- /**
- * @return Value.
- */
- static short[] doReadShortArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readShortArray(len);
- }
-
- /**
- * @return Value.
- */
- static char[] doReadCharArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readCharArray(len);
- }
-
- /**
- * @return Value.
- */
- static int[] doReadIntArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readIntArray(len);
- }
-
- /**
- * @return Value.
- */
- static long[] doReadLongArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readLongArray(len);
- }
-
- /**
- * @return Value.
- */
- static float[] doReadFloatArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readFloatArray(len);
- }
-
- /**
- * @return Value.
- */
- static double[] doReadDoubleArray(BinaryInputStream in) {
- int len = in.readInt();
-
- return in.readDoubleArray(len);
- }
-
- /**
- * @return Value.
- */
- static BigDecimal doReadDecimal(BinaryInputStream in) {
- int scale = in.readInt();
- byte[] mag = doReadByteArray(in);
-
- boolean negative = mag[0] < 0;
-
- if (negative)
- mag[0] &= 0x7F;
-
- BigInteger intVal = new BigInteger(mag);
-
- if (negative)
- intVal = intVal.negate();
-
- return new BigDecimal(intVal, scale);
- }
-
- /**
- * @return Value.
- */
- static String doReadString(BinaryInputStream in) {
- if (!in.hasArray()) {
- byte[] arr = doReadByteArray(in);
-
- if (USE_STR_SERIALIZATION_VER_2)
- return utf8BytesToStr(arr, 0, arr.length);
- else
- return new String(arr, UTF_8);
- }
-
- int strLen = in.readInt();
-
- int pos = in.position();
-
- // String will copy necessary array part for us.
- String res;
-
- if (USE_STR_SERIALIZATION_VER_2) {
- res = utf8BytesToStr(in.array(), pos, strLen);
- }
- else {
- res = new String(in.array(), pos, strLen, UTF_8);
- }
-
- in.position(pos + strLen);
-
- return res;
- }
-
- /**
- * @return Value.
- */
- static UUID doReadUuid(BinaryInputStream in) {
- return new UUID(in.readLong(), in.readLong());
- }
-
- /**
- * @return Value.
- */
- static Date doReadDate(BinaryInputStream in) {
- long time = in.readLong();
-
- return new Date(time);
- }
-
- /**
- * @return Value.
- */
- static Timestamp doReadTimestamp(BinaryInputStream in) {
- long time = in.readLong();
- int nanos = in.readInt();
-
- Timestamp ts = new Timestamp(time);
-
- ts.setNanos(ts.getNanos() + nanos);
-
- return ts;
- }
-
- /**
- * @return Value.
- */
- static Time doReadTime(BinaryInputStream in) {
- long time = in.readLong();
-
- return new Time(time);
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- BigDecimal[] arr = new BigDecimal[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.DECIMAL)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadDecimal(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- String[] arr = new String[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.STRING)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadString(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static UUID[] doReadUuidArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- UUID[] arr = new UUID[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.UUID)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadUuid(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static Date[] doReadDateArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- Date[] arr = new Date[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.DATE)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadDate(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static Timestamp[] doReadTimestampArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- Timestamp[] arr = new Timestamp[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.TIMESTAMP)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadTimestamp(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static Time[] doReadTimeArray(BinaryInputStream in) throws BinaryObjectException {
- int len = in.readInt();
-
- Time[] arr = new Time[len];
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else {
- if (flag != GridBinaryMarshaller.TIME)
- throw new BinaryObjectException("Invalid flag value: " + flag);
-
- arr[i] = doReadTime(in);
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach) {
- if (in.offheapPointer() > 0) {
- int len = in.readInt();
-
- int pos = in.position();
-
- in.position(in.position() + len);
-
- int start = in.readInt();
-
- return binariesFactory.binaryOffheapObject(ctx, in.offheapPointer() + pos, start, len);
- }
- else {
- byte[] arr = doReadByteArray(in);
- int start = in.readInt();
-
- BinaryObject binO = binariesFactory.binaryObject(ctx, arr, start);
-
- if (detach)
- return detach(binO);
-
- return binO;
- }
- }
-
- /**
- * @param in Binary input stream.
- * @param ctx Binary context.
- * @param ldr Class loader.
- * @return Class object specified at the input stream.
- * @throws BinaryObjectException If failed.
- */
- static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)
- throws BinaryObjectException {
- return doReadClass(in, ctx, ldr, true);
- }
-
- /**
- * @param in Binary input stream.
- * @param ctx Binary context.
- * @param ldr Class loader.
- * @param deserialize Doesn't load the class when the flag is {@code false}. Class information is skipped.
- * @return Class object specified at the input stream if {@code deserialize == true}. Otherwise returns {@code null}
- * @throws BinaryObjectException If failed.
- */
- private static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, boolean deserialize)
- throws BinaryObjectException {
- int typeId = in.readInt();
-
- if (!deserialize) {
- // Skip class name at the stream.
- if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- doReadClassName(in);
-
- return null;
- }
-
- return doReadClass(in, ctx, ldr, typeId);
- }
-
- /**
- * @return Value.
- */
- @SuppressWarnings("ConstantConditions")
- static Object doReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles) {
- Class>[] intfs = new Class>[in.readInt()];
-
- for (int i = 0; i < intfs.length; i++)
- intfs[i] = doReadClass(in, ctx, ldr);
-
- InvocationHandler ih = (InvocationHandler)doReadObject(in, ctx, ldr, handles);
-
- return Proxy.newProxyInstance(ldr != null ? ldr : CommonUtils.gridClassLoader(), intfs, ih);
- }
-
- /**
- * Read plain type.
- *
- * @param in Input stream.
- * @return Plain type.
- */
- static EnumType doReadEnumType(BinaryInputStream in) {
- int typeId = in.readInt();
-
- if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- return new EnumType(typeId, null);
- else {
- String clsName = doReadClassName(in);
-
- return new EnumType(GridBinaryMarshaller.UNREGISTERED_TYPE_ID, clsName);
- }
- }
-
- /**
- * @param in Input stream.
- * @return Class name.
- */
- static String doReadClassName(BinaryInputStream in) {
- byte flag = in.readByte();
-
- if (flag != GridBinaryMarshaller.STRING)
- throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']');
-
- return doReadString(in);
- }
-
- /**
- * @param in Binary input stream.
- * @param ctx Binary context.
- * @param ldr Class loader.
- * @param typeId Type id.
- * @return Class object specified at the input stream.
- * @throws BinaryObjectException If failed.
- */
- static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId)
- throws BinaryObjectException {
- Class cls;
-
- if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- cls = ctx.descriptorForTypeId(true, typeId, ldr, false).describedClass();
- else {
- String clsName = doReadClassName(in);
-
- try {
- cls = ClassLoaderUtils.forName(clsName, ldr);
- }
- catch (ClassNotFoundException e) {
- throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
- }
-
- // forces registering of class by type id, at least locally
- if (Marshallers.USE_CACHE.get())
- ctx.registerType(cls, false, false);
- }
-
- return cls;
- }
-
- /**
- * Resolve the class.
- *
- * @param ctx Binary context.
- * @param typeId Type ID.
- * @param clsName Class name.
- * @param ldr Class loaded.
- * @return Resovled class.
- */
- static Class resolveClass(BinaryContext ctx, int typeId, @Nullable String clsName,
- @Nullable ClassLoader ldr, boolean registerMeta) {
- Class cls;
-
- if (ldr == null)
- ldr = ctx.classLoader();
-
- if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- cls = ctx.descriptorForTypeId(true, typeId, ldr, registerMeta).describedClass();
- else {
- try {
- cls = ClassLoaderUtils.forName(clsName, ldr);
- }
- catch (ClassNotFoundException e) {
- throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
- }
-
- ctx.registerType(cls, false, false);
- }
-
- return cls;
- }
-
- /**
- * Read binary enum.
- *
- * @param in Input stream.
- * @param ctx Binary context.
- * @param type Plain type.
- * @return Enum.
- */
- static BinaryObjectEx doReadBinaryEnum(BinaryInputStream in, BinaryContext ctx,
- EnumType type) {
- return binariesFactory.binaryEnum(ctx, type.typeId, type.clsName, in.readInt());
- }
-
- /**
- * Read binary enum array.
- *
- * @param in Input stream.
- * @param ctx Binary context.
- * @return Enum array.
- */
- private static Object[] doReadBinaryEnumArray(BinaryInputStream in, BinaryContext ctx) {
- int len = in.readInt();
-
- Object[] arr = (Object[])Array.newInstance(binariesFactory.binaryEnumClass(), len);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == GridBinaryMarshaller.NULL)
- arr[i] = null;
- else
- arr[i] = doReadBinaryEnum(in, ctx, doReadEnumType(in));
- }
-
- return arr;
+ return BinaryWriteMode.OBJECT;
}
/**
- * Read object serialized using optimized marshaller.
+ * Check if class represents a collection which must be treated specially.
*
- * @return Result.
+ * @param cls Class.
+ * @return {@code True} if this is a special collection class.
*/
- public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable ClassLoader clsLdr) {
- int len = in.readInt();
-
- ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
-
- try {
- return ctx.optimizedMarsh().unmarshal(input, CommonUtils.resolveClassLoader(clsLdr, ctx.classLoader()));
- }
- catch (IgniteCheckedException e) {
- throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
- }
- finally {
- in.position(in.position() + len);
- }
+ public static boolean isSpecialCollection(Class cls) {
+ return ArrayList.class.equals(cls) || LinkedList.class.equals(cls) || SINGLETON_LIST_CLS.equals(cls) ||
+ HashSet.class.equals(cls) || LinkedHashSet.class.equals(cls);
}
/**
- * @return Object.
- * @throws BinaryObjectException In case of error.
+ * Check if class represents a map which must be treated specially.
+ *
+ * @param cls Class.
+ * @return {@code True} if this is a special map class.
*/
- @Nullable static Object doReadObject(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles) throws BinaryObjectException {
- return reader(ctx, in, ldr, handles.handles(), false, true).deserialize();
+ public static boolean isSpecialMap(Class cls) {
+ return HashMap.class.equals(cls) || LinkedHashMap.class.equals(cls);
}
/**
- * @return Unmarshalled value.
- * @throws BinaryObjectException In case of error.
+ * @return Value.
*/
- @Nullable static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)
- throws BinaryObjectException {
- return unmarshal(in, ctx, ldr, new BinaryReaderHandlesHolderImpl());
- }
+ static byte[] doReadByteArray(BinaryInputStream in) {
+ int len = in.readInt();
- /**
- * @return Unmarshalled value.
- * @throws BinaryObjectException In case of error.
- */
- @Nullable static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles) throws BinaryObjectException {
- return unmarshal(in, ctx, ldr, handles, false, false);
+ return in.readByteArray(len);
}
/**
- * @return Unmarshalled value.
- * @throws BinaryObjectException In case of error.
+ * @return Value.
*/
- @Nullable static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException {
- int start = in.position();
-
- byte flag = in.readByte();
-
- switch (flag) {
- case GridBinaryMarshaller.NULL:
- return null;
-
- case GridBinaryMarshaller.HANDLE: {
- int handlePos = start - in.readInt();
-
- Object obj = handles.getHandle(handlePos);
-
- if (obj == null) {
- int retPos = in.position();
-
- in.position(handlePos);
+ static String doReadString(BinaryInputStream in) {
+ if (!in.hasArray()) {
+ byte[] arr = doReadByteArray(in);
- obj = unmarshal(in, ctx, ldr, handles, detach, deserialize);
+ if (USE_STR_SERIALIZATION_VER_2)
+ return utf8BytesToStr(arr, 0, arr.length);
+ else
+ return new String(arr, UTF_8);
+ }
- in.position(retPos);
- }
+ int strLen = in.readInt();
- return obj;
- }
+ int pos = in.position();
- case GridBinaryMarshaller.OBJ: {
- checkProtocolVersion(in.readByte());
+ // String will copy necessary array part for us.
+ String res;
- int len = length(in, start);
+ if (USE_STR_SERIALIZATION_VER_2) {
+ res = utf8BytesToStr(in.array(), pos, strLen);
+ }
+ else {
+ res = new String(in.array(), pos, strLen, UTF_8);
+ }
- BinaryObjectEx po;
+ in.position(pos + strLen);
- if (detach) {
- BinaryObjectEx binObj = binariesFactory.binaryObject(ctx, in.array(), start);
+ return res;
+ }
- binObj.detachAllowed(true);
+ /**
+ * @return Value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException {
+ int len = in.readInt();
- po = binObj.detach(!handles.isEmpty());
- }
- else {
- if (in.offheapPointer() == 0)
- po = binariesFactory.binaryObject(ctx, in.array(), start);
- else
- po = binariesFactory.binaryOffheapObject(ctx, in.offheapPointer(), start,
- in.remaining() + in.position());
- }
+ String[] arr = new String[len];
- in.position(start + len);
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
- handles.setHandle(po, start);
+ if (flag == GridBinaryMarshaller.NULL)
+ arr[i] = null;
+ else {
+ if (flag != GridBinaryMarshaller.STRING)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
- return po;
+ arr[i] = doReadString(in);
}
-
- case GridBinaryMarshaller.BYTE:
- return in.readByte();
-
- case GridBinaryMarshaller.SHORT:
- return in.readShort();
-
- case GridBinaryMarshaller.INT:
- return in.readInt();
-
- case GridBinaryMarshaller.LONG:
- return in.readLong();
-
- case GridBinaryMarshaller.FLOAT:
- return in.readFloat();
-
- case GridBinaryMarshaller.DOUBLE:
- return in.readDouble();
-
- case GridBinaryMarshaller.CHAR:
- return in.readChar();
-
- case GridBinaryMarshaller.BOOLEAN:
- return in.readBoolean();
-
- case GridBinaryMarshaller.DECIMAL:
- return doReadDecimal(in);
-
- case GridBinaryMarshaller.STRING:
- return doReadString(in);
-
- case GridBinaryMarshaller.UUID:
- return doReadUuid(in);
-
- case GridBinaryMarshaller.DATE:
- return doReadDate(in);
-
- case GridBinaryMarshaller.TIMESTAMP:
- return doReadTimestamp(in);
-
- case GridBinaryMarshaller.TIME:
- return doReadTime(in);
-
- case GridBinaryMarshaller.BYTE_ARR:
- return doReadByteArray(in);
-
- case GridBinaryMarshaller.SHORT_ARR:
- return doReadShortArray(in);
-
- case GridBinaryMarshaller.INT_ARR:
- return doReadIntArray(in);
-
- case GridBinaryMarshaller.LONG_ARR:
- return doReadLongArray(in);
-
- case GridBinaryMarshaller.FLOAT_ARR:
- return doReadFloatArray(in);
-
- case GridBinaryMarshaller.DOUBLE_ARR:
- return doReadDoubleArray(in);
-
- case GridBinaryMarshaller.CHAR_ARR:
- return doReadCharArray(in);
-
- case GridBinaryMarshaller.BOOLEAN_ARR:
- return doReadBooleanArray(in);
-
- case GridBinaryMarshaller.DECIMAL_ARR:
- return doReadDecimalArray(in);
-
- case GridBinaryMarshaller.STRING_ARR:
- return doReadStringArray(in);
-
- case GridBinaryMarshaller.UUID_ARR:
- return doReadUuidArray(in);
-
- case GridBinaryMarshaller.DATE_ARR:
- return doReadDateArray(in);
-
- case GridBinaryMarshaller.TIMESTAMP_ARR:
- return doReadTimestampArray(in);
-
- case GridBinaryMarshaller.TIME_ARR:
- return doReadTimeArray(in);
-
- case GridBinaryMarshaller.OBJ_ARR:
- if (useBinaryArrays() && !deserialize)
- return doReadBinaryArray(in, ctx, ldr, handles, detach, deserialize, false);
- else
- return doReadObjectArray(in, ctx, ldr, handles, detach, deserialize);
-
- case GridBinaryMarshaller.COL:
- return doReadCollection(in, ctx, ldr, handles, detach, deserialize, null);
-
- case GridBinaryMarshaller.MAP:
- return doReadMap(in, ctx, ldr, handles, detach, deserialize, null);
-
- case GridBinaryMarshaller.BINARY_OBJ:
- return doReadBinaryObject(in, ctx, detach);
-
- case GridBinaryMarshaller.ENUM:
- case GridBinaryMarshaller.BINARY_ENUM:
- return doReadBinaryEnum(in, ctx, doReadEnumType(in));
-
- case GridBinaryMarshaller.ENUM_ARR:
- if (useBinaryArrays() && !deserialize)
- return doReadBinaryArray(in, ctx, ldr, handles, detach, deserialize, true);
- else {
- doReadEnumType(in); // Simply skip this part as we do not need it.
-
- return doReadBinaryEnumArray(in, ctx);
- }
-
- case GridBinaryMarshaller.CLASS:
- return doReadClass(in, ctx, ldr);
-
- case GridBinaryMarshaller.PROXY:
- return doReadProxy(in, ctx, ldr, handles);
-
- case GridBinaryMarshaller.OPTM_MARSH:
- return doReadOptimized(in, ctx, ldr);
-
- default:
- throw new BinaryObjectException("Invalid flag value: " + flag);
}
+
+ return arr;
}
/**
@@ -1584,226 +860,6 @@ public static byte sqlTypeToBinary(int sqlType) {
}
}
- /**
- * @param in Binary input stream.
- * @param ctx Binary context.
- * @param ldr Class loader.
- * @param handles Holder for handles.
- * @param detach Detach flag.
- * @param deserialize Deep flag.
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- static Object[] doReadObjectArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException {
- int hPos = positionForHandle(in);
-
- Class compType = doReadClass(in, ctx, ldr, deserialize);
-
- int len = in.readInt();
-
- Object[] arr = (deserialize && !BinaryObject.class.isAssignableFrom(compType))
- ? (Object[])Array.newInstance(compType, len)
- : new Object[len];
-
- handles.setHandle(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- Object res = deserializeOrUnmarshal(in, ctx, ldr, handles, detach, deserialize);
-
- if (deserialize && useBinaryArrays() && res instanceof BinaryObject)
- arr[i] = ((BinaryObject)res).deserialize(ldr);
- else
- arr[i] = res;
- }
-
- return arr;
- }
-
- /**
- * @param in Binary input stream.
- * @param ctx Binary context.
- * @param ldr Class loader.
- * @param handles Holder for handles.
- * @param detach Detach flag.
- * @param deserialize Deep flag.
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- private static BinaryArray doReadBinaryArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, boolean isEnumArray) {
- int hPos = positionForHandle(in);
-
- int compTypeId = in.readInt();
- String compClsName = null;
-
- if (compTypeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
- compClsName = doReadClassName(in);
-
- int len = in.readInt();
-
- Object[] arr = new Object[len];
-
- BinaryArray res = isEnumArray
- ? new BinaryEnumArray(ctx, compTypeId, compClsName, arr)
- : new BinaryArray(ctx, compTypeId, compClsName, arr);
-
- handles.setHandle(res, hPos);
-
- for (int i = 0; i < len; i++)
- arr[i] = deserializeOrUnmarshal(in, ctx, ldr, handles, detach, deserialize);
-
- return res;
- }
-
- /**
- * @param deserialize Deep flag.
- * @param factory Collection factory.
- * @return Value.
- * @throws BinaryObjectException In case of error.
- */
- @SuppressWarnings("unchecked")
- static Collection> doReadCollection(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
- BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryCollectionFactory factory)
- throws BinaryObjectException {
- int hPos = positionForHandle(in);
-
- int size = in.readInt();
-
- assert size >= 0;
-
- byte colType = in.readByte();
-
- Collection