Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package drugi;
  2.  
  3. import jdk.nashorn.api.tree.Tree;
  4.  
  5. import java.io.IOException;
  6. import java.nio.file.*;
  7. import java.nio.file.attribute.BasicFileAttributes;
  8. import java.util.LinkedHashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.TreeMap;
  12.  
  13. public class citaj extends SimpleFileVisitor<Path> {
  14. List<String> extensions;
  15. Map<Path, TreeMap<String, Long>> sizes;
  16.  
  17. public Map<Path, TreeMap<String, Long>> getSizes() {
  18. return sizes;
  19. }
  20.  
  21. public citaj(List input){
  22. extensions = input;
  23. sizes = new LinkedHashMap<>();
  24. }
  25.  
  26. @Override
  27. public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
  28. return FileVisitResult.CONTINUE;
  29. }
  30.  
  31. @Override
  32. public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
  33. //ako file zavrsava s nekom od ekstenzija iz extensions onda dodaj sa imenom godine, mjeseca velicinom;
  34. for(String i : extensions){
  35. System.out.println(file.toString());
  36. if(file.toString().endsWith(i)){
  37. String godina = file.getParent().getParent().getFileName().toString();
  38. String mjesec = file.getParent().getFileName().toString();
  39. if(sizes.containsKey(file)){
  40. Map tren = sizes.get(file);
  41. if(tren.containsKey(i)){
  42. tren.replace(i, (Long)tren.get(i) + file.toFile().length());
  43. }
  44. else{
  45. tren.put(i, file.toFile().length());
  46. }
  47. }
  48. else {
  49. TreeMap<String, Long> val = new TreeMap<String, Long>();
  50. val.put(i, file.toFile().length());
  51. sizes.put(file, val);
  52. }
  53. }
  54. }
  55. return FileVisitResult.CONTINUE;
  56. }
  57.  
  58. @Override
  59. public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
  60. return FileVisitResult.CONTINUE;
  61. }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement