/[classpath]/classpath/java/util/zip/InflaterInputStream.java
ViewVC logotype

Diff of /classpath/java/util/zip/InflaterInputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by cbj, Sat Feb 15 13:55:08 2003 UTC revision 1.6 by mkoch, Wed Jun 11 18:00:09 2003 UTC
# Line 49  import java.io.IOException; Line 49  import java.io.IOException;
49   * as the <code>GZIPInputStream</code>.   * as the <code>GZIPInputStream</code>.
50   *   *
51   * @author John Leuner   * @author John Leuner
52   * @since JDK 1.1   * @since 1.1
53   */   */
54    public class InflaterInputStream extends FilterInputStream
55  public class InflaterInputStream extends FilterInputStream {  {
   
   //Variables  
   
56    /**    /**
57     * Decompressor for this filter     * Decompressor for this filter
58     */     */
   
59    protected Inflater inf;    protected Inflater inf;
60    
61    /**    /**
62     * Byte array used as a buffer     * Byte array used as a buffer
63     */     */
   
64    protected byte[] buf;    protected byte[] buf;
65    
66    /**    /**
67     * Size of buffer       * Size of buffer  
68     */     */
   
69    protected int len;    protected int len;
70    
71    
72    //We just use this if we are decoding one byte at a time with the read() call    /*
73       * We just use this if we are decoding one byte at a time with the read() call
74       */
75    private byte[] onebytebuffer = new byte[1];    private byte[] onebytebuffer = new byte[1];
76    
   //Constructors  
   
   
77    /**    /**
78     * Create an InflaterInputStream with the default decompresseor     * Create an InflaterInputStream with the default decompresseor
79     * and a default buffer size.     * and a default buffer size.
80     *     *
81     * @param in the InputStream to read bytes from     * @param in the InputStream to read bytes from
82     */     */
   
83    public InflaterInputStream(InputStream in)    public InflaterInputStream(InputStream in)
84    {    {
85      this(in, new Inflater(), 4096);      this(in, new Inflater(), 4096);
# Line 101  public class InflaterInputStream extends Line 92  public class InflaterInputStream extends
92     * @param in the InputStream to read bytes from     * @param in the InputStream to read bytes from
93     * @param inf the decompressor used to decompress data read from in     * @param inf the decompressor used to decompress data read from in
94     */     */
   
95    public InflaterInputStream(InputStream in, Inflater inf)    public InflaterInputStream(InputStream in, Inflater inf)
96    {    {
97      this(in, inf, 4096);      this(in, inf, 4096);
# Line 115  public class InflaterInputStream extends Line 105  public class InflaterInputStream extends
105     * @param inf the decompressor used to decompress data read from in     * @param inf the decompressor used to decompress data read from in
106     * @param size size of the buffer to use     * @param size size of the buffer to use
107     */     */
   
108    public InflaterInputStream(InputStream in, Inflater inf, int size)    public InflaterInputStream(InputStream in, Inflater inf, int size)
109    {    {
110      super(in);      super(in);
# Line 127  public class InflaterInputStream extends Line 116  public class InflaterInputStream extends
116      buf = new byte[size]; //Create the buffer      buf = new byte[size]; //Create the buffer
117    }    }
118    
   //Methods  
   
119    /**    /**
120     * Returns 0 once the end of the stream (EOF) has been reached.     * Returns 0 once the end of the stream (EOF) has been reached.
121     * Otherwise returns 1.     * Otherwise returns 1.
122     */     */
   
123    public int available() throws IOException    public int available() throws IOException
124    {    {
125      return inf.finished() ? 0 : 1;      return inf.finished() ? 0 : 1;
# Line 145  public class InflaterInputStream extends Line 131  public class InflaterInputStream extends
131    public void close() throws IOException    public void close() throws IOException
132    {    {
133      in.close();      in.close();
134        in = null;
135    }    }
136    
137    /**    /**
# Line 152  public class InflaterInputStream extends Line 139  public class InflaterInputStream extends
139     */     */
140    protected void fill() throws IOException    protected void fill() throws IOException
141    {    {
142        if (in == null)
143          throw new ZipException ("InflaterInputStream is closed");
144        
145      len = in.read(buf, 0, buf.length);      len = in.read(buf, 0, buf.length);
146    
147      if (len < 0)      if (len < 0)
148        throw new ZipException("Deflated stream ends early.");        throw new ZipException("Deflated stream ends early.");
149        
150      inf.setInput(buf, 0, len);      inf.setInput(buf, 0, len);
151    }    }
152    
# Line 167  public class InflaterInputStream extends Line 158  public class InflaterInputStream extends
158    public int read() throws IOException    public int read() throws IOException
159    {    {
160      int nread = read(onebytebuffer, 0, 1); //read one byte      int nread = read(onebytebuffer, 0, 1); //read one byte
161        
162      if (nread > 0)      if (nread > 0)
163        return onebytebuffer[0] & 0xff;        return onebytebuffer[0] & 0xff;
164        
165      return -1;      return -1;
166    }    }
167    
168    /**    /**
169     * Decompresses data into the byte array     * Decompresses data into the byte array
170     *     *
    *  
171     * @param b the array to read and decompress data into     * @param b the array to read and decompress data into
172     * @param off the offset indicating where the data should be placed     * @param off the offset indicating where the data should be placed
173     * @param len the number of bytes to decompress     * @param len the number of bytes to decompress
174     */     */
175    public int read(byte[] b, int off, int len) throws IOException    public int read(byte[] b, int off, int len) throws IOException
176    {    {
   
177      if (len == 0) return 0;      if (len == 0) return 0;
178    
179      for (;;)      for (;;)
# Line 201  public class InflaterInputStream extends Line 192  public class InflaterInputStream extends
192            return count;            return count;
193                    
194          if (inf.needsDictionary())          if (inf.needsDictionary())
195            throw new ZipException("Need a dictionary");              | inf.finished())
         else if (inf.finished())  
196            return -1;            return -1;
197          else if (inf.needsInput())          else if (inf.needsInput())
198            fill();            fill();
# Line 216  public class InflaterInputStream extends Line 206  public class InflaterInputStream extends
206     *     *
207     * @param n number of bytes to skip     * @param n number of bytes to skip
208     */     */
   
209    public long skip(long n) throws IOException    public long skip(long n) throws IOException
210    {    {
211      if (n < 0)      if (n < 0)
# Line 239  public class InflaterInputStream extends Line 228  public class InflaterInputStream extends
228    {    {
229      return false;      return false;
230    }    }
   
   /**  
    *  Throws an exception.  
    *  
    * @see #markSupported  
    *  
    * @param readlimit The parameter passed to <code>in.mark(int)</code>  
    */  
   public void mark(int readlimit)  
   {  
   
   }  
   
   /**  
    *  Throws an exception.  
    *  
    * @see #markSupported  
    *  
    * @exception IOException If an error occurs  
    */  
   public void reset() throws IOException  
   {  
     throw new IOException("mark/reset not supported by " + getClass());  
   }  
231  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26