1 jls.loader.provide('jls.util.zip.Inflater');
  2 
  3 jls.util.zip.Inflater = jls.lang.Class.create( /** @lends jls.util.zip.Inflater.prototype */
  4 {
  5     /**
  6      * Creates an inflater.
  7      *
  8      * @param {String} name The entry name.
  9      * @constructs
 10 	 * @class This class provides support for the ZLIB inflater.
 11      */
 12     initialize : function(wBits) {
 13         this._no = new _native.core.ZStream();
 14         this._wBits = (typeof wBits == 'undefined') ? -jls.util.zip.Inflater.MAX_WBITS : wBits;
 15         this._no.inflateInit(this._wBits);
 16         this._lastResult = _native.core.ZStream.Z_OK;
 17     },
 18     setDictionary : function(buffer) {
 19     	// TODO
 20     },
 21     /**
 22      * Sets the input.
 23      *
 24      * @param {jls.lang.ByteBuffer} buffer The buffer to inflate.
 25      */
 26     setInput : function(buffer) {
 27     	this._inBuf = buffer;
 28     },
 29     /**
 30      * Inflates the input into the specified buffer.
 31      *
 32      * @param {jls.lang.ByteBuffer} buffer The buffer to fill.
 33      * @returns {Number} The inflated byte count.
 34      */
 35     inflate : function(buffer) {
 36     	this._no.nextIn(this._inBuf.byteArray(), this._inBuf.offset(), this._inBuf.remaining());
 37     	this._no.nextOut(buffer.byteArray(), buffer.offset(), buffer.remaining());
 38     	this._lastResult = this._no.inflate();
 39         var count = buffer.remaining() - this._no.availOut();
 40         if (count > 0) {
 41             buffer.incrementPosition(count);
 42         }
 43         count = this._inBuf.remaining() - this._no.availIn();
 44         if (count > 0) {
 45         	this._inBuf.incrementPosition(count);
 46         }
 47         return count;
 48     },
 49     /**
 50      * Tells if the inflater needs a dictionary.
 51      *
 52      * @returns {Boolean} true if the inflater needs a dictionary.
 53      */
 54     needsDictionary : function() {
 55         return this._lastResult == _native.core.ZStream.Z_NEED_DICT;
 56     },
 57     /**
 58      * Tells if the inflater needs more input data.
 59      *
 60      * @returns {Boolean} true if the inflater needs more input data.
 61      */
 62     needsInput : function() {
 63         return this._inBuf.remaining() == 0;
 64     },
 65     getTotalIn : function() {
 66         return 0; // TODO
 67     },
 68     getTotalOut : function() {
 69         return 0; // TODO
 70     },
 71     reset : function() {
 72         this._no.inflateInit(this._wBits);
 73     },
 74     /**
 75      * Ends the inflater.
 76      *
 77      */
 78     end : function() {
 79     	this._no.inflateEnd();
 80     },
 81     /**
 82      * Tells if the inflater has finished to consume the input data.
 83      *
 84      * @returns {Boolean} true if the inflater has finished to consume the input data.
 85      */
 86     finished : function() {
 87         return this._lastResult == _native.core.ZStream.Z_NEED_DICT;
 88     }
 89 });
 90 
 91 Object.extend(jls.util.zip.Inflater, /** @lends jls.util.zip.Inflater */
 92 {
 93     MAX_WBITS : 15,
 94 });
 95