Esempio n. 1
0
  private void parseString(String input) {
    Map<String, JSONObject> map = (Map<String, JSONObject>) JStormUtils.from_json(input);

    for (JSONObject jobj : map.values()) {
      FileAttribute attribute = FileAttribute.fromJSONObject(jobj);
      if (attribute != null) {
        files.add(attribute);
      }
    }

    summary = "There are " + files.size() + " files";
  }
Esempio n. 2
0
    byte[] getJSonFiles(String dir) throws Exception {
      Map<String, FileAttribute> fileMap = new HashMap<String, FileAttribute>();

      String path = logDir;
      if (dir != null) {
        path = path + File.separator + dir;
      }

      LOG.info("List dir " + path);

      File file = new File(path);

      String[] files = file.list();

      for (String fileName : files) {
        String logFile = Joiner.on(File.separator).join(path, fileName);

        FileAttribute fileAttribute = new FileAttribute();
        fileAttribute.setFileName(fileName);

        File subFile = new File(logFile);

        Date modify = new Date(subFile.lastModified());
        fileAttribute.setModifyTime(TimeFormat.getSecond(modify));

        if (subFile.isFile()) {
          fileAttribute.setIsDir(String.valueOf(false));
          fileAttribute.setSize(String.valueOf(subFile.length()));

          fileMap.put(logFile, fileAttribute);
        } else if (subFile.isDirectory()) {
          fileAttribute.setIsDir(String.valueOf(true));
          fileAttribute.setSize(String.valueOf(4096));

          fileMap.put(logFile, fileAttribute);
        }
      }

      String fileJsonStr = JStormUtils.to_json(fileMap);
      return fileJsonStr.getBytes();
    }