-3

I have a problem. Currently I'm developing video game in java language. At this moment data files take about 100MB space even though game world is not big. I want to zip those text files ant protect them with password or some kind of encryption, but I can't find any good and free library for that.

Or maybe it's possible to pack data into some kind of archive without external libraries?

Update I tried to download Zip4j, but it shows that I need source attachments and I can't find in library's site.

  • http://docs.oracle.com/javase/6/docs/api/java/util/zip/package-summary.html ? – creinig Jun 05 '13 at 10:48
  • Have you looked at the java.util.zip package? I don't think password protection is supported, but you could potentially encrypt the whole zip file. – Jon Skeet Jun 05 '13 at 10:49
  • The JDK already has an API to read from/write to ZIP files. As to protecting the game data, why do you want to do that? – fge Jun 05 '13 at 10:49
  • Search before posting a question, check: http://stackoverflow.com/questions/127001/whats-a-good-compression-library-for-java – Khaled.K Jun 05 '13 at 10:49
  • Your answer is here: http://www.mkyong.com/java/how-to-compress-files-in-zip-format/ – Parth Soni Jun 05 '13 at 10:50
  • Can I extract or zip specific file with it? – user2055675 Jun 05 '13 at 10:50
  • Not that I want to protect my game data, I just want to make those files not so easily accessible, that it won't be possible to edit them with simple notepad. And they take a lot of space, so that's why I want to compress them. – user2055675 Jun 05 '13 at 10:53

3 Answers3

0

You can use apache Compress Library for compressing file. http://commons.apache.org/proper/commons-compress/

you can also compress using zip libraries at java.util.zip

Dijesh
  • 334
  • 2
  • 11
0

Java provides several features that compress the data such as: GZIPInputStream and GZIPOutputStream

you can also use zip with ZipFile (java.util.zip)

For encryption you could write your own FilterOutputStream and FilterInputStream where you use a Cipher to encrypt it.

Those features are working all without external libraries.

0

You can compress yor game data with the facilities provided by the JDK:

  • java.util.ZipFile and related classes to handle normal zip files
  • java.util.GZIPInput/OutputStream to compress data directly (no "files catalog" concept, just a blob).
  • java.util.DeflaterInput/OutputStream (like GZIP)

There exists a multitude of 3rd-Party compression classes. I personally like XZ for Java, because it provides excellent compression ratios and is easy to use through the standard stream interface (http://tukaani.org/xz/java.html).

For encryption, there are encrypting streams that are used just like the compression streams. Beware that anybody will be able to extract the "key" from your game files with a little knowledge and patience if they really want to.

Durandal
  • 19,919
  • 4
  • 36
  • 70