KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > zlib > ZlibInputStream


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Nam Nguyen
28  */

29
30 package com.caucho.quercus.lib.zlib;
31
32 import com.caucho.quercus.QuercusModuleException;
33 import com.caucho.quercus.lib.file.BinaryInput;
34 import com.caucho.quercus.lib.file.ReadStreamInput;
35 import com.caucho.vfs.*;
36
37 import java.io.IOException JavaDoc;
38
39 /**
40  * Input from a compressed stream.
41  *
42  *
43  */

44 public class ZlibInputStream extends ReadStreamInput
45 {
46   private BinaryInput _in;
47   private GZInputStream _gzIn;
48   
49   public ZlibInputStream(BinaryInput in) throws IOException JavaDoc
50   {
51     init(in);
52   }
53
54   protected void init(BinaryInput in)
55     throws IOException JavaDoc
56   {
57     _in = in;
58
59     _gzIn = new GZInputStream(in.getInputStream());
60     ReadStream rs = new ReadStream(new VfsStream(_gzIn, null));
61
62     init(rs);
63   }
64
65   /**
66    * Opens a new copy.
67    */

68   public BinaryInput openCopy()
69     throws IOException JavaDoc
70   {
71     return new ZlibInputStream(_in.openCopy());
72   }
73
74   /**
75    * Sets the position.
76    */

77   public boolean setPosition(long offset)
78   {
79     try {
80       BinaryInput newIn = _in.openCopy();
81       
82       _gzIn.close();
83       getInputStream().close();
84
85       init(newIn);
86
87       if (offset > 0)
88         skip(offset);
89
90       return true;
91     } catch (IOException JavaDoc e) {
92       throw new QuercusModuleException(e);
93     }
94   }
95
96   public String JavaDoc toString()
97   {
98     return "ZlibInputStream[]";
99   }
100 }
101
Popular Tags