The Apache Commons Lang library could help you to determine the running OS type. Here is an simple example.
pom.xml
...
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
...
Continue reading Java – Determine if the running OS is Windows, Mac or Linux →
Sometimes we want to build a executable jar which contains all the dependencies. In this case we could make use of the maven-assembly-plugin which help us to package a jar-with-dependencies artifact during the Maven package phase. Let’s refer to the simple Maven project we did before.
1. First let’s introduce a dependency to our project. Say, we want to make use of the Apache Commons – Commons Lang to check the empty string. Edit the src/main/java/info/ykyuen/eureka/Addition.java as follow.
Continue reading Maven – Package the jar file with dependencies →
The Apache Commons Codec could help you to generate the MD5 of a file with just one command. Download the lib @ Download Commons Codec. If you want to use Maven, include the following dependency in the pom.xml. Continue reading Java – Get MD5 Checksum of a File →
If you don’t want to use Apache Commons which i show you in previous post. You can use the following static function to check if a string is empty.
public static boolean notEmpty(String s) {
return (s != null && s.length() > 0);
}
Done =)
Reference:
Apache Commons IO provides the StringUtils Class for checking empty string in Java.
Add the Apache Commons Lang in the pom.xml. Continue reading Java – Check Empty String with Apache Commons →
If you want to convert a String into InputStream, you can use the following piece of code.
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
public class ConvertStringToInputStream {
public static void main(String[] args) {
try {
// Convert the String into InputStream
String eurekaUrl = "https://ykyuen.wordpress.com";
InputStream is = new ByteArrayInputStream(eurekaUrl.getBytes("UTF-8"));
// Use Apache Commons IO to get the content of the InputStream
System.out.println(IOUtils.toString(is, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Continue reading Java – Convert String to InputStream →
Recently, i got a support case and it is about the inconsistency of the content length declared in the http header and the actual content length of the http request.
So i modified an existing program which will get the http request and manipulate it. I add some codes such that it will get the request inputStream and count it byte by byte before the request manipulation.
Continue reading Java – Get the content of inputStream from HttpServletRequest →
Dream BIG and go for it =)