c2c413f29636b93b4352b94ee8795c943f3180f3.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5. package cn.com.goldenwater.util.common;
  6. import cn.com.goldenwater.dcproj.utils.DateUtils;
  7. import org.apache.commons.logging.Log;
  8. import org.apache.commons.logging.LogFactory;
  9. import javax.servlet.http.HttpServletResponse;
  10. import java.io.*;
  11. import java.util.ArrayList;
  12. import java.util.Calendar;
  13. import java.util.List;
  14. public final class FileUtils {
  15. private static final Log logger = LogFactory.getLog(FileUtils.class);
  16. private FileUtils() {
  17. }
  18. public static ArrayList executeArray(String path, String seperator) {
  19. if (path == null || "".equals(path.trim())) {
  20. System.err.println("path is not exist");
  21. System.exit(0);
  22. }
  23. ArrayList list = new ArrayList();
  24. BufferedReader intxt = null;
  25. try {
  26. intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
  27. String line = null;
  28. while((line = intxt.readLine()) != null) {
  29. if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
  30. list.add(line.split(seperator));
  31. }
  32. }
  33. } catch (IOException var13) {
  34. logger.error("executeArray(String, String)", var13);
  35. System.err.println("fail in reading parameter file");
  36. var13.printStackTrace();
  37. } finally {
  38. try {
  39. intxt.close();
  40. } catch (Exception var12) {
  41. logger.warn("executeArray(String, String) - exception ignored", var12);
  42. }
  43. }
  44. return list;
  45. }
  46. public static ArrayList executeList(String path) {
  47. if (path == null || "".equals(path.trim())) {
  48. System.err.println("path is not exist");
  49. System.exit(0);
  50. }
  51. ArrayList list = new ArrayList();
  52. BufferedReader intxt = null;
  53. if (!(new File(path)).exists()) {
  54. logger.warn(path + " 没有找到!");
  55. return list;
  56. } else {
  57. try {
  58. intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
  59. String line = null;
  60. while((line = intxt.readLine()) != null) {
  61. if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
  62. list.add(line);
  63. }
  64. }
  65. } catch (IOException var12) {
  66. logger.error("executeList(String)", var12);
  67. var12.printStackTrace();
  68. System.err.println("fail in reading parameter file" + path);
  69. } finally {
  70. try {
  71. intxt.close();
  72. } catch (Exception var11) {
  73. logger.warn("executeList(String) - exception ignored", var11);
  74. }
  75. }
  76. return list;
  77. }
  78. }
  79. public static String executeString(String path) {
  80. if (path == null || "".equals(path.trim())) {
  81. System.err.println("path is not exist");
  82. System.exit(0);
  83. }
  84. StringBuffer list = new StringBuffer();
  85. BufferedReader intxt = null;
  86. if (!(new File(path)).exists()) {
  87. logger.warn(path + " 没有找到!");
  88. return null;
  89. } else {
  90. try {
  91. intxt = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
  92. String line = null;
  93. while((line = intxt.readLine()) != null) {
  94. if (!line.startsWith("#") && !line.startsWith("//") && !"".equals(line.trim())) {
  95. list.append(line).append("\n\r");
  96. }
  97. }
  98. } catch (IOException var12) {
  99. logger.error("executeList(String)", var12);
  100. var12.printStackTrace();
  101. System.err.println("fail in reading parameter file" + path);
  102. } finally {
  103. try {
  104. intxt.close();
  105. } catch (Exception var11) {
  106. logger.warn("executeList(String) - exception ignored", var11);
  107. }
  108. }
  109. return list.toString();
  110. }
  111. }
  112. public static String appendSeparator(String path) {
  113. return path.endsWith(File.separator) ? path : path + File.separator;
  114. }
  115. public static boolean writeFile(String path, String content) {
  116. if (content == null) {
  117. content = "";
  118. }
  119. BufferedWriter output = null;
  120. boolean var4;
  121. try {
  122. logger.info(DateUtils.Calendar2Str(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss") + "----------->path: " + path);
  123. File file = new File(path);
  124. if (!file.exists() && !file.createNewFile()) {
  125. var4 = false;
  126. return var4;
  127. }
  128. output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
  129. output.write(content);
  130. var4 = true;
  131. return var4;
  132. } catch (Exception var15) {
  133. logger.error("FileUtils.writeFile(String, String)", var15);
  134. var4 = false;
  135. } finally {
  136. try {
  137. output.close();
  138. } catch (Exception var14) {
  139. ;
  140. }
  141. }
  142. return var4;
  143. }
  144. public static void appendFile(String path, String content) {
  145. if (exist(path) && null != content) {
  146. try {
  147. RandomAccessFile randomFile = new RandomAccessFile(path, "rw");
  148. long fileLength = randomFile.length();
  149. randomFile.seek(fileLength);
  150. randomFile.writeBytes(content);
  151. randomFile.close();
  152. } catch (IOException var5) {
  153. var5.printStackTrace();
  154. }
  155. }
  156. }
  157. public static void copyFile(String sourceFile, String destFile) throws IOException {
  158. org.apache.commons.io.FileUtils.copyFile(new File(sourceFile), new File(destFile));
  159. }
  160. public static boolean exist(String path) {
  161. File file = new File(path);
  162. return file.exists();
  163. }
  164. public static boolean deleteFile(String path) {
  165. if (path != null && !"".equals(path.trim())) {
  166. File file = new File(path);
  167. if (file.exists()) {
  168. if (file.isDirectory()) {
  169. try {
  170. org.apache.commons.io.FileUtils.deleteDirectory(file);
  171. } catch (IOException var3) {
  172. logger.error("FileUtils.deleteFile(......)", var3);
  173. return false;
  174. }
  175. } else {
  176. file.delete();
  177. }
  178. }
  179. return true;
  180. } else {
  181. return false;
  182. }
  183. }
  184. public static boolean mkFolder(String path) {
  185. try {
  186. File folder = new File(path);
  187. if (!folder.exists()) {
  188. folder.mkdirs();
  189. }
  190. return true;
  191. } catch (Exception var2) {
  192. logger.error("FileUtils.mkFolder(......)", var2);
  193. return false;
  194. }
  195. }
  196. public static boolean createFolder(String path) {
  197. try {
  198. deleteFile(path);
  199. File folder = new File(path);
  200. folder.mkdirs();
  201. return true;
  202. } catch (Exception var2) {
  203. logger.error("FileUtils.createFolder(......)", var2);
  204. return false;
  205. }
  206. }
  207. public static void writeToDisk(InputStream ins, String path, String fileName) {
  208. try {
  209. if (!exist(path)) {
  210. File folder = new File(path);
  211. folder.mkdirs();
  212. }
  213. OutputStream bos = new FileOutputStream(path + fileName);
  214. byte[] buffer = new byte[4096];
  215. int bytesRead;
  216. while((bytesRead = ins.read(buffer, 0, 4096)) != -1) {
  217. bos.write(buffer, 0, bytesRead);
  218. }
  219. bos.close();
  220. } catch (FileNotFoundException var6) {
  221. var6.printStackTrace();
  222. } catch (IOException var7) {
  223. var7.printStackTrace();
  224. }
  225. }
  226. public static void clearPath(String path, long timeAgo) {
  227. File folder = new File(path);
  228. if (folder.exists() && folder.isDirectory()) {
  229. File[] files = folder.listFiles();
  230. File temp = null;
  231. for(int i = 0; i < files.length; ++i) {
  232. temp = files[i];
  233. if (timeAgo > temp.lastModified()) {
  234. deleteFile(temp.getPath());
  235. logger.debug("clearPath:" + temp.getPath());
  236. }
  237. }
  238. }
  239. }
  240. public static void outFile(File file, HttpServletResponse response) {
  241. byte[] buffer = new byte[1024];
  242. FileInputStream fis = null;
  243. BufferedInputStream bis = null;
  244. try {
  245. fis = new FileInputStream(file);
  246. bis = new BufferedInputStream(fis);
  247. OutputStream os = response.getOutputStream();
  248. for(int i = bis.read(buffer); i != -1; i = bis.read(buffer)) {
  249. os.write(buffer, 0, i);
  250. }
  251. System.out.println("success");
  252. } catch (Exception var19) {
  253. var19.printStackTrace();
  254. } finally {
  255. if (bis != null) {
  256. try {
  257. bis.close();
  258. } catch (IOException var18) {
  259. var18.printStackTrace();
  260. }
  261. }
  262. if (fis != null) {
  263. try {
  264. fis.close();
  265. } catch (IOException var17) {
  266. var17.printStackTrace();
  267. }
  268. }
  269. }
  270. }
  271. private String concatList(List list) {
  272. StringBuffer sb = new StringBuffer();
  273. for(int i = 0; i < list.size(); ++i) {
  274. sb.append(list.get(i)).append("\r\n");
  275. }
  276. return sb.toString();
  277. }
  278. }