PageRenderTime 759ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/jstorm-client-extension/src/main/java/com/alibaba/jstorm/utils/FileAttribute.java

https://gitlab.com/hackbuteer59/jstorm
Java | 118 lines | 84 code | 32 blank | 2 comment | 2 complexity | e75945b509a79b15e15f9407062cd9d1 MD5 | raw file
  1. package com.alibaba.jstorm.utils;
  2. import java.io.Serializable;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import org.apache.commons.lang.builder.ToStringBuilder;
  7. import org.apache.commons.lang.builder.ToStringStyle;
  8. import org.json.simple.JSONAware;
  9. //import com.alibaba.fastjson.JSONAware;
  10. public class FileAttribute implements Serializable, JSONAware {
  11. /** */
  12. private static final long serialVersionUID = -5131640995402822835L;
  13. private String fileName;
  14. private String isDir;
  15. private String modifyTime;
  16. private String size;
  17. private static final String FILE_NAME_FIELD = "fileName";
  18. private static final String IS_DIR_FIELD = "isDir";
  19. private static final String MODIFY_TIME_FIELD = "modifyTime";
  20. private static final String SIZE_FIELD = "size";
  21. public String getFileName() {
  22. return fileName;
  23. }
  24. public void setFileName(String fileName) {
  25. this.fileName = fileName;
  26. }
  27. public String getIsDir() {
  28. return isDir;
  29. }
  30. public void setIsDir(String isDir) {
  31. this.isDir = isDir;
  32. }
  33. public String getModifyTime() {
  34. return modifyTime;
  35. }
  36. public void setModifyTime(String modifyTime) {
  37. this.modifyTime = modifyTime;
  38. }
  39. public String getSize() {
  40. return size;
  41. }
  42. public void setSize(String size) {
  43. this.size = size;
  44. }
  45. @Override
  46. public String toString() {
  47. return ToStringBuilder.reflectionToString(this,
  48. ToStringStyle.SHORT_PREFIX_STYLE);
  49. }
  50. @Override
  51. public String toJSONString() {
  52. Map<String, String> map = new HashMap<String, String>();
  53. map.put(FILE_NAME_FIELD, fileName);
  54. map.put(IS_DIR_FIELD, isDir);
  55. map.put(MODIFY_TIME_FIELD, modifyTime);
  56. map.put(SIZE_FIELD, size);
  57. return JStormUtils.to_json(map);
  58. }
  59. public static FileAttribute fromJSONObject(Map jobj) {
  60. if (jobj == null) {
  61. return null;
  62. }
  63. FileAttribute attribute = new FileAttribute();
  64. attribute.setFileName((String) jobj.get(FILE_NAME_FIELD));
  65. attribute.setIsDir((String) jobj.get(IS_DIR_FIELD));
  66. attribute.setModifyTime((String) jobj.get(MODIFY_TIME_FIELD));
  67. attribute.setSize((String) jobj.get(SIZE_FIELD));
  68. return attribute;
  69. }
  70. public static void main(String[] args) {
  71. Map<String, FileAttribute> map = new HashMap<String, FileAttribute>();
  72. FileAttribute attribute = new FileAttribute();
  73. attribute.setFileName("test");
  74. attribute.setIsDir("true");
  75. attribute.setModifyTime(new Date().toString());
  76. attribute.setSize("4096");
  77. map.put("test", attribute);
  78. System.out.println("Before:" + map);
  79. String jsonString = JStormUtils.to_json(map);
  80. Map<String, Map> map2 = (Map<String, Map>) JStormUtils
  81. .from_json(jsonString);
  82. Map jObject = map2.get("test");
  83. FileAttribute attribute2 = FileAttribute.fromJSONObject(jObject);
  84. System.out.println("attribute2:" + attribute2);
  85. }
  86. }