final int cnt = streamFields.length;
final ReadField[] readFields = new ReadField[cnt];
// todo - find defaulted fields
for (int i = 0; i < cnt; i++) {
SerializableField field = streamFields[i];
try {
switch (field.getKind()) {
case BOOLEAN: {
readFields[i] = new BooleanReadField(field, unmarshaller.readBoolean());
break;
}
case BYTE: {
readFields[i] = new ByteReadField(field, unmarshaller.readByte());
break;
}
case CHAR: {
readFields[i] = new CharReadField(field, unmarshaller.readChar());
break;
}
case DOUBLE: {
readFields[i] = new DoubleReadField(field, unmarshaller.readDouble());
break;
}
case FLOAT: {
readFields[i] = new FloatReadField(field, unmarshaller.readFloat());
break;
}
case INT: {
readFields[i] = new IntReadField(field, unmarshaller.readInt());
break;
}
case LONG: {
readFields[i] = new LongReadField(field, unmarshaller.readLong());
break;
}
case OBJECT: {
readFields[i] = new ObjectReadField(field, unmarshaller.readObject());
break;
}
case SHORT: {
readFields[i] = new ShortReadField(field, unmarshaller.readShort());
break;
}
default:
throw new IllegalStateException("Wrong field type");
}
} catch (IOException e) {
TraceInformation.addFieldInformation(e, field.getName());
throw e;
} catch (ClassNotFoundException e) {
TraceInformation.addFieldInformation(e, field.getName());
throw e;
} catch (RuntimeException e) {
TraceInformation.addFieldInformation(e, field.getName());
throw e;
}
}
if (old == UNREAD_FIELDS_EOB) {
restoreIdx = blockUnmarshaller.tempEndOfStream();
}
return new GetField() {
public ObjectStreamClass getObjectStreamClass() {
throw new UnsupportedOperationException("TODO...");
}
private ReadField find(final String name) {
if (name == null) {
throw new NullPointerException("name is null");
}
for (ReadField field : readFields) {
if (name.equals(field.getName())) {
return field;
}
}
return null;
}
public boolean defaulted(final String name) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted();
}
public boolean get(final String name, final boolean val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getBoolean();
}
public byte get(final String name, final byte val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getByte();
}
public char get(final String name, final char val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getChar();
}
public short get(final String name, final short val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getShort();
}
public int get(final String name, final int val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getInt();
}
public long get(final String name, final long val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getLong();
}
public float get(final String name, final float val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getFloat();
}
public double get(final String name, final double val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getDouble();
}
public Object get(final String name, final Object val) throws IOException {
final ReadField field = find(name);
return field == null || field.isDefaulted() ? val : field.getObject();
}
};
}