Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.nio.file.Files;
- import java.nio.file.InvalidPathException;
- import java.nio.file.Paths;
- public class Walk {
- private static void process(String string, BufferedWriter writer) {
- Integer hash = 0;
- try (InputStream is = Files.newInputStream(Paths.get(string))) {
- hash = 0x811c9dc5;
- int c = 0;
- byte[] buffer = new byte[1024];
- while ((c = is.read(buffer)) >= 0) {
- hash = hash(buffer, c, hash);
- }
- } catch (IOException | InvalidPathException e) {
- hash = 0;
- }
- try {
- writer.write(String.format("%08x", hash) + " " + string + "\n");
- } catch (IOException e) {
- System.out.println("IO exception with output file! You lose");
- return;
- }
- }
- public static void main(String[] args) {
- if (args == null || args.length != 2 || args[0] == null || args[1] == null) {
- System.out.println("You should use 2 args!!!!!!!");
- return;
- }
- try (BufferedReader bufread = Files.newBufferedReader(Paths.get(args[0]));
- BufferedWriter bufwrite = Files.newBufferedWriter(Paths.get(args[1]))) {
- String readLine;
- while ((readLine = bufread.readLine()) != null) {
- process(readLine, bufwrite);
- }
- } catch (IOException | InvalidPathException e) {
- System.out.println("Problems with args");
- }
- }
- private static int hash(final byte[] bytes, int c, int h) {
- for (int i = 0; i < c; i++) {
- h = (h * 0x01000193) ^ (bytes[i] & 0xff);
- }
- return h;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement