Piotr Gabryanczyk’s Blog

Java, Refactoring, AOP, Spring, DDD, TDD, etc.

  • Blogroll

    • I have joined Anti-IF Campaign

Archive for June, 2009

How to download JavaDocs or sources in Maven 2?

Posted by Piotr Gabryanczyk on June 25, 2009


You want to download javadocs for your depenencies into local repository to be able to use them ie. in IntelliJ.


mvn dependency:resolve -Dclassifier=javadoc
mvn dependency:resolve -Dclassifier=sources


Posted in java | Tagged: | 4 Comments »

Howto compress or decompress byte array in Java?

Posted by Piotr Gabryanczyk on June 8, 2009

Check this class out:


import java.io.*;
import java.util.zip.*;

import org.apache.commons.io.IOUtils;

public class Compressor{
    public static byte[] compress(byte[] content){
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        } catch(IOException e){
            throw new RuntimeException(e);
        System.out.printf("Compression ratio %f\n", (1.0f * content.length/byteArrayOutputStream.size()));
        return byteArrayOutputStream.toByteArray();

    public static byte[] decompress(byte[] contentBytes){
        ByteArrayOutputStream out = new ByteArrayOutputStream();
            IOUtils.copy(new GZIPInputStream(new ByteArrayInputStream(contentBytes)), out);
        } catch(IOException e){
            throw new RuntimeException(e);
        return out.toByteArray();

    public static boolean notWorthCompressing(String contentType){
        return contentType.contains("jpeg")
                || contentType.contains("pdf")
                || contentType.contains("zip")
                || contentType.contains("mpeg")
                || contentType.contains("avi");

Dependencies: Apache commons-io.jar

Posted in Uncategorized | 12 Comments »