This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Add the Given Dependency | |
<dependency> | |
<groupId>com.amazonaws</groupId> | |
<artifactId>aws-java-sdk</artifactId> | |
<version>1.11.163</version> | |
</dependency> | |
*/ | |
import java.io.IOException; | |
import java.io.InputStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To Kill Port On Linux | |
========================== | |
kill $(lsof -t -i:8080) | |
To Move File to Other Location | |
============================= | |
mv command main options: | |
option description | |
mv -f force move by overwriting destination file without prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] compress(BufferedImage image, float scale) throws IOException { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); | |
ImageWriter writer = writers.next(); | |
ImageWriteParam param = writer.getDefaultWriteParam(); | |
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); | |
param.setCompressionQuality(scale); | |
ImageOutputStream ios = ImageIO.createImageOutputStream(baos); | |
writer.setOutput(ios); | |
writer.write(null, new IIOImage(image, null, null), param); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to write to raw string with jackson 2? | |
String result =""; | |
try { | |
result = objectMapper.writeValueAsString(objectMapper.writeValueAsString(list)); | |
} catch (JsonProcessingException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
System.out.println(result); | |
//Output like this "[{\"id\":1,\"name\":\"Dinesh\",\"age\":20},{\"id\":2,\"name\":\"Kamal\",\"age\":15},{\"id\":3,\"name\":\"Vijay\",\"age\":25},{\"id\":4,\"name\":\"Dinesh\",\"age\":30},{\"id\":5,\"name\":\"Dinesh\",\"age\":18}]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#======================== Composite Key Group By ================================= | |
Function<UserInfo, List<Object>> compositeKey = userInfo -> | |
Arrays.<Object>asList(userInfo.getName(), userInfo.getId()); | |
Map<Object, List<UserInfo>> map = userInfos.stream().collect(Collectors.groupingBy(compositeKey, Collectors.toList())); | |
#=================================================== | |
Integer arr[] = { 5, 5, 1, 2, 3, 2, 1, 1 }; | |
List<Integer> data = Stream.of(arr).collect(Collectors.toList()); | |
System.out.println("Move Data into List"+data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Remove duplicate prime number in a list | |
*/ | |
for (int i = 0; i < list.size(); i++) { | |
if (Collections.frequency(list, list.get(i)) > 1) { | |
final Integer number = list.get(i); | |
if(LongStream.range(2, (long) Math.ceil(Math.sqrt(number + 1))).noneMatch(x -> number % x == 0)) | |
{ | |
list.remove(i); | |
} |
NewerOlder