/** @see ClassResolver#getRegistration(int) */ public Registration getRegistration (int classID) { return classResolver.getRegistration(classID); }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already * registered, the existing entry is updated with the new serializer. Registering a primitive also affects the corresponding * primitive wrapper. * <p> * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when * using this method. The order must be the same at deserialization as it was for serialization. */ public Registration register (Class type, Serializer serializer) { Registration registration = classResolver.getRegistration(type); if (registration != null) { registration.setSerializer(serializer); return registration; } return classResolver.register(new Registration(type, serializer, getNextRegistrationId())); }
/** If the class is not registered and {@link Kryo#setRegistrationRequired(boolean)} is false, it is automatically registered * using the {@link Kryo#addDefaultSerializer(Class, Class) default serializer}. * @throws IllegalArgumentException if the class is not registered and {@link Kryo#setRegistrationRequired(boolean)} is true. * @see ClassResolver#getRegistration(Class) */ public Registration getRegistration (Class type) { if (type == null) throw new IllegalArgumentException("type cannot be null."); Registration registration = classResolver.getRegistration(type); if (registration == null) { if (Proxy.isProxyClass(type)) { // If a Proxy class, treat it like an InvocationHandler because the concrete class for a proxy is generated. registration = getRegistration(InvocationHandler.class); } else if (!type.isEnum() && Enum.class.isAssignableFrom(type)) { // This handles an enum value that is an inner class. Eg: enum A {b{}}; registration = getRegistration(type.getEnclosingClass()); } else if (EnumSet.class.isAssignableFrom(type)) { registration = classResolver.getRegistration(EnumSet.class); } if (registration == null) { if (registrationRequired) { throw new IllegalArgumentException("Class is not registered: " + className(type) + "\nNote: To register this class use: kryo.register(" + className(type) + ".class);"); } registration = classResolver.registerImplicit(type); } } return registration; }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Resets unregistered class names, references to previously serialized or deserialized objects, and the * {@link #getGraphContext() graph context}. If {@link #setAutoReset(boolean) auto reset} is true, this method is called * automatically when an object graph has been completely serialized or deserialized. If overridden, the super method must be * called. */ public void reset () { depth = 0; if (graphContext != null) graphContext.clear(); classResolver.reset(); if (references) { referenceResolver.reset(); readObject = null; } copyDepth = 0; if (originalToCopy != null) originalToCopy.clear(2048); if (TRACE) trace("kryo", "Object graph complete."); }
/** Stores the specified registration. If the ID is already in use by the same type, the old entry is overwritten. Registering * a primitive also affects the corresponding primitive wrapper. * <p> * IDs must be the same at deserialization as they were for serialization. * <p> * Registration can be suclassed to efficiently store per type information, accessible in serializers via * {@link Kryo#getRegistration(Class)}. */ public Registration register (Registration registration) { int id = registration.getId(); if (id < 0) throw new IllegalArgumentException("id must be > 0: " + id); Registration existing = getRegistration(registration.getId()); if (DEBUG && existing != null && existing.getType() != registration.getType()) { debug("An existing registration with a different type already uses ID: " + registration.getId() + "\nExisting registration: " + existing + "\nis now overwritten with: " + registration); } return classResolver.register(registration); }
classResolver.setKryo(this);
if (type == null) throw new IllegalArgumentException("type cannot be null."); Registration registration = classResolver.getRegistration(type); if (registration == null) { if (Proxy.isProxyClass(type)) { registration = classResolver.getRegistration(EnumSet.class); } else if (isClosure(type)) { registration = classResolver.getRegistration(ClosureSerializer.Closure.class); warn(unregisteredClassMessage(type)); registration = classResolver.registerImplicit(type);
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Resets unregistered class names, references to previously serialized or deserialized objects, and the * {@link #getGraphContext() graph context}. If {@link #setAutoReset(boolean) auto reset} is true, this method is called * automatically when an object graph has been completely serialized or deserialized. If overridden, the super method must be * called. */ public void reset () { depth = 0; if (graphContext != null) graphContext.clear(); classResolver.reset(); if (references) { referenceResolver.reset(); readObject = null; } copyDepth = 0; if (originalToCopy != null) originalToCopy.clear(2048); if (TRACE) trace("kryo", "Object graph complete."); }
/** Stores the specified registration. If the ID is already in use by the same type, the old entry is overwritten. If the ID is * already in use by a different type, a {@link KryoException} is thrown. Registering a primitive also affects the * corresponding primitive wrapper. * <p> * IDs must be the same at deserialization as they were for serialization. * <p> * Registration can be suclassed to efficiently store per type information, accessible in serializers via * {@link Kryo#getRegistration(Class)}. */ public Registration register (Registration registration) { int id = registration.getId(); if (id < 0) throw new IllegalArgumentException("id must be > 0: " + id); Registration existing = getRegistration(registration.getId()); if (DEBUG && existing != null && existing.getType() != registration.getType()) { debug("An existing registration with a different type already uses ID: " + registration.getId() + "\nExisting registration: " + existing + "\nUnable to set registration: " + registration); } return classResolver.register(registration); }
classResolver.setKryo(this);
/** @see ClassResolver#getRegistration(int) */ public Registration getRegistration (int classID) { return classResolver.getRegistration(classID); }
/** Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already * registered, the existing entry is updated with the new serializer. Registering a primitive also affects the corresponding * primitive wrapper. * <p> * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when * using this method. The order must be the same at deserialization as it was for serialization. */ public Registration register (Class type, Serializer serializer) { Registration registration = classResolver.getRegistration(type); if (registration != null) { registration.setSerializer(serializer); return registration; } return classResolver.register(new Registration(type, serializer, getNextRegistrationId())); }
/** If the class is not registered and {@link Kryo#setRegistrationRequired(boolean)} is false, it is automatically registered * using the {@link Kryo#addDefaultSerializer(Class, Class) default serializer}. * @throws IllegalArgumentException if the class is not registered and {@link Kryo#setRegistrationRequired(boolean)} is true. * @see ClassResolver#getRegistration(Class) */ public Registration getRegistration (Class type) { if (type == null) throw new IllegalArgumentException("type cannot be null."); Registration registration = classResolver.getRegistration(type); if (registration == null) { if (Proxy.isProxyClass(type)) { // If a Proxy class, treat it like an InvocationHandler because the concrete class for a proxy is generated. registration = getRegistration(InvocationHandler.class); } else if (!type.isEnum() && Enum.class.isAssignableFrom(type)) { // This handles an enum value that is an inner class. Eg: enum A {b{}}; registration = getRegistration(type.getEnclosingClass()); } else if (EnumSet.class.isAssignableFrom(type)) { registration = classResolver.getRegistration(EnumSet.class); } if (registration == null) { if (registrationRequired) { throw new IllegalArgumentException("Class is not registered: " + className(type) + "\nNote: To register this class use: kryo.register(" + className(type) + ".class);"); } registration = classResolver.registerImplicit(type); } } return registration; }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Resets unregistered class names, references to previously serialized or deserialized objects, and the * {@link #getGraphContext() graph context}. If {@link #setAutoReset(boolean) auto reset} is true, this method is called * automatically when an object graph has been completely serialized or deserialized. If overridden, the super method must be * called. */ public void reset () { depth = 0; if (graphContext != null) graphContext.clear(); classResolver.reset(); if (references) { referenceResolver.reset(); readObject = null; } copyDepth = 0; if (originalToCopy != null) originalToCopy.clear(2048); if (TRACE) trace("kryo", "Object graph complete."); }
/** Stores the specified registration. If the ID is already in use by the same type, the old entry is overwritten. Registering * a primitive also affects the corresponding primitive wrapper. * <p> * IDs must be the same at deserialization as they were for serialization. * <p> * Registration can be suclassed to efficiently store per type information, accessible in serializers via * {@link Kryo#getRegistration(Class)}. */ public Registration register (Registration registration) { int id = registration.getId(); if (id < 0) throw new IllegalArgumentException("id must be > 0: " + id); Registration existing = getRegistration(registration.getId()); if (DEBUG && existing != null && existing.getType() != registration.getType()) { debug("An existing registration with a different type already uses ID: " + registration.getId() + "\nExisting registration: " + existing + "\nis now overwritten with: " + registration); } return classResolver.register(registration); }