Ejemplo n.º 1
0
  private void ListSubDirectorySizes(File file) {
    File[] files;
    files =
        file.listFiles(
            new FileFilter() {
              @Override
              public boolean accept(File file) {
                //                if (!file.isDirectory()){
                //                    return false;  //To change body of implemented methods use
                // File | Settings | File Templates.
                //                }else{
                //                    return true;
                //                }
                return true;
              }
            });
    Map<String, Long> dirListing = new HashMap<String, Long>();
    for (File dir : files) {
      DiskUsage diskUsage = new DiskUsage();
      diskUsage.accept(dir);
      //            long size = diskUsage.getSize() / (1024 * 1024);
      long size = diskUsage.getSize();
      dirListing.put(dir.getName(), size);
    }

    ValueComparator bvc = new ValueComparator(dirListing);
    TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(bvc);
    sorted_map.putAll(dirListing);

    PrettyPrint(file, sorted_map);
  }
Ejemplo n.º 2
0
  private void PrettyPrint(File file, TreeMap<String, Long> sortedMap) {

    //        Long size = 0L;
    //        ArrayList<Long> values = new ArrayList<Long>(sortedMap.values());

    Long total = 0L;
    for (Long value : sortedMap.values()) {
      total = total + value; // Can also be done by total += value;
    }

    log.append(file.getName() + ": " + readableFileSize(total) + "\n\n");
    for (Map.Entry<String, Long> entry : sortedMap.entrySet()) {
      log.append("[ " + readableFileSize(entry.getValue()) + " ]");
      log.append(" --> " + entry.getKey() + "\n");
    }
    //        log.append(sortedMap + "\n");
  }