Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...

Compressing Streams: Direct Inflater, read and inflate the data Java code example - Click here to copy ->>>

   Can't find what you're looking for? Try our search:

Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run!

/* Title: Hardcore Java
* Title: Java I/O
* Second Edition: May 2006
* ISBN 10: 0-596-52750-0
* ISBN 13: 9780596527501


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

public class DirectInflater {

  public static void main(String[] args) {
    Inflater inf = new Inflater();
    byte[] input = new byte[1024];
    byte[] output = new byte[1024];

    for (int i = 0; i < args.length; i++) {
      try {
        if (!args[i].endsWith(DirectDeflater.DEFLATE_SUFFIX)) {
          System.err.println(args[i] + " does not look like a deflated file");
        FileInputStream fin = new FileInputStream(args[i]);   
        FileOutputStream fout = new FileOutputStream(args[i].substring(0,
         args[i].length() - DirectDeflater.DEFLATE_SUFFIX.length()));
        while (true) { // Read and inflate the data.     

          // Fill the input array.
          int numRead = fin.read(input);
          if (numRead != -1) { // End of stream, finish inflating.
            inf.setInput(input, 0, numRead);
          } // end if
          // Inflate the input.
          int numDecompressed = 0;
          while ((numDecompressed = inf.inflate(output, 0, output.length))
           != 0) {
            fout.write(output, 0, numDecompressed);
          // At this point inflate() has returned 0.
          // Let's find out why.
          if (inf.finished()) { // all done
          else if (inf.needsDictionary()) { // We don't handle dictionaries.
            System.err.println("Dictionary required! bailing...");
          else if (inf.needsInput()) {
        } // end while
        // Close up and get ready for the next file.
      } // end try
      catch (IOException ex) {System.err.println(ex);}
      catch (DataFormatException ex) {
        System.err.println(args[i] + " appears to be corrupt");     
      } // end catch


The list of classes which were used on this page you can find below. The links to Java API contain official SUN documentation about all used classes.







[ Go Back ]

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy