OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [java/] [util/] [zip/] [GZIPOutputStream.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* GZIPOutputStream.java - Create a file in gzip format
2
   Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package java.util.zip;
39
 
40
import java.io.IOException;
41
import java.io.OutputStream;
42
 
43
/**
44
 * This filter stream is used to compress a stream into a "GZIP" stream.
45
 * The "GZIP" format is described in RFC 1952.
46
 *
47
 * @author John Leuner
48
 * @author Tom Tromey
49
 * @since JDK 1.1
50
 */
51
 
52
/* Written using on-line Java Platform 1.2 API Specification
53
 * and JCL book.
54
 * Believed complete and correct.
55
 */
56
 
57
public class GZIPOutputStream extends DeflaterOutputStream
58
{
59
  /**
60
   * CRC-32 value for uncompressed data
61
   */
62
  protected CRC32 crc;
63
 
64
  /**
65
   * Creates a GZIPOutputStream with the default buffer size
66
   *
67
   * @param out The stream to read data (to be compressed) from
68
   *
69
   */
70
  public GZIPOutputStream(OutputStream out) throws IOException
71
  {
72
    this(out, 4096);
73
  }
74
 
75
  /**
76
   * Creates a GZIPOutputStream with the specified buffer size
77
   *
78
   * @param out The stream to read compressed data from
79
   * @param size Size of the buffer to use
80
   */
81
  public GZIPOutputStream(OutputStream out, int size) throws IOException
82
  {
83
    super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
84
    crc = new CRC32();
85
    put2(GZIPInputStream.GZIP_MAGIC);
86
    out.write(GZIPInputStream.Z_DEFLATED);
87
    // No flags for now.
88
    out.write(0);
89
    // No time either.
90
    put2(0);
91
    put2(0);
92
    // No xflags either.
93
    out.write(0);
94
    // FIXME: unknown OS.
95
    out.write(255);
96
  }
97
 
98
  public synchronized void write(int bval) throws IOException
99
  {
100
    super.write(bval);
101
    // super.write(int) eventually calls our write(byte[],int,int),
102
    // so updating the CRC here is wrong.
103
    // crc.update(bval);
104
  }
105
 
106
  public synchronized void write(byte[] buf) throws IOException
107
  {
108
    write(buf, 0, buf.length);
109
  }
110
 
111
  public synchronized void write(byte[] buf, int off, int len)
112
    throws IOException
113
  {
114
    super.write(buf, off, len);
115
    crc.update(buf, off, len);
116
  }
117
 
118
  /**
119
   * Writes remaining compressed output data to the output stream
120
   * and closes it.
121
   */
122
  public void close() throws IOException
123
  {
124
    finish();
125
    out.close();
126
  }
127
 
128
  public void finish() throws IOException
129
  {
130
    super.finish();
131
    put4((int) crc.getValue());
132
    put4(def.getTotalIn());
133
  }
134
 
135
  private final void put2(int i) throws IOException
136
  {
137
    out.write(i);
138
    out.write(i >> 8);
139
  }
140
 
141
  private final void put4 (int i) throws IOException
142
  {
143
    out.write(i);
144
    out.write(i >> 8);
145
    out.write(i >> 16);
146
    out.write(i >> 24);
147
  }
148
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.