Skip to content

Instantly share code, notes, and snippets.

@rmetzler
Created January 6, 2010 12:07
Show Gist options
  • Save rmetzler/270235 to your computer and use it in GitHub Desktop.
Save rmetzler/270235 to your computer and use it in GitHub Desktop.
public static <T> List<T> unmarshalList(IUnmarshaller<T> unmarshaller, DataInputStream in)
throws UnmarshalException {
try {
BufferedInputStream buff = new BufferedInputStream(in);
in = new DataInputStream(buff);
byte tag = in.readByte();
if (TagTable.NO_VALUE == tag) {
return null;
}
if (TagTable.SEQ == tag) {
ArrayList<T> list = new ArrayList<T>();
byte b;
in.mark(2);
while ( TagTable.EOC != (b = in.readByte()) ) {
in.reset();
T o = unmarshaller.unmarshal(in);
list.add(o);
in.mark(2);
}
return list;
}
// else if (TagTable.REG_EXT == tag) {
//
// //Registered Extension
// //TODO implement
// int extId = in.readInt();
// System.out.println("Registered Extension:" + extId);
// IProtocolElement unmarshalled = ExtensionRegistry.getInstance().getForId(extId).unmarshal(in);
// System.out.println(unmarshalled);
//
// return null;
// }
throw new UnmarshalException("Sequence expected, Tag was " + Byte.toString(tag));
} catch (IOException e) {
throw new UnmarshalException("Fehler beim unmarshalling der Liste", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment