| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package cn.com.goldenwater.util.common;
- import cn.com.goldenwater.dcproj.utils.DateUtils;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.List;
- public final class FileUtils {
- private static final Log logger = LogFactory.getLog(FileUtils.class);
- private FileUtils() {
- }
- public static ArrayList executeArray(String path, String seperator) {
- if (path == null || "".equals(path.trim())) {
- System.err.println("path is not exist");
- System.exit(0);
- }
- ArrayList list = new ArrayList();
- BufferedReader intxt = null;
- try {
- intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
- String line = null;
- while((line = intxt.readLine()) != null) {
- if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
- list.add(line.split(seperator));
- }
- }
- } catch (IOException var13) {
- logger.error("executeArray(String, String)", var13);
- System.err.println("fail in reading parameter file");
- var13.printStackTrace();
- } finally {
- try {
- intxt.close();
- } catch (Exception var12) {
- logger.warn("executeArray(String, String) - exception ignored", var12);
- }
- }
- return list;
- }
- public static ArrayList executeList(String path) {
- if (path == null || "".equals(path.trim())) {
- System.err.println("path is not exist");
- System.exit(0);
- }
- ArrayList list = new ArrayList();
- BufferedReader intxt = null;
- if (!(new File(path)).exists()) {
- logger.warn(path + " 没有找到!");
- return list;
- } else {
- try {
- intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
- String line = null;
- while((line = intxt.readLine()) != null) {
- if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
- list.add(line);
- }
- }
- } catch (IOException var12) {
- logger.error("executeList(String)", var12);
- var12.printStackTrace();
- System.err.println("fail in reading parameter file" + path);
- } finally {
- try {
- intxt.close();
- } catch (Exception var11) {
- logger.warn("executeList(String) - exception ignored", var11);
- }
- }
- return list;
- }
- }
- public static String executeString(String path) {
- if (path == null || "".equals(path.trim())) {
- System.err.println("path is not exist");
- System.exit(0);
- }
- StringBuffer list = new StringBuffer();
- BufferedReader intxt = null;
- if (!(new File(path)).exists()) {
- logger.warn(path + " 没有找到!");
- return null;
- } else {
- try {
- intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
- String line = null;
- while((line = intxt.readLine()) != null) {
- if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
- list.append(line).append("\n\r");
- }
- }
- } catch (IOException var12) {
- logger.error("executeList(String)", var12);
- var12.printStackTrace();
- System.err.println("fail in reading parameter file" + path);
- } finally {
- try {
- intxt.close();
- } catch (Exception var11) {
- logger.warn("executeList(String) - exception ignored", var11);
- }
- }
- return list.toString();
- }
- }
- public static String appendSeparator(String path) {
- return path.endsWith(File.separator) ? path : path + File.separator;
- }
- public static boolean writeFile(String path, String content) {
- if (content == null) {
- content = "";
- }
- BufferedWriter output = null;
- boolean var4;
- try {
- logger.info(DateUtils.Calendar2Str(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss") + "----------->path: " + path);
- File file = new File(path);
- if (!file.exists() && !file.createNewFile()) {
- var4 = false;
- return var4;
- }
- output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
- output.write(content);
- var4 = true;
- return var4;
- } catch (Exception var15) {
- logger.error("FileUtils.writeFile(String, String)", var15);
- var4 = false;
- } finally {
- try {
- output.close();
- } catch (Exception var14) {
- ;
- }
- }
- return var4;
- }
- public static void appendFile(String path, String content) {
- if (exist(path) && null != content) {
- try {
- RandomAccessFile randomFile = new RandomAccessFile(path, "rw");
- long fileLength = randomFile.length();
- randomFile.seek(fileLength);
- randomFile.writeBytes(content);
- randomFile.close();
- } catch (IOException var5) {
- var5.printStackTrace();
- }
- }
- }
- public static void copyFile(String sourceFile, String destFile) throws IOException {
- org.apache.commons.io.FileUtils.copyFile(new File(sourceFile), new File(destFile));
- }
- public static boolean exist(String path) {
- File file = new File(path);
- return file.exists();
- }
- public static boolean deleteFile(String path) {
- if (path != null && !"".equals(path.trim())) {
- File file = new File(path);
- if (file.exists()) {
- if (file.isDirectory()) {
- try {
- org.apache.commons.io.FileUtils.deleteDirectory(file);
- } catch (IOException var3) {
- logger.error("FileUtils.deleteFile(......)", var3);
- return false;
- }
- } else {
- file.delete();
- }
- }
- return true;
- } else {
- return false;
- }
- }
- public static boolean mkFolder(String path) {
- try {
- File folder = new File(path);
- if (!folder.exists()) {
- folder.mkdirs();
- }
- return true;
- } catch (Exception var2) {
- logger.error("FileUtils.mkFolder(......)", var2);
- return false;
- }
- }
- public static boolean createFolder(String path) {
- try {
- deleteFile(path);
- File folder = new File(path);
- folder.mkdirs();
- return true;
- } catch (Exception var2) {
- logger.error("FileUtils.createFolder(......)", var2);
- return false;
- }
- }
- public static void writeToDisk(InputStream ins, String path, String fileName) {
- try {
- if (!exist(path)) {
- File folder = new File(path);
- folder.mkdirs();
- }
- OutputStream bos = new FileOutputStream(path + fileName);
- byte[] buffer = new byte[4096];
- int bytesRead;
- while((bytesRead = ins.read(buffer, 0, 4096)) != -1) {
- bos.write(buffer, 0, bytesRead);
- }
- bos.close();
- } catch (FileNotFoundException var6) {
- var6.printStackTrace();
- } catch (IOException var7) {
- var7.printStackTrace();
- }
- }
- public static void clearPath(String path, long timeAgo) {
- File folder = new File(path);
- if (folder.exists() && folder.isDirectory()) {
- File[] files = folder.listFiles();
- File temp = null;
- for(int i = 0; i < files.length; ++i) {
- temp = files[i];
- if (timeAgo > temp.lastModified()) {
- deleteFile(temp.getPath());
- logger.debug("clearPath:" + temp.getPath());
- }
- }
- }
- }
- public static void outFile(File file, HttpServletResponse response) {
- byte[] buffer = new byte[1024];
- FileInputStream fis = null;
- BufferedInputStream bis = null;
- try {
- fis = new FileInputStream(file);
- bis = new BufferedInputStream(fis);
- OutputStream os = response.getOutputStream();
- for(int i = bis.read(buffer); i != -1; i = bis.read(buffer)) {
- os.write(buffer, 0, i);
- }
- System.out.println("success");
- } catch (Exception var19) {
- var19.printStackTrace();
- } finally {
- if (bis != null) {
- try {
- bis.close();
- } catch (IOException var18) {
- var18.printStackTrace();
- }
- }
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException var17) {
- var17.printStackTrace();
- }
- }
- }
- }
- private String concatList(List list) {
- StringBuffer sb = new StringBuffer();
- for(int i = 0; i < list.size(); ++i) {
- sb.append(list.get(i)).append("\r\n");
- }
- return sb.toString();
- }
- }
|