Tag Archives: Example

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 »

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 = “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 »

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

IntelliJ IDEA – Find and Replace Text

Find and replace text on intellij idea by using (ctrl+R) or (ctrl+shift+R) for windows. Find and replace If you want to find and replace word on a file just use (Ctrl+R). But if you need to replace word in all file, you can use (Ctrl+Shift+R) shortcut.   For example search and replace in all file, see image below:… Read More »