|
|
@@ -1,6 +1,7 @@
|
|
|
package com.miekir.shibei.tool.web;
|
|
|
|
|
|
import com.miekir.shibei.tool.TextUtils;
|
|
|
+import sun.net.NetworkClient;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
@@ -18,6 +19,8 @@ sudo chmod 777 -R /file/images/
|
|
|
恢复默认权限
|
|
|
sudo chmod 755 /file/images/*/
|
|
|
public class WebImageTool {
|
|
|
+ // 不能小于100KB
|
|
|
+ private static final int FILE_SIZE_LIMIT = 100 * 1024;
|
|
|
// 只要授权之后,是可以直接写这个路径的,但是由于jar包等冲突(或缺失),会导致war包发布的时候,没有真正运行,也就没有文件写进去了。
|
|
|
private static final String PATH_AUTO_FOLDER = "/file/images/eden/auto/";
|
|
|
private static final String CMD_GET_AUTO_FILE_COUNT = "ls -l " + PATH_AUTO_FOLDER + " | grep \"^-\"|wc -l";
|
|
|
@@ -44,8 +47,8 @@ public class WebImageTool {
|
|
|
format = imageUrl.substring(formatIndex);
|
|
|
}
|
|
|
|
|
|
- File folder = new File(PATH_AUTO_FOLDER);
|
|
|
- //File folder = new File("D:\\");
|
|
|
+ //File folder = new File(PATH_AUTO_FOLDER);
|
|
|
+ File folder = new File("F:\\auto");
|
|
|
if (!folder.exists()) {
|
|
|
folder.mkdirs();
|
|
|
}
|
|
|
@@ -76,7 +79,8 @@ public class WebImageTool {
|
|
|
// this must be called before 'getErrorStream()' works
|
|
|
input = connection.getInputStream();
|
|
|
} else {
|
|
|
- input = connection.getErrorStream();
|
|
|
+ return null;
|
|
|
+ //input = connection.getErrorStream();
|
|
|
}
|
|
|
|
|
|
in = new BufferedInputStream(input);
|
|
|
@@ -86,6 +90,9 @@ public class WebImageTool {
|
|
|
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
|
|
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
|
|
}
|
|
|
+ if (file.length() < FILE_SIZE_LIMIT) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return String.format(IMAGE_URL_FORMAT, String.valueOf(futureFileCount), format);
|
|
|
} catch (IOException e) {
|
|
|
// handle exception
|
|
|
@@ -99,16 +106,23 @@ public class WebImageTool {
|
|
|
}
|
|
|
}
|
|
|
if (fileOutputStream != null) {
|
|
|
- try {
|
|
|
- fileOutputStream.close();
|
|
|
+ try {fileOutputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 去除太小的文件
|
|
|
+ if (file.length() < FILE_SIZE_LIMIT) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * JAVA获取文件目录的文件数
|
|
|
+ */
|
|
|
public static int getFilesCount(File folderFile) {
|
|
|
if (folderFile == null) {
|
|
|
return 0;
|
|
|
@@ -123,7 +137,7 @@ public class WebImageTool {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取文件目录的文件数
|
|
|
+ * 命令行获取文件目录的文件数
|
|
|
* @param commandStr
|
|
|
*/
|
|
|
public static int getFilesCount(String commandStr) {
|