1 /* -*-mode:java; c-basic-offset:2; -*- */
2 /*
3 Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8   1. Redistributions of source code must retain the above copyright notice,
9      this list of conditions and the following disclaimer.
10 
11   2. Redistributions in binary form must reproduce the above copyright
12      notice, this list of conditions and the following disclaimer in
13      the documentation and/or other materials provided with the distribution.
14 
15   3. The names of the authors may not be used to endorse or promote products
16      derived from this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 /*
30  * This program is based on zlib-1.1.3, so all credit should go authors
31  * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
32  * and contributors of zlib.
33  */
34 
35 package org.mathpiper.mpreduce.zip;
36 
37 import java.io.UnsupportedEncodingException;
38 
39 public class GZIPHeader implements Cloneable {
40   boolean text = false;
41   private boolean fhcrc = false;
42   long time;
43   int xflags;
44   int os = 255;
45   byte[] extra;
46   byte[] name;
47   byte[] comment;
48   int hcrc;
49   long crc;
50   boolean done = false;
51   long mtime = 0;
52 
setModifiedTime(long mtime)53   public void setModifiedTime(long mtime) {
54     this.mtime = mtime;
55   }
56 
getModifiedTime()57   public long getModifiedTime() {
58     return mtime;
59   }
60 
setOS(int os)61   public void setOS(int os) {
62     if((0<=os && os <=13) | os==255){
63       this.os=os;
64     }
65     else
66       throw new IllegalArgumentException("os: "+os);
67   }
68 
getOS()69   public int getOS(){
70     return os;
71   }
72 
setName(String name)73   public void setName(String name) {
74     try{
75       this.name=name.getBytes("ISO-8859-1");
76     }
77     catch(UnsupportedEncodingException e){
78       throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
79     }
80   }
81 
getName()82   public String getName(){
83     if(name==null) return "";
84     return new String(name);
85   }
86 
setComment(String comment)87   public void setComment(String comment) {
88     try{
89       this.comment=comment.getBytes("ISO-8859-1");
90     }
91     catch(UnsupportedEncodingException e){
92       throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
93     }
94   }
95 
getComment()96   public String getComment(){
97     if(comment==null) return "";
98     return new String(comment);
99   }
100 
setCRC(long crc)101   public void setCRC(long crc){
102     this.crc = crc;
103   }
104 
getCRC()105   public long getCRC(){
106     return crc;
107   }
108 
109 
110 /*
111   public Object clone() throws CloneNotSupportedException {
112     GZIPHeader gheader = (GZIPHeader)super.clone();
113     byte[] tmp;
114     if(gheader.extra!=null){
115       tmp=new byte[gheader.extra.length];
116       System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
117       gheader.extra = tmp;
118     }
119 
120     if(gheader.name!=null){
121       tmp=new byte[gheader.name.length];
122       System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
123       gheader.name = tmp;
124     }
125 
126     if(gheader.comment!=null){
127       tmp=new byte[gheader.comment.length];
128       System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
129       gheader.comment = tmp;
130     }
131 
132     return gheader;
133   }*/
134 }
135