Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vvzorichev.hash;
- public class Main {
- public static void main(String[] args) {
- switch (args[0]) {
- case "-i":
- InteractiveMode imobj = new InteractiveMode(args);
- break;
- default:
- SimpleMode smobj = new SimpleMode(args);
- break;
- }
- }
- }
- package com.vvzorichev.hash;
- import java.io.IOException;
- import java.util.Scanner;
- public class InteractiveMode {
- private String Args[];
- private boolean Stop;
- public InteractiveMode(String input[]) {
- this.Args = input;
- this.Stop = false;
- }
- private void PrintHash(String fileName) {
- try
- {
- CountHash chObj = new CountHash(fileName);
- String md5 = chObj.CountMd5();
- String sha256 = chObj.CountSha256();
- System.out.println("\nFile : " + fileName + "\nMd5 : " + md5 + "\nSha256 : " + sha256 + "\n");
- }
- catch (IOException ex)
- {
- System.out.println("File does not found!\n");
- }
- }
- public void Interactive() {
- while (!stop) {
- System.out.println("Enter file / files names:");
- Scanner input = new Scanner(System.in);
- for (String str : input.nextLine().split(" ")) {
- printHash(str);
- }
- boolean answer = false;
- while (!answer) {
- System.out.println("Do you want to count hash of another files?\n1 - Yes\n2 - No");
- String response = input.next();
- switch(response){
- case "2":
- stop = true;
- answer = true;
- break;
- case "1":
- answer = true;
- break;
- default:
- System.out.println("Incorrect answer! Try again");
- break;
- }
- }
- }
- }
- }
- package com.vvzorichev.hash;
- import org.apache.commons.codec.digest.DigestUtils;
- import java.io.FileInputStream;
- import java.io.IOException;
- public class CountHash {
- private String fileName;
- public CountHash(String str) {
- this.fileName = str;
- }
- public String CountMd5() throws IOException {
- return DigestUtils.md5Hex(new FileInputStream(fileName));
- }
- public String CountSha256() throws IOException {
- return DigestUtils.sha256Hex(new FileInputStream(fileName));
- }
- }
- package com.vvzorichev.hash;
- import java.io.IOException;
- public class SimpleMode {
- private String Args[];
- public String HashType;
- public SimpleMode(String input[]) {
- this.Args = input;
- this.HashType = Args[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement