Package com.gigaspaces.internal.io
Class IOUtils
java.lang.Object
com.gigaspaces.internal.io.IOUtils
This class provides a set of static utility methods used for I/O manipulations (convert data to
streams, socket ports).
- Version:
- 4.5
- Author:
- Igor Goldenberg, Guy Korland
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectA deep copy makes a distinct copy of each of the object's fields, recursing through the entire graph of other objects referenced by the object being copied.static voiddeserializeSupportCodeChangeCollection(ObjectInput in, Collection collection) static intGet an anonymous socket port.static Map<Class<?>,IClassSerializer<?>> static intstatic IClassSerializer<?>static booleanstatic booleanisPortBusy(int port, String bindAddr) Checks whether a supplied socket port is busy.static ObjectobjectFromByteBuffer(byte[] buffer) Creates an object from a byte buffer.static byte[]objectToByteBuffer(Object obj) Serializes an object into a byte buffer.static boolean[]static byte[]static voidstatic IEntryPacket[]static Exception[]static intreadInt(ObjectInput in) static int[]static ListreadList(ObjectInput in) static longreadLong(ObjectInput in) static long[]static <T extends ISwapExternalizable>
Tstatic <T> Tstatic ObjectreadObject(ObjectInput in, SupportCodeChangeAnnotationContainer supportCodeChangeAnnotationContainer, boolean useIOUtilsReadObject) Tasks are loaded with a fresh class loader.static Object[]static Object[]static <T> TObjects read and written with repetitive must be immutable (cannot be changed as they are kept in underlying map, changing them will affect the next repetitiveRead/Writestatic StringRead strings that were Shrinked usingwriteRepetitiveString(ObjectOutput, String)static String[]static shortreadShort(ObjectInput in) static short[]static Stringstatic String[]static <T extends ISwapExternalizable>
Tstatic ITemplatePacket[]static Throwable[]static UUIDreadUUID(ObjectInput in) static <T> Tstatic voidserializeSupportCodeChangeCollection(ObjectOutput out, Collection collection) Complement of {@link #deserializeSupportCodeChangeCollection(ObjectInput in, Collection collection))}static booleanstatic voidwriteBooleanArray(ObjectOutput out, boolean[] array) static voidwriteByteArray(ObjectOutput out, byte[] array) static voidstatic voidwriteInt(ObjectOutput out, int value) static voidwriteIntegerArray(ObjectOutput out, int[] array) static voidwriteList(ObjectOutput out, List list) static voidwriteListString(ObjectOutput out, List<String> list) static voidwriteLong(ObjectOutput out, long value) static voidwriteLongArray(ObjectOutput out, long[] array) static <T> voidwriteMapRepetitiveKeys(ObjectOutput out, Map<String, T> map) static voidwriteMapStringListString(ObjectOutput out, Map<String, List<String>> map) static voidwriteMapStringObject(ObjectOutput out, Map<String, Object> map) static voidwriteMapStringString(ObjectOutput out, Map<String, String> map) static <T> voidwriteMapStringT(ObjectOutput out, Map<String, T> map) static voidwriteNullableSwapExternalizableObject(ObjectOutput out, ISwapExternalizable swapExternalizable) static voidwriteObject(ObjectOutput out, Object obj) static voidwriteObjectArray(ObjectOutput out, Object[] array) static voidwriteObjectArrayCompressed(ObjectOutput out, Object[] array) static voidwriteRepetitiveObject(ObjectOutput out, Object obj) Should only be used for objects that their class is known to SystemJars.DATA_GRID_JAR, meaning at SystemJars.DATA_GRID_JAR, its dependencies or JDK Objects read and written with repetitive must be immutable (cannot be changed as they are kept in underlying map, changing them will affect the next repetitiveRead/Writestatic voidwriteRepetitiveString(ObjectOutput out, String s) Shrink string over the wire, should be used for constant number of strings which are repetitive (i.e space names, class names)static voidwriteRepetitiveStringArray(ObjectOutput out, String[] array) static voidwriteShort(ObjectOutput out, short value) static voidwriteShortArray(ObjectOutput out, short[] array) static voidwriteString(ObjectOutput out, String s) static voidwriteStringArray(ObjectOutput out, String[] array) static voidwriteStringSet(ObjectOutput out, Set<String> set) static voidwriteSwapExternalizableObject(ObjectOutput out, ISwapExternalizable swapExternalizable) static voidwriteUUID(ObjectOutput out, UUID value) static voidwriteWithCachedStubs(ObjectOutput out, Object obj)
-
Field Details
-
SMART_EXTERNALIZABLE_ENABLED
public static final boolean SMART_EXTERNALIZABLE_ENABLED
-
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
isArchive
-
objectFromByteBuffer
Creates an object from a byte buffer.- Throws:
Exception
-
objectToByteBuffer
Serializes an object into a byte buffer. The object has to implement interface Serializable or Externalizable.- Throws:
Exception
-
deepClone
A deep copy makes a distinct copy of each of the object's fields, recursing through the entire graph of other objects referenced by the object being copied. Deep clone by serialize and deserialize the object and return the deserialized version. A deep copy/clone, assuming everything in the tree is serializable. NOTE: This method is very expensive!, don't use this method if you need performance.- Parameters:
obj- the object to clone, the object and object context must implement java.io.Serializable.- Returns:
- the copied object include all object references.
- Throws:
IllegalArgumentException- Failed to perform deep clone. The object of the context object is not implements java.io.Serializable.
-
writeUUID
- Throws:
IOException
-
readUUID
- Throws:
IOException
-
getCodeMapRevision
public static int getCodeMapRevision() -
writeCodeMaps
- Throws:
IOException
-
readCodeMaps
- Throws:
IOExceptionClassNotFoundException
-
isPortBusy
Checks whether a supplied socket port is busy. The port must be between 0 and 65535, inclusive.- Parameters:
port- the port to check.bindAddr- check if port busy on specificInetAddress, If bindAddr is null, it will default accepting connections on any/all local addresses- Returns:
trueif supplied port is busy, otherwisefalse.- Throws:
UnknownHostException- if no IP address for thehostcould be found, or if a scope_id was specified for a global IPv6 address.
-
getAnonymousPort
Get an anonymous socket port.- Returns:
- An anonymous port created by instantiating a
java.net.ServerSocketwith a port of 0 - Throws:
IOException
-
writeShortArray
- Throws:
IOException
-
readShortArray
- Throws:
IOException
-
writeIntegerArray
- Throws:
IOException
-
readIntegerArray
- Throws:
IOException
-
writeLongArray
- Throws:
IOException
-
readLongArray
- Throws:
IOException
-
writeByteArray
- Throws:
IOException
-
readByteArray
- Throws:
IOException
-
writeBooleanArray
- Throws:
IOException
-
readBooleanArray
- Throws:
IOException
-
writeRepetitiveString
Shrink string over the wire, should be used for constant number of strings which are repetitive (i.e space names, class names)- Throws:
IOException
-
readRepetitiveString
public static String readRepetitiveString(ObjectInput in) throws IOException, ClassNotFoundException Read strings that were Shrinked usingwriteRepetitiveString(ObjectOutput, String)- Throws:
IOExceptionClassNotFoundException
-
writeString
- Throws:
IOException
-
readString
- Throws:
IOExceptionClassNotFoundException
-
writeStringArray
- Throws:
IOException
-
readStringArray
- Throws:
IOExceptionClassNotFoundException
-
writeStringSet
- Throws:
IOException
-
readStringSet
- Throws:
IOExceptionClassNotFoundException
-
writeRepetitiveStringArray
- Throws:
IOException
-
readRepetitiveStringArray
public static String[] readRepetitiveStringArray(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeList
- Throws:
IOException
-
readList
- Throws:
IOExceptionClassNotFoundException
-
writeListString
- Throws:
IOException
-
readListString
public static List<String> readListString(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeMapStringString
public static void writeMapStringString(ObjectOutput out, Map<String, String> map) throws IOException- Throws:
IOException
-
readMapStringString
public static Map<String,String> readMapStringString(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeMapStringListString
public static void writeMapStringListString(ObjectOutput out, Map<String, List<String>> map) throws IOException- Throws:
IOException
-
readMapStringListString
public static Map<String,List<String>> readMapStringListString(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeMapStringT
- Throws:
IOException
-
readMapStringT
public static <T> Map<String,T> readMapStringT(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeMapStringObject
public static void writeMapStringObject(ObjectOutput out, Map<String, Object> map) throws IOException- Throws:
IOException
-
readMapStringObject
public static Map<String,Object> readMapStringObject(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeMapRepetitiveKeys
public static <T> void writeMapRepetitiveKeys(ObjectOutput out, Map<String, T> map) throws IOException- Throws:
IOException
-
readMapRepetitiveKeys
public static <T> Map<String,T> readMapRepetitiveKeys(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeRepetitiveObject
Should only be used for objects that their class is known to SystemJars.DATA_GRID_JAR, meaning at SystemJars.DATA_GRID_JAR, its dependencies or JDK Objects read and written with repetitive must be immutable (cannot be changed as they are kept in underlying map, changing them will affect the next repetitiveRead/Write- Throws:
IOException
-
targetSupportsSmartExternalizable
public static boolean targetSupportsSmartExternalizable() -
writeObject
- Throws:
IOException
-
readRepetitiveObject
Objects read and written with repetitive must be immutable (cannot be changed as they are kept in underlying map, changing them will affect the next repetitiveRead/Write- Throws:
IOExceptionClassNotFoundException
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
writeObjectArray
- Throws:
IOException
-
readObjectArray
- Throws:
IOExceptionClassNotFoundException
-
readThrowableArray
public static Throwable[] readThrowableArray(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
readExceptionArray
public static Exception[] readExceptionArray(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
readEntryPacketArray
public static IEntryPacket[] readEntryPacketArray(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
readTemplatePacketArray
public static ITemplatePacket[] readTemplatePacketArray(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeObjectArrayCompressed
- Throws:
IOException
-
readObjectArrayCompressed
public static Object[] readObjectArrayCompressed(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeSwapExternalizableObject
public static void writeSwapExternalizableObject(ObjectOutput out, ISwapExternalizable swapExternalizable) throws IOException - Throws:
IOException
-
readSwapExternalizableObject
public static <T extends ISwapExternalizable> T readSwapExternalizableObject(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeNullableSwapExternalizableObject
public static void writeNullableSwapExternalizableObject(ObjectOutput out, ISwapExternalizable swapExternalizable) throws IOException - Throws:
IOException
-
readNullableSwapExternalizableObject
public static <T extends ISwapExternalizable> T readNullableSwapExternalizableObject(ObjectInput in) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeWithCachedStubs
- Throws:
IOException
-
readWithCachedStubs
- Throws:
IOExceptionClassNotFoundException
-
readObject
public static Object readObject(ObjectInput in, SupportCodeChangeAnnotationContainer supportCodeChangeAnnotationContainer, boolean useIOUtilsReadObject) throws ClassNotFoundException, IOException Tasks are loaded with a fresh class loader. When the task is done this fresh class loader is removed. This will make it possible to load a modified version of this class GS-12351- Running Distributed Task can throw ClassNotFoundException, if this task was loaded by a client that already shutdown aInternalSpaceTaskWrapper.java:155nd the class has more dependencies to load. GS-12352 - Distributed Task class is not unloaded after the task finish. GS-12295 - Distributed task - improve class loading mechanism. -
serializeSupportCodeChangeCollection
public static void serializeSupportCodeChangeCollection(ObjectOutput out, Collection collection) throws IOException Complement of {@link #deserializeSupportCodeChangeCollection(ObjectInput in, Collection collection))}- Throws:
IOException
-
deserializeSupportCodeChangeCollection
public static void deserializeSupportCodeChangeCollection(ObjectInput in, Collection collection) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
writeShort
- Throws:
IOException
-
writeInt
- Throws:
IOException
-
writeLong
- Throws:
IOException
-
readShort
- Throws:
IOException
-
readInt
- Throws:
IOException
-
readLong
- Throws:
IOException
-
getClassSerializers
-
getDefaultSerializer
-