public PutField putFields() throws IOException {
if (state == State.NEW) {
final Map<String, FieldPutter> map = new TreeMap<String, FieldPutter>();
currentFieldMap = map;
for (SerializableField serializableField : currentSerializableClass.getFields()) {
final FieldPutter putter;
switch (serializableField.getKind()) {
case BOOLEAN: {
putter = new BooleanFieldPutter();
break;
}
case BYTE: {
putter = new ByteFieldPutter();
break;
}
case CHAR: {
putter = new CharFieldPutter();
break;
}
case DOUBLE: {
putter = new DoubleFieldPutter();
break;
}
case FLOAT: {
putter = new FloatFieldPutter();
break;
}
case INT: {
putter = new IntFieldPutter();
break;
}
case LONG: {
putter = new LongFieldPutter();
break;
}
case OBJECT: {
putter = new ObjectFieldPutter(serializableField.isUnshared());
break;
}
case SHORT: {
putter = new ShortFieldPutter();
break;
}
default: {
continue;
}
}
map.put(serializableField.getName(), putter);
}
state = State.FIELDS;
return new PutField() {
public void put(final String name, final boolean val) {
find(name).setBoolean(val);
}
public void put(final String name, final byte val) {
find(name).setByte(val);
}
public void put(final String name, final char val) {
find(name).setChar(val);
}
public void put(final String name, final short val) {
find(name).setShort(val);
}
public void put(final String name, final int val) {
find(name).setInt(val);
}
public void put(final String name, final long val) {
find(name).setLong(val);
}
public void put(final String name, final float val) {
find(name).setFloat(val);
}
public void put(final String name, final double val) {
find(name).setDouble(val);
}
public void put(final String name, final Object val) {
find(name).setObject(val);
}
@Deprecated
public void write(final ObjectOutput out) throws IOException {
throw new UnsupportedOperationException("write(ObjectOutput)");
}
private FieldPutter find(final String name) {
final FieldPutter putter = map.get(name);
if (putter == null) {
throw new IllegalArgumentException("No field named '" + name + "' found");
}
return putter;
}