minor formatting work
This commit is contained in:
parent
7194d8b84a
commit
f354f9e305
|
@ -1,6 +1,5 @@
|
|||
package com.baeldung.hashing;
|
||||
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
|
@ -11,17 +10,14 @@ import java.security.NoSuchAlgorithmException;
|
|||
|
||||
public class SHA256Hashing {
|
||||
|
||||
public static String HashWithJavaMessageDigest(final String originalString)
|
||||
throws NoSuchAlgorithmException {
|
||||
public static String HashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
final byte[] encodedhash = digest.digest(
|
||||
originalString.getBytes(StandardCharsets.UTF_8));
|
||||
final byte[] encodedhash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
|
||||
return bytesToHex(encodedhash);
|
||||
}
|
||||
|
||||
public static String HashWithGuava(final String originalString) {
|
||||
final String sha256hex = Hashing.sha256().hashString(
|
||||
originalString, StandardCharsets.UTF_8).toString();
|
||||
final String sha256hex = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
||||
return sha256hex;
|
||||
}
|
||||
|
||||
|
@ -30,11 +26,9 @@ public class SHA256Hashing {
|
|||
return sha256hex;
|
||||
}
|
||||
|
||||
public static String HashWithBouncyCastle(final String originalString)
|
||||
throws NoSuchAlgorithmException {
|
||||
public static String HashWithBouncyCastle(final String originalString) throws NoSuchAlgorithmException {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
final byte[] hash = digest.digest(
|
||||
originalString.getBytes(StandardCharsets.UTF_8));
|
||||
final byte[] hash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
|
||||
final String sha256hex = new String(Hex.encode(hash));
|
||||
return sha256hex;
|
||||
}
|
||||
|
@ -43,7 +37,8 @@ public class SHA256Hashing {
|
|||
StringBuffer hexString = new StringBuffer();
|
||||
for (int i = 0; i < hash.length; i++) {
|
||||
String hex = Integer.toHexString(0xff & hash[i]);
|
||||
if(hex.length() == 1) hexString.append('0');
|
||||
if (hex.length() == 1)
|
||||
hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
|
|
|
@ -19,12 +19,12 @@ public class FileVisitorImpl implements FileVisitor<Path> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) {
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class GenericsTest {
|
|||
// testing the generic method with Integer
|
||||
@Test
|
||||
public void givenArrayOfIntegers_thanListOfIntegersReturnedOK() {
|
||||
Integer[] intArray = {1, 2, 3, 4, 5};
|
||||
Integer[] intArray = { 1, 2, 3, 4, 5 };
|
||||
List<Integer> list = Generics.fromArrayToList(intArray);
|
||||
|
||||
assertThat(list, hasItems(intArray));
|
||||
|
@ -21,7 +21,7 @@ public class GenericsTest {
|
|||
// testing the generic method with String
|
||||
@Test
|
||||
public void givenArrayOfStrings_thanListOfStringsReturnedOK() {
|
||||
String[] stringArray = {"hello1", "hello2", "hello3", "hello4", "hello5"};
|
||||
String[] stringArray = { "hello1", "hello2", "hello3", "hello4", "hello5" };
|
||||
List<String> list = Generics.fromArrayToList(stringArray);
|
||||
|
||||
assertThat(list, hasItems(stringArray));
|
||||
|
@ -32,7 +32,7 @@ public class GenericsTest {
|
|||
// extend Number it will fail to compile
|
||||
@Test
|
||||
public void givenArrayOfIntegersAndNumberUpperBound_thanListOfIntegersReturnedOK() {
|
||||
Integer[] intArray = {1, 2, 3, 4, 5};
|
||||
Integer[] intArray = { 1, 2, 3, 4, 5 };
|
||||
List<Integer> list = Generics.fromArrayToListWithUpperBound(intArray);
|
||||
|
||||
assertThat(list, hasItems(intArray));
|
||||
|
|
|
@ -4,12 +4,10 @@ import org.junit.Test;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class SHA256HashingTest {
|
||||
|
||||
private static String originalValue = "abc123";
|
||||
private static String hashedValue =
|
||||
"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
|
||||
private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
|
||||
|
||||
@Test
|
||||
public void testHashWithJavaMessageDigest() throws Exception {
|
||||
|
|
|
@ -119,8 +119,7 @@ public class StringConversionTest {
|
|||
int afterConvCalendarDay = 03;
|
||||
Month afterConvCalendarMonth = Month.DECEMBER;
|
||||
int afterConvCalendarYear = 2007;
|
||||
LocalDateTime afterConvDate
|
||||
= new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str);
|
||||
LocalDateTime afterConvDate = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str);
|
||||
|
||||
assertEquals(afterConvDate.getDayOfMonth(), afterConvCalendarDay);
|
||||
assertEquals(afterConvDate.getMonth(), afterConvCalendarMonth);
|
||||
|
|
|
@ -66,6 +66,7 @@ public class AsyncEchoServer {
|
|||
AsyncEchoServer server = new AsyncEchoServer();
|
||||
server.runServer();
|
||||
}
|
||||
|
||||
public static Process start() throws IOException, InterruptedException {
|
||||
String javaHome = System.getProperty("java.home");
|
||||
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
|
||||
|
|
|
@ -81,7 +81,6 @@ public class AsyncEchoServer2 {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new AsyncEchoServer2();
|
||||
}
|
||||
|
|
|
@ -82,8 +82,7 @@ public class AsyncFileTest {
|
|||
public void givenPathAndContent_whenWritesToFileWithHandler_thenCorrect() throws IOException {
|
||||
String fileName = UUID.randomUUID().toString();
|
||||
Path path = Paths.get(fileName);
|
||||
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,StandardOpenOption.DELETE_ON_CLOSE);
|
||||
|
||||
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
buffer.put("hello world".getBytes());
|
||||
|
|
|
@ -20,7 +20,6 @@ public class JavaFileUnitTest {
|
|||
|
||||
private static final String TEMP_DIR = "src/test/resources/temp" + UUID.randomUUID().toString();
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
Files.createDirectory(Paths.get(TEMP_DIR));
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package org.baeldung.java.sorting;
|
||||
|
||||
public class Employee implements Comparable {
|
||||
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
private double salary;
|
||||
|
||||
public Employee(String name, int age, double salary) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class Employee implements Comparable {
|
|||
public void setSalary(double salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return ((Employee) obj).getName().equals(getName());
|
||||
|
@ -46,13 +46,10 @@ public class Employee implements Comparable {
|
|||
Employee e = (Employee) o;
|
||||
return getName().compareTo(e.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuffer()
|
||||
.append("(").append(getName())
|
||||
.append(getAge()).append(",")
|
||||
.append(getSalary()).append(")").toString();
|
||||
return new StringBuffer().append("(").append(getName()).append(getAge()).append(",").append(getSalary()).append(")").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue