162 // last deflater buffer. Fit trailer at the end 163 writeTrailer(buf, len); 164 len = len + TRAILER_SIZE; 165 out.write(buf, 0, len); 166 return; 167 } 168 if (len > 0) 169 out.write(buf, 0, len); 170 } 171 // if we can't fit the trailer at the end of the last 172 // deflater buffer, we write it separately 173 byte[] trailer = new byte[TRAILER_SIZE]; 174 writeTrailer(trailer, 0); 175 out.write(trailer); 176 } 177 } 178 179 /* 180 * Writes GZIP member header. 181 */ 182 183 private final static byte[] header = { 184 (byte) GZIP_MAGIC, // Magic number (short) 185 (byte)(GZIP_MAGIC >> 8), // Magic number (short) 186 Deflater.DEFLATED, // Compression method (CM) 187 0, // Flags (FLG) 188 0, // Modification time MTIME (int) 189 0, // Modification time MTIME (int) 190 0, // Modification time MTIME (int) 191 0, // Modification time MTIME (int) 192 0, // Extra flags (XFLG) 193 0 // Operating system (OS) 194 }; 195 196 private void writeHeader() throws IOException { 197 out.write(header); 198 } 199 200 /* 201 * Writes GZIP member trailer to a byte array, starting at a given 202 * offset. 203 */ 204 private void writeTrailer(byte[] buf, int offset) throws IOException { 205 writeInt((int)crc.getValue(), buf, offset); // CRC-32 of uncompr. data 206 writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes 207 } 208 209 /* 210 * Writes integer in Intel byte order to a byte array, starting at a 211 * given offset. 212 */ 213 private void writeInt(int i, byte[] buf, int offset) throws IOException { 214 writeShort(i & 0xffff, buf, offset); 215 writeShort((i >> 16) & 0xffff, buf, offset + 2); 216 } 217 | 162 // last deflater buffer. Fit trailer at the end 163 writeTrailer(buf, len); 164 len = len + TRAILER_SIZE; 165 out.write(buf, 0, len); 166 return; 167 } 168 if (len > 0) 169 out.write(buf, 0, len); 170 } 171 // if we can't fit the trailer at the end of the last 172 // deflater buffer, we write it separately 173 byte[] trailer = new byte[TRAILER_SIZE]; 174 writeTrailer(trailer, 0); 175 out.write(trailer); 176 } 177 } 178 179 /* 180 * Writes GZIP member header. 181 */ 182 private void writeHeader() throws IOException { 183 out.write(new byte[] { 184 (byte) GZIP_MAGIC, // Magic number (short) 185 (byte)(GZIP_MAGIC >> 8), // Magic number (short) 186 Deflater.DEFLATED, // Compression method (CM) 187 0, // Flags (FLG) 188 0, // Modification time MTIME (int) 189 0, // Modification time MTIME (int) 190 0, // Modification time MTIME (int) 191 0, // Modification time MTIME (int) 192 0, // Extra flags (XFLG) 193 0 // Operating system (OS) 194 }); 195 } 196 197 /* 198 * Writes GZIP member trailer to a byte array, starting at a given 199 * offset. 200 */ 201 private void writeTrailer(byte[] buf, int offset) throws IOException { 202 writeInt((int)crc.getValue(), buf, offset); // CRC-32 of uncompr. data 203 writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes 204 } 205 206 /* 207 * Writes integer in Intel byte order to a byte array, starting at a 208 * given offset. 209 */ 210 private void writeInt(int i, byte[] buf, int offset) throws IOException { 211 writeShort(i & 0xffff, buf, offset); 212 writeShort((i >> 16) & 0xffff, buf, offset + 2); 213 } 214 |