Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: fix resource leak and null pointer exception #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/serviceRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ private static void copyFileUsingFileChannels(File source, File dest) throws IOE
outputChannel = new FileOutputStream(dest).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
inputChannel.close();
outputChannel.close();
if (inputChannel != null) {
inputChannel.close();
}
if(outputChannel != null) {
outputChannel.close();
}
}
}
boolean exeCopy(File fileHandle,String file,long backupfileid) throws IOException {
Expand All @@ -150,7 +154,13 @@ boolean exeCopy(File fileHandle,String file,long backupfileid) throws IOExceptio
logger.error("no space in all targetbackups! need:"+fileHandle.length());
return false;
}
String md5str=DigestUtils.md5Hex(new FileInputStream(file));
FileInputStream fileStream = new FileInputStream(file);
String md5str = "";
try {
md5str = DigestUtils.md5Hex(fileStream);
} finally {
fileStream.close();
}
String targetName=backuptargetroot.getTagetrootpath()+File.separator+backuptargetroot.getTargetrootdir()+File.separator+md5str+"_"+System.currentTimeMillis();
String targetNameSave=File.separator+backuptargetroot.getTargetrootdir()+File.separator+md5str+"_"+System.currentTimeMillis();
LocalDateTime begincopysingle=LocalDateTime.now();
Expand Down