Modifier and Type | Class and Description |
---|---|
static class |
InstantiationUtil.ClassLoaderObjectInputStream
A custom ObjectInputStream that can load classes using a specific ClassLoader.
|
static class |
InstantiationUtil.FailureTolerantObjectInputStream
An
ObjectInputStream that ignores serialVersionUID mismatches when deserializing objects of
anonymous classes or our Scala serializer classes and also replaces occurences of GenericData.Array
(from Avro) by a dummy class so that the KryoSerializer can still be deserialized without
Avro being on the classpath. |
Modifier and Type | Method and Description |
---|---|
static void |
checkForInstantiation(Class<?> clazz)
Performs a standard check whether the class can be instantiated by
Class#newInstance() . |
static String |
checkForInstantiationError(Class<?> clazz) |
static <T extends Serializable> |
clone(T obj)
Clones the given serializable object using Java serialization.
|
static <T extends Serializable> |
clone(T obj,
ClassLoader classLoader)
Clones the given serializable object using Java serialization, using the given classloader to
resolve the cloned classes.
|
static <T extends IOReadableWritable> |
createCopyWritable(T original)
Clones the given writable using the
serialization . |
static <T> T |
deserializeFromByteArray(TypeSerializer<T> serializer,
byte[] buf) |
static <T> T |
deserializeFromByteArray(TypeSerializer<T> serializer,
T reuse,
byte[] buf) |
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl) |
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl,
boolean isFailureTolerant) |
static <T> T |
deserializeObject(InputStream in,
ClassLoader cl) |
static <T> T |
deserializeObject(InputStream in,
ClassLoader cl,
boolean isFailureTolerant) |
static boolean |
hasPublicNullaryConstructor(Class<?> clazz)
Checks, whether the given class has a public nullary constructor.
|
static <T> T |
instantiate(Class<T> clazz)
Creates a new instance of the given class.
|
static <T> T |
instantiate(Class<T> clazz,
Class<? super T> castTo)
Creates a new instance of the given class.
|
static boolean |
isNonStaticInnerClass(Class<?> clazz)
Checks, whether the class is an inner class that is not statically accessible.
|
static boolean |
isProperClass(Class<?> clazz)
Checks, whether the class is a proper class, i.e.
|
static boolean |
isPublic(Class<?> clazz)
Checks, whether the given class is public.
|
static boolean |
isSerializable(Object o) |
static <T> T |
readObjectFromConfig(Configuration config,
String key,
ClassLoader cl) |
static byte[] |
serializeObject(Object o) |
static void |
serializeObject(OutputStream out,
Object o) |
static <T> byte[] |
serializeToByteArray(TypeSerializer<T> serializer,
T record) |
static void |
writeObjectToConfig(Object o,
Configuration config,
String key) |
public static <T> T instantiate(Class<T> clazz, Class<? super T> castTo)
T
- The generic type of the class.clazz
- The class to instantiate.castTo
- Optional parameter, specifying the class that the given class must be a subclass off. This
argument is added to prevent class cast exceptions occurring later.RuntimeException
- Thrown, if the class could not be instantiated. The exception contains a detailed
message about the reason why the instantiation failed.public static <T> T instantiate(Class<T> clazz)
T
- The generic type of the class.clazz
- The class to instantiate.RuntimeException
- Thrown, if the class could not be instantiated. The exception contains a detailed
message about the reason why the instantiation failed.public static boolean hasPublicNullaryConstructor(Class<?> clazz)
clazz
- The class to check.public static boolean isPublic(Class<?> clazz)
clazz
- The class to check.public static boolean isProperClass(Class<?> clazz)
clazz
- The class to check.public static boolean isNonStaticInnerClass(Class<?> clazz)
clazz
- The class to check.public static void checkForInstantiation(Class<?> clazz)
Class#newInstance()
.clazz
- The class to check.RuntimeException
- Thrown, if the class cannot be instantiated by Class#newInstance()
.public static <T> T readObjectFromConfig(Configuration config, String key, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static void writeObjectToConfig(Object o, Configuration config, String key) throws IOException
IOException
public static <T> byte[] serializeToByteArray(TypeSerializer<T> serializer, T record) throws IOException
IOException
public static <T> T deserializeFromByteArray(TypeSerializer<T> serializer, byte[] buf) throws IOException
IOException
public static <T> T deserializeFromByteArray(TypeSerializer<T> serializer, T reuse, byte[] buf) throws IOException
IOException
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(InputStream in, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl, boolean isFailureTolerant) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(InputStream in, ClassLoader cl, boolean isFailureTolerant) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static byte[] serializeObject(Object o) throws IOException
IOException
public static void serializeObject(OutputStream out, Object o) throws IOException
IOException
public static boolean isSerializable(Object o)
public static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException
T
- Type of the object to cloneobj
- Object to cloneIOException
ClassNotFoundException
public static <T extends Serializable> T clone(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException
T
- Type of the object to cloneobj
- Object to cloneclassLoader
- The classloader to resolve the classes during deserialization.IOException
ClassNotFoundException
public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException
serialization
.T
- Type of the object to cloneoriginal
- Object to cloneIOException
- Thrown is the serialization fails.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.