Fix warning about .close() not being called in FileUtils.

This commit is contained in:
Andrew Grieve 2012-09-07 11:11:19 -04:00
parent 451688a12e
commit 0a669077fb

View File

@ -409,19 +409,19 @@ public class FileUtils extends Plugin {
throw new InvalidModificationException("Can't rename a file to a directory"); throw new InvalidModificationException("Can't rename a file to a directory");
} }
FileChannel input = new FileInputStream(srcFile).getChannel(); FileInputStream istream = new FileInputStream(srcFile);
FileChannel output = new FileOutputStream(destFile).getChannel(); FileOutputStream ostream = new FileOutputStream(destFile);
FileChannel input = istream.getChannel();
FileChannel output = ostream.getChannel();
input.transferTo(0, input.size(), output); try {
input.transferTo(0, input.size(), output);
input.close(); } finally {
output.close(); istream.close();
ostream.close();
/* input.close();
if (srcFile.length() != destFile.length()) { output.close();
return false;
} }
*/
return getEntry(destFile); return getEntry(destFile);
} }
@ -1008,14 +1008,17 @@ public class FileUtils extends Plugin {
filename = stripFileProtocol(filename); filename = stripFileProtocol(filename);
RandomAccessFile raf = new RandomAccessFile(filename, "rw"); RandomAccessFile raf = new RandomAccessFile(filename, "rw");
try {
if (raf.length() >= size) { if (raf.length() >= size) {
FileChannel channel = raf.getChannel(); FileChannel channel = raf.getChannel();
channel.truncate(size); channel.truncate(size);
return size; return size;
}
return raf.length();
} finally {
raf.close();
} }
return raf.length();
} }
/** /**