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 =; ArrayList<String> arrayListCollection =; Set<String> setCollection =; HashSet<String> hashSetCollection =; TreeSet<String> treeSetCollection =; LinkedList<String> linkedListCollection =; LinkedHashSet<String> linkedHashSetCollection =; ArrayDeque<String> arrayDequeCollection =… Read More »

REST API Return Image With Spring

How to create rest controller for return image file? Here is the code for create image rest API with spring: @GetMapping( value = “/img”, produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_PNG_VALUE}) public ResponseEntity getImageAsResource() { HttpHeaders headers = new HttpHeaders(); String home = System.getProperty(“user.home”); File f = new File(home + File.separator + “Desktop” + File.separator + “image.jpg”); Resource resource =… Read More »

Download Image From URL In Java

Simple way to download image from url in java is like this: String source = “”; 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!=( { out.write(buf, 0, n); } out.close(); in.close(); byte[] response = out.toByteArray(); String home… Read More »

JAVA – How to Split an ArrayList in Multiple Small ArrayLists

This is a sample how to split an arraylist in multiple small arraylists in java code. How to Split an ArrayList in Java List<List<String>> batchData = new ArrayList<>(); int size = 1000; for (int start = 0; start < data.size(); start += size) { int end = Math.min(start + size, data.size()); List<String> sublist = data.subList(start, end); batchData.add(sublist); }… Read More »

String to Byte Array in Java

To convert string to byte array in java you can use “getBytes” function. For example: “your string”.getBytes() String to Byte Array in Java See image below: That is how to convert string to byte array in java. In this example i’m using: IntelliJ IDEA Spring Boot Maven Other convert topics