Tag Archives: Programming Language

AsyncRequestTimeoutException in Spring Boot

If you using asynchronous programming with observable streams in spring boot, i suggest you to setup async request timeout because default async request timeout in spring boot 2.0 is 10 second. You will got an exception (AsyncRequestTimeoutException) when request is more than 10 second. AsyncRequestTimeout My suggestion is 60s or 120s (s mean second) : spring.mvc.async.request-timeout=60s That is how to… Read More »

Convert Array to List In Java 8

In java 8 you can easily to convert array to list with stream. Convert Array to List In Java 8 For example: String[] array = new String[10]; List<String> listCollection = Arrays.stream(array).collect(Collectors.toList()); ArrayList<String> arrayListCollection = Arrays.stream(array).collect(Collectors.toCollection(ArrayList::new)); Set<String> setCollection = Arrays.stream(array).collect(Collectors.toSet()); HashSet<String> hashSetCollection = Arrays.stream(array).collect(Collectors.toCollection(HashSet::new)); TreeSet<String> treeSetCollection = Arrays.stream(array).collect(Collectors.toCollection(TreeSet::new)); LinkedList<String> linkedListCollection = Arrays.stream(array).collect(Collectors.toCollection(LinkedList::new)); LinkedHashSet<String> linkedHashSetCollection = Arrays.stream(array).collect(Collectors.toCollection(LinkedHashSet::new)); ArrayDeque<String> arrayDequeCollection =… Read More »

Download Image From URL In Java

Simple way to download image from url in java is like this: String source = “https://www.google.co.id/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png”; URL url = new URL(source); URLConnection urlConnection = url.openConnection(); InputStream in = urlConnection.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n = 0; while (-1!=(n=in.read(buf))) { out.write(buf, 0, n); } out.close(); in.close(); byte[] response = out.toByteArray(); String home… Read More »