if (source.lastModified() > dest.lastModified()) {
log("Expanding " + source.getAbsolutePath() + " to "
+ dest.getAbsolutePath());
FileOutputStream out = null;
CBZip2InputStream zIn = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
out = new FileOutputStream(dest);
fis = new FileInputStream(source);
bis = new BufferedInputStream(fis);
int b = bis.read();
if (b != 'B') {
throw new BuildException("Invalid bz2 file.", getLocation());
}
b = bis.read();
if (b != 'Z') {
throw new BuildException("Invalid bz2 file.", getLocation());
}
zIn = new CBZip2InputStream(bis);
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
out.write(buffer, 0, count);
count = zIn.read(buffer, 0, buffer.length);
} while (count != -1);
} catch (IOException ioe) {
String msg = "Problem expanding bzip2 " + ioe.getMessage();
throw new BuildException(msg, ioe, getLocation());
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ioex) {
// ignore
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException ioex) {
// ignore
}
}
if (out != null) {
try {
out.close();
} catch (IOException ioex) {
// ignore
}
}
if (zIn != null) {
try {
zIn.close();
} catch (IOException ioex) {
// ignore
}
}
}