98cba2a98e75d4e64f5e2f2adb557f8bfa61141f.svn-base 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package org.jeecg.modules.demo.onemap.utils;
  2. import com.alibaba.fastjson.JSON;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.apache.commons.collections.collection.CompositeCollection;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.Date;
  10. import java.util.List;
  11. /**
  12. * @author wangkang
  13. * @email iwuang@qq.com
  14. * @date 2019/1/24 18:49
  15. */
  16. @Slf4j
  17. public class Utility {
  18. public Date start = null;
  19. // 读取判断
  20. public static boolean valiFileForRead(String filepath) {
  21. File file = new File(filepath);
  22. return file.exists();
  23. }
  24. //写入判断
  25. public static boolean valiFileForWrite(String filepath) {
  26. File file = new File(filepath);
  27. boolean result = false;
  28. if (file.exists()) {
  29. deleteDir(file);
  30. }
  31. try {
  32. result = file.createNewFile();
  33. } catch (IOException e) {
  34. log.error(e.getMessage(), e);
  35. }
  36. return result;
  37. }
  38. // 删除指定文件或者文件夹
  39. public static boolean deleteDir(final File dir) {
  40. if (dir.isDirectory()) {
  41. final String[] children = dir.list();
  42. for (int i = 0; i < children.length; i++) {
  43. final boolean success = deleteDir(new File(dir, children[i]));
  44. if (!success) {
  45. return false;
  46. }
  47. }
  48. }
  49. // 目录此时为空,可以删除
  50. return dir.delete();
  51. }
  52. // 判断空对象,判断空数组,判断空的字符串
  53. public static boolean isEmpty(Object o) {
  54. if (o == null) {
  55. return true;
  56. }
  57. if (o.getClass().equals(String.class) && String.valueOf(o).trim().length() < 1) {
  58. return true;
  59. }
  60. if (Collection.class.isAssignableFrom(o.getClass()) && ((Collection) (o)).size() < 1) {
  61. List list = new ArrayList();
  62. Collection collection = new CompositeCollection();
  63. }
  64. return false;
  65. }
  66. public static boolean valiShpField(String filedname) {
  67. boolean result = false;
  68. return result;
  69. }
  70. public void startRecord(Object o) {
  71. if (!isEmpty(o)) {
  72. System.out.println(JSON.toJSONString(o));
  73. }
  74. start = new Date();
  75. }
  76. public void tagLast(Object o) {
  77. Date date = new Date();
  78. System.out.println("\n========= "+JSON.toJSONString(o) + " --------> " + (date.getTime() - start.getTime() + "毫秒"));
  79. start = date;
  80. }
  81. }