required standard open options for creating or replacing a file

I just found a bug on my own code.

final FileChannel fileChannel =
    StandardOpenOption.CREATE, // create if not exist
    StandardOpenOption.WRITE // i'm gonna write on

Above code seemed working, but when I tried to replace a bigger file with a smaller one, the file size remains and the only leading(?) portion of file contents replaced.

final FileChannel fileChannel =
    StandardOpenOption.TRUNCATE_EXISTING, // truncate the file!!!

java_home environment variable





$ ls -l /Library/Java/JavaVirtualMachines/


$ /usr/libexec/java_home

$ /usr/libexec/java_home -v 1.8

$ /usr/libexec/java_home -v 1.7


$ cat ~/.profile
export JAVA7_HOME=$(/usr/libexec/java_home -v 1.7)
export JAVA8_HOME=$(/usr/libexec/java_home -v 1.8)

$ echo $JAVA7_HOME

$ echo $JAVA8_HOME

$ echo $JAVA_HOME



See installing latest oracle jdk in old ubuntu.

mapping a milliseconds parameter directly into a date instance in jax-rs

public void myResource(
    final Long milliseconds) {

    final Date date = new Date(milliseconds);

I wrote some codes using ParamConverter and ParamConverterProvider.
And now I can do like this.

public void myResource(
    final Date date) {


Here are 3 classes for this.

curl을 이용해 바이너리 파일 올릴 때 주의할 점

curl을 이용해서 PUT 메서드를 테스트하던 중 데이터가 이상하게 올라가는 현상을 발견했습니다.

$ curl -X PUT -H "Content-Type: image/jpeg" --data @a.jpg http://...

올라가긴 잘 올라가는 것 같은데 브라우저로 이미지를 불러보면 안보입니다.
검색결과, --data 옵션은 --data-ascii와 같다고 하는 군요.
다음과 같이 했더니 잘 올라갑니다.

$ curl -X PUT -H "Content-Type: image/jpeg" --data-binary @a.jpg http://...

changing a nullable milliseconds to a nullable date using optional.

public Date toDate(@Nullable Long millis) {
    //return millis == null ? null : new Date(millis);
    return Optional.ofNullable(millis).map(Date::new).orElse(null);

Returning an Optional rather than a nullable Date instance is a better idea.

public Optional<Date> toDate(@Nullable Long millis) {
    return Optional.ofNullable(millis).map(Date::new);

selecting javac with maven in command line

I just found that some of my company’s legacy codes doesn’t compile with JDK 8. And I just tried selecting the javac executable in command line rather than changing maven-compiler-plugin‘s configuration.

$ mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable=/path/to/jdk7/javac clean package

Note that, as documented, maven.compiler.fork parameter must be true.

suppressing application.wadl with jax-rs

public class EpdResourcesRequestFilter implements ContainerRequestFilter {

    public void filter(final ContainerRequestContext requestContext)
        throws IOException {

        // abort any request whose uri includes ".wadl" with 404
        if (requestContext.getUriInfo().getPath().contains(".wadl")) {