|
@@ -80,7 +80,7 @@ public class FtpUtil {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -99,7 +99,7 @@ public class FtpUtil {
|
|
|
return br.lines().map(line -> StringUtils.trimToEmpty(line))
|
|
|
.filter(line -> StringUtils.isNotEmpty(line)).collect(Collectors.toList());
|
|
|
} finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -234,7 +234,7 @@ public class FtpUtil {
|
|
|
workbook.close();
|
|
|
return true;
|
|
|
} finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -248,7 +248,7 @@ public class FtpUtil {
|
|
|
out.write(bytes);
|
|
|
return true;
|
|
|
} finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -279,7 +279,7 @@ public class FtpUtil {
|
|
|
|
|
|
return true;
|
|
|
}finally {
|
|
|
-
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -343,7 +343,7 @@ public class FtpUtil {
|
|
|
log.info("上传文件结果:{}",b);
|
|
|
return true;
|
|
|
}finally {
|
|
|
-
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -409,7 +409,7 @@ public class FtpUtil {
|
|
|
out.flush();
|
|
|
}
|
|
|
} finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|
|
@@ -423,7 +423,7 @@ public class FtpUtil {
|
|
|
try {
|
|
|
in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
|
|
|
}finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
return in;
|
|
@@ -431,34 +431,31 @@ public class FtpUtil {
|
|
|
|
|
|
@SneakyThrows
|
|
|
public static byte[] getByteDataforFile(String remoteFilePath){
|
|
|
+ byte[] flieByte=null;
|
|
|
FTPClient ftpClient = getFtpClient();
|
|
|
if(StringUtil.isNotEmpty(remoteFilePath)){
|
|
|
try{
|
|
|
ftpClient.changeWorkingDirectory(remoteFilePath);
|
|
|
}catch (Exception e){
|
|
|
log.info("e:",e.getMessage());
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
return null;
|
|
|
}
|
|
|
log.info("file success");
|
|
|
- }
|
|
|
-
|
|
|
- String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf("/") + 1);
|
|
|
- fileName = new String(fileName.getBytes("utf-8"), "iso-8859-1");
|
|
|
- byte[] flieByte=null;
|
|
|
- try (InputStream in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
- int size = 0;
|
|
|
- byte[] buf = new byte[10240];
|
|
|
- while ((size = in.read(buf)) > 0) {
|
|
|
- out.write(buf, 0, size);
|
|
|
- out.flush();
|
|
|
+ try (InputStream in = ftpClient.retrieveFileStream(encodingPath(remoteFilePath));
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
+ int size = 0;
|
|
|
+ byte[] buf = new byte[10240];
|
|
|
+ while ((size = in.read(buf)) > 0) {
|
|
|
+ out.write(buf, 0, size);
|
|
|
+ out.flush();
|
|
|
+ }
|
|
|
+ flieByte = out.toByteArray();
|
|
|
+ } finally {
|
|
|
+
|
|
|
+ releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
- flieByte = out.toByteArray();
|
|
|
- } finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
- releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
return flieByte;
|
|
|
}
|
|
@@ -486,7 +483,7 @@ public class FtpUtil {
|
|
|
out.flush();
|
|
|
}
|
|
|
} finally {
|
|
|
- ftpClient.completePendingCommand();
|
|
|
+
|
|
|
releaseFtpClient(ftpClient);
|
|
|
}
|
|
|
}
|