Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.file.Files;
  3. import java.nio.file.InvalidPathException;
  4. import java.nio.file.Paths;
  5.  
  6. public class Walk {
  7.  
  8. private static void process(String string, BufferedWriter writer) {
  9. Integer hash = 0;
  10.  
  11. try (InputStream is = Files.newInputStream(Paths.get(string))) {
  12. hash = 0x811c9dc5;
  13. int c = 0;
  14. byte[] buffer = new byte[1024];
  15. while ((c = is.read(buffer)) >= 0) {
  16. hash = hash(buffer, c, hash);
  17. }
  18. } catch (IOException | InvalidPathException e) {
  19. hash = 0;
  20. }
  21.  
  22. try {
  23. writer.write(String.format("%08x", hash) + " " + string + "\n");
  24. } catch (IOException e) {
  25. System.out.println("IO exception with output file! You lose");
  26. return;
  27. }
  28. }
  29.  
  30. public static void main(String[] args) {
  31. if (args == null || args.length != 2 || args[0] == null || args[1] == null) {
  32. System.out.println("You should use 2 args!!!!!!!");
  33. return;
  34. }
  35.  
  36. try (BufferedReader bufread = Files.newBufferedReader(Paths.get(args[0]));
  37. BufferedWriter bufwrite = Files.newBufferedWriter(Paths.get(args[1]))) {
  38. String readLine;
  39.  
  40. while ((readLine = bufread.readLine()) != null) {
  41. process(readLine, bufwrite);
  42. }
  43.  
  44. } catch (IOException | InvalidPathException e) {
  45. System.out.println("Problems with args");
  46. }
  47. }
  48.  
  49. private static int hash(final byte[] bytes, int c, int h) {
  50. for (int i = 0; i < c; i++) {
  51. h = (h * 0x01000193) ^ (bytes[i] & 0xff);
  52. }
  53. return h;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement