private void write()

in xstream/src/java/com/thoughtworks/xstream/converters/reflection/SunUnsafeReflectionProvider.java [60:102]


    private void write(final Field field, final Object object, final Object value) {
        if (exception != null) {
            final ObjectAccessException ex = new ObjectAccessException("Cannot set field", exception);
            ex.add("field", object.getClass() + "." + field.getName());
            throw ex;
        }
        try {
            final long offset = getFieldOffset(field);
            final Class<?> type = field.getType();
            if (type.isPrimitive()) {
                if (type.equals(Integer.TYPE)) {
                    unsafe.putInt(object, offset, ((Integer)value).intValue());
                } else if (type.equals(Long.TYPE)) {
                    unsafe.putLong(object, offset, ((Long)value).longValue());
                } else if (type.equals(Short.TYPE)) {
                    unsafe.putShort(object, offset, ((Short)value).shortValue());
                } else if (type.equals(Character.TYPE)) {
                    unsafe.putChar(object, offset, ((Character)value).charValue());
                } else if (type.equals(Byte.TYPE)) {
                    unsafe.putByte(object, offset, ((Byte)value).byteValue());
                } else if (type.equals(Float.TYPE)) {
                    unsafe.putFloat(object, offset, ((Float)value).floatValue());
                } else if (type.equals(Double.TYPE)) {
                    unsafe.putDouble(object, offset, ((Double)value).doubleValue());
                } else if (type.equals(Boolean.TYPE)) {
                    unsafe.putBoolean(object, offset, ((Boolean)value).booleanValue());
                } else {
                    final ObjectAccessException ex = new ObjectAccessException("Cannot set field of unknown type",
                        exception);
                    ex.add("field", object.getClass() + "." + field.getName());
                    ex.add("unknown-type", type.getName());
                    throw ex;
                }
            } else {
                unsafe.putObject(object, offset, value);
            }

        } catch (final IllegalArgumentException e) {
            final ObjectAccessException ex = new ObjectAccessException("Cannot set field", e);
            ex.add("field", object.getClass() + "." + field.getName());
            throw ex;
        }
    }