public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { int ordinal = data.getInt(); if (ordinal == -1) return null; T[] enumConstants = c.getEnumConstants(); if (enumConstants == null) { throw new SerializerException("Class has no enum constants:" + c + " Ordinal:" + ordinal); } return enumConstants[ordinal]; } catch (IndexOutOfBoundsException ex) { return null; } }
object = ctor.newInstance(); } catch (Exception e) { throw new SerializerException( "Error creating object of type:" + c, e ); field.set(object, value); } catch (IllegalAccessException e) { throw new SerializerException( "Error reading object", e);
val = savedField.field.get(object); } catch (IllegalAccessException e) { throw new SerializerException("Unable to access field:" + savedField.field + " on:" + object, e); throw boe; } catch (Exception e) { throw new SerializerException( "Error writing object for field:" + savedField.field, e );
/** * Write a class and return its SerializerRegistration. * * @param buffer The buffer to write the given class to. * @param type The class to write. * @return The SerializerRegistration that's registered to the class. */ public static SerializerRegistration writeClass(ByteBuffer buffer, Class type) throws IOException { SerializerRegistration reg = getSerializerRegistration(type); if (reg == null) { throw new SerializerException( "Class not registered:" + type ); } if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "writing class:{0} with ID:{1}", new Object[]{type, reg.getId()}); } buffer.putShort(reg.getId()); return reg; }
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { int ordinal = data.getInt(); if (ordinal == -1) return null; T[] enumConstants = c.getEnumConstants(); if (enumConstants == null) throw new SerializerException( "Class has no enum constants:" + c ); return enumConstants[ordinal]; } catch (IndexOutOfBoundsException ex) { return null; } }
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { int ordinal = data.getInt(); if (ordinal == -1) return null; T[] enumConstants = c.getEnumConstants(); if (enumConstants == null) { throw new SerializerException("Class has no enum constants:" + c + " Ordinal:" + ordinal); } return enumConstants[ordinal]; } catch (IndexOutOfBoundsException ex) { return null; } }
object = c.newInstance(); } catch (Exception e) { throw new SerializerException( "Error creating object of type:" + c, e ); field.set(object, value); } catch (IllegalAccessException e) { throw new SerializerException( "Error reading object", e);
object = ctor.newInstance(); } catch (Exception e) { throw new SerializerException( "Error creating object of type:" + c, e ); field.set(object, value); } catch (IllegalAccessException e) { throw new SerializerException( "Error reading object", e);
/** * Write a class and return its SerializerRegistration. * * @param buffer The buffer to write the given class to. * @param type The class to write. * @return The SerializerRegistration that's registered to the class. */ public static SerializerRegistration writeClass(ByteBuffer buffer, Class type) throws IOException { SerializerRegistration reg = getSerializerRegistration(type); if (reg == null) { throw new SerializerException( "Class not registered:" + type ); } buffer.putShort(reg.getId()); return reg; }
val = savedField.field.get(object); } catch (IllegalAccessException e) { throw new SerializerException("Unable to access field:" + savedField.field + " on:" + object, e); throw boe; } catch (Exception e) { throw new SerializerException( "Error writing object for field:" + savedField.field, e );
} catch (Exception e) { log.log(Level.WARNING, "[FieldSerializer][???] Exception occurred on writing. Maybe you've forgotten to register a class, or maybe a class member does not have a serializer."); throw new SerializerException( "Error writing object", e);
public <T> T readObject( ByteBuffer data, Class<T> c ) throws IOException { // Use serializer's support for class reading/writing SerializerRegistration reg = readClass(data); if( reg == null ) { throw new SerializerException("Class not found for buffer data."); } if( reg.getId() == -1 ) { return null; } return c.cast(reg.getType()); }
/** * Write a class and return its SerializerRegistration. * * @param buffer The buffer to write the given class to. * @param type The class to write. * @return The SerializerRegistration that's registered to the class. */ public static SerializerRegistration writeClass(ByteBuffer buffer, Class type) throws IOException { SerializerRegistration reg = getSerializerRegistration(type); if (reg == null) { throw new SerializerException( "Class not registered:" + type ); } if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "writing class:{0} with ID:{1}", new Object[]{type, reg.getId()}); } buffer.putShort(reg.getId()); return reg; }
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }