fix resource leaks
This commit is contained in:
parent
17ed666fef
commit
eba38941d3
|
@ -47,6 +47,8 @@ import java.math.RoundingMode;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -320,13 +322,13 @@ public class Utilities {
|
||||||
destFile.createNewFile();
|
destFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileChannel source = null;
|
FileInputStream source = null;
|
||||||
FileChannel destination = null;
|
FileOutputStream destination = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
source = new FileInputStream(sourceFile).getChannel();
|
source = new FileInputStream(sourceFile);
|
||||||
destination = new FileOutputStream(destFile).getChannel();
|
destination = new FileOutputStream(destFile);
|
||||||
destination.transferFrom(source, 0, source.size());
|
destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
|
||||||
} finally {
|
} finally {
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
source.close();
|
source.close();
|
||||||
|
@ -398,8 +400,8 @@ public class Utilities {
|
||||||
clearDirectory(fh.getAbsolutePath());
|
clearDirectory(fh.getAbsolutePath());
|
||||||
fh.delete();
|
fh.delete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue