Skip to content

Commit 39b9a93

Browse files
committed
[INLONG-9859][Agent] Modify based on comments
1 parent 5062935 commit 39b9a93

File tree

1 file changed

+12
-14
lines changed
  • inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer

1 file changed

+12
-14
lines changed

inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,15 @@ private boolean downloadModule(ModuleConfig module) {
228228
authHeader.forEach((k, v) -> {
229229
conn.setRequestProperty(k, v);
230230
});
231-
InputStream inStream = conn.getInputStream();
232231
String path = module.getPackageConfig().getStoragePath() + "/" + module.getPackageConfig().getFileName();
233-
FileOutputStream fs = new FileOutputStream(path);
234-
LOGGER.info("save path {}", path);
235-
int byteRead;
236-
byte[] buffer = new byte[DOWNLOAD_PACKAGE_READ_BUFF_SIZE];
237-
while ((byteRead = inStream.read(buffer)) != -1) {
238-
fs.write(buffer, 0, byteRead);
232+
try (InputStream inputStream = conn.getInputStream();
233+
FileOutputStream outputStream = new FileOutputStream(path)) {
234+
LOGGER.info("save path {}", path);
235+
int byteRead;
236+
byte[] buffer = new byte[DOWNLOAD_PACKAGE_READ_BUFF_SIZE];
237+
while ((byteRead = inputStream.read(buffer)) != -1) {
238+
outputStream.write(buffer, 0, byteRead);
239+
}
239240
}
240241
if (isPackageDownloaded(module)) {
241242
return true;
@@ -284,16 +285,13 @@ public void stop() throws Exception {
284285

285286
private static String calcFileMd5(String path) {
286287
BigInteger bi = null;
287-
try {
288-
byte[] buffer = new byte[DOWNLOAD_PACKAGE_READ_BUFF_SIZE];
289-
int len = 0;
288+
byte[] buffer = new byte[DOWNLOAD_PACKAGE_READ_BUFF_SIZE];
289+
int len = 0;
290+
try (FileInputStream fileInputStream = new FileInputStream(path)) {
290291
MessageDigest md = MessageDigest.getInstance("MD5");
291-
File f = new File(path);
292-
FileInputStream fis = new FileInputStream(f);
293-
while ((len = fis.read(buffer)) != -1) {
292+
while ((len = fileInputStream.read(buffer)) != -1) {
294293
md.update(buffer, 0, len);
295294
}
296-
fis.close();
297295
byte[] b = md.digest();
298296
bi = new BigInteger(1, b);
299297
} catch (NoSuchAlgorithmException e) {

0 commit comments

Comments
 (0)