encodeURIComponent and decodeURIComponent in Java

A very common task when working with Webservices, is to encode/decode specific URI components, and for there is no direct API in Java for the same, it gets a difficult. Below is the code piece that I have been using for quite some time now. public static final String ALLOWED\_CHARS = "abcdefghijklmnopqrstuvwxyz"+ “ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"; public static String encodeURIComponent(String input) { if(StringUtils.isEmpty(input)) { return input; } int l = input.length(); StringBuilder o = new StringBuilder(l * 3); [Read More]

In-Place Character Array Compression

Problem: Given a character stream as an array, compress the characters in place appending the number of continuous characters by the numerical value and then the character. The array is terminated by a 0x00 character. Solution: Another classic interview problem which tests multiple skills in a single problem, namely, Conversion from integer to ascii - the number returned is a integral value which needs to be converted to ascii and then put in place in stream Skills with pointers (not the real pointers) when operating on an array The following JAVA code illustrates how to work up the given problem. [Read More]