Code with Misuse: |
class PassportFileService {
/**
* Reads the file with id <code>fid</code>.
*
* @param fid the file to read.
*
* @return the contents of the file.
*/
public byte[] readFile(short fid) throws IOException {
/* Was this file read previously? */
Short fidKey = new Short(fid);
if (files.containsKey(fidKey)) {
return (byte[])files.get(fidKey);
}
/* No? Read it from document... */
SecureMessagingWrapper wrapper = getWrapper();
ByteArrayOutputStream out = new ByteArrayOutputStream();
service.sendSelectFile(wrapper, fid);
int offset = 0;
while (true) {
byte[] data = service.sendReadBinary(wrapper, (short)offset, 255);
if (data.length == 0) {
// TODO: also break out of loop if SW indicates EOF
break;
}
out.write(data, 0, data.length);
offset += data.length;
}
byte[] file = out.toByteArray();
files.put(fidKey, file);
return file;
}
}
|