public void writeFile(String fileName, byte[] data) throws UpdateException {
File file = new File(mDir, fileName);
FileOutputStream stream = null;
try {
stream = new FileOutputStream(file);
stream.write(data);
mBytesWritten += data.length;
}
catch (IOException exc) {
// Try to delete the corrupt file
if (stream != null) {
try { stream.close(); } catch (IOException exc2) {}
}
file.delete();
throw new UpdateException("Writing file failed: " + fileName, exc);
}
finally {
if (stream != null) {
try { stream.close(); } catch (IOException exc) {}
}
}
}