private static void writeOnPrimitive(
      final ObjectOutput out, final Object obj, final ClassMetadataField metaField)
      throws IOException {

    try {
      final Field field = metaField.getField();
      final Class clazz = field.getType();
      if (clazz == Integer.TYPE) {
        out.writeInt(FieldsManager.getFieldsManager().getInt(obj, metaField));
      } else if (clazz == Byte.TYPE) {
        out.writeByte(FieldsManager.getFieldsManager().getByte(obj, metaField));
      } else if (clazz == Long.TYPE) {
        out.writeLong(FieldsManager.getFieldsManager().getLong(obj, metaField));
      } else if (clazz == Float.TYPE) {
        out.writeFloat(FieldsManager.getFieldsManager().getFloat(obj, metaField));
      } else if (clazz == Double.TYPE) {
        out.writeDouble(FieldsManager.getFieldsManager().getDouble(obj, metaField));
      } else if (clazz == Short.TYPE) {
        out.writeShort(FieldsManager.getFieldsManager().getShort(obj, metaField));
      } else if (clazz == Character.TYPE) {
        out.writeChar(field.getChar(obj));
      } else if (clazz == Boolean.TYPE) {
        out.writeBoolean(field.getBoolean(obj));
      } else {
        throw new RuntimeException("Unexpected datatype " + clazz.getName());
      }
    } catch (IllegalAccessException access) {
      IOException io = new IOException(access.getMessage());
      io.initCause(access);
      throw io;
    }
  }
예제 #2
0
  /** {@inheritDoc} */
  public void writeExternal(ObjectOutput out) throws IOException {
    // VERSION
    out.writeByte(0);

    // SUPER
    super.writeExternal(out);

    // NUMBER OF ENTRIES
    out.writeInt(_size);

    // ENTRIES
    for (int i = _states.length; i-- > 0; ) {
      if (_states[i] == FULL) {
        out.writeDouble(_set[i]);
        out.writeInt(_values[i]);
      }
    }
  }
예제 #3
0
파일: DComplex.java 프로젝트: Narnach/ioke
 /**
  * @serialData Writes the real part, followed by the imaginary part. Both are written as doubles
  *     (using writeDouble).
  */
 public void writeExternal(ObjectOutput out) throws IOException {
   out.writeDouble(real);
   out.writeDouble(imag);
 }