class PassportService {
/**
* Reads the passport holder's name.
*
* @return a string containing last name and first names seperated by spaces
*
* @throws IOException is something goes wrong
*/
public String readName() throws IOException {
byte[] fileData = readMRZ();
DataInputStream in = new DataInputStream(new ByteArrayInputStream(fileData));
in.skip(2);
in.skip(3);
byte[] data = new byte[39]; // FIXME: check if we have ID3 type document (otherwise 30 or 31 instead of 39)
in.readFully(data);
for (int i = 0; i < data.length; i++) {
if (data[i] == '<') {
data[i] = ' ';
}
}
String name = new String(data).trim();
return name;
}
}