public static SimulationResponseReceiver readFromStream(DataInputStream input) throws IOException {
int messageLength = input.readInt();
int remaining = messageLength - 4;
List<Command> commands = new ArrayList<Command>();
// the first command is the response to the command step
Command status = Command.readFromStream(input);
commands.add(status);
remaining -= status.size();
int numberResponses = 0;
// for an unknown reason the protocol was broken here
// a raw integer value follows the the first command
// indicating the following number of subscription responses
if (remaining >= 4) {
numberResponses = input.readInt();
remaining -= 4;
}
// read the subscription response commands
for (int i = 0; i < numberResponses; i++) {
Command simResp = Command.readFromStream(input);
commands.add(simResp);
remaining -= simResp.size();
}
return new SimulationResponseReceiver(numberResponses, commands);
}