I can write a simple compression algorithm for you in Java. The basic idea I will go with is to load the complete byte array into memory, search for any duplicated patterns in the array, and replace the duplicates with a small code (maybe 3 bytes) that points to a table location at the beginning of the byte array. The concept is basically the same as the PNG image compression algorithm, which is a lossless algorithm.
Unless this is for something like a homework assignment, you'll need a decompression algorithm to go along with the compression algorithm. Otherwise you'll be able to compress something but you won't be able to do anything with the compressed data.
My idea for a decompression algorithm would be to look at the table with all the code bytes and the bytes they replace and then replace the code bytes with the real bytes that should be there. Then the method or class with the decompression algorithm will send the actual byte data to whatever called it, leaving the table behind because it is not needed anymore.
Let me know if you're interested. Hope to hear from you soon. Regards,
Christopher (andrewscm)