001/** 002 * Java Web Archive Toolkit - Software to read and validate ARC, WARC 003 * and GZip files. (http://jwat.org/) 004 * Copyright 2011-2012 Netarkivet.dk (http://netarkivet.dk/) 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.jwat.gzip; 019 020import java.util.Map; 021import java.util.TreeMap; 022 023/** 024 * Class containing all relevant GZip constants and structures. 025 * Including but not limited to compression methods, flags 026 * and known Operating Systems. 027 * Also includes non statically initialized structures for validation. 028 * 029 * @author nicl 030 */ 031public class GzipConstants { 032 033 /** 034 * This utility class does not require instantiation. 035 */ 036 protected GzipConstants() { 037 } 038 039 /** GZip header magic number. */ 040 public static final byte[] GZIP_MAGIC_HEADER = new byte[] {(byte)0x1f, (byte)0x8b}; 041 042 /** GZip header magic number. */ 043 public static final int GZIP_MAGIC = 0x8b1f; 044 045 /* 046 * Compression. 047 */ 048 049 /** Friendly name for the deflate compression method. */ 050 public static final String CM_STRING_DEFLATE = "deflate"; 051 052 /** Deflate compression method. */ 053 public static final int CM_DEFLATE = 8; 054 055 /** Maximum compression flag bit. */ 056 public static final int DEFLATE_XFL_MAXIMUM_COMPRESSION = 2; 057 /** Fastest compression flag bit. */ 058 public static final int DEFLATE_XFL_FASTEST_COMPRESSION = 4; 059 /** Compression flag bit mask. */ 060 public static final int DEFLATE_XFL_COMPRESSION_MASK = 061 DEFLATE_XFL_MAXIMUM_COMPRESSION + DEFLATE_XFL_FASTEST_COMPRESSION; 062 /** Reserved compression bits mask. */ 063 public static final int DEFLATE_XLF_RESERVED = 1 + 8 + 16 + 32 + 64 + 128; 064 065 /* 066 * File header flags. 067 */ 068 069 /** Extra text flag. */ 070 public static final int FLG_FTEXT = 1; 071 /** Header CRC flag. */ 072 public static final int FLG_FHCRC = 2; 073 /** Extra field flag. */ 074 public static final int FLG_FEXTRA = 4; 075 /** File name flag. */ 076 public static final int FLG_FNAME = 8; 077 /** File comment flag. */ 078 public static final int FLG_FCOMMENT = 16; 079 /** Reserved flag bits mask. */ 080 public static final int FLG_FRESERVED = 224; 081 082 /** FAT filesystem OS name. */ 083 public static final String OS_STRING_FAT_FS = "FAT filesystem (MS-DOS, OS/2, NT/Win32)"; 084 /** Amiga OS name. */ 085 public static final String OS_STRING_AMIGA = "Amiga"; 086 /** VMS OS name. */ 087 public static final String OS_STRING_VMS = "VMS (or OpenVMS)"; 088 /** Unix OS name. */ 089 public static final String OS_STRING_UNIX = "Unix"; 090 /** VM/CMS OS name. */ 091 public static final String OS_STRING_VM = "VM/CMS"; 092 /** Atari TOS OS name. */ 093 public static final String OS_STRING_ATARI = "Atari TOS"; 094 /** HPFS filesystem OS name. */ 095 public static final String OS_STRING_HPFS_FS = "HPFS filesystem (OS/2, NT)"; 096 /** Macintosh OS name. */ 097 public static final String OS_STRING_MACINTOSH = "Macintosh"; 098 /** Z-System OS name. */ 099 public static final String OS_STRING_Z_SYSTEM = "Z-System"; 100 /** CP/M OS name. */ 101 public static final String OS_STRING_CPM = "CP/M"; 102 /** TOPS-20 OS name. */ 103 public static final String OS_STRING_TOPS_20 = "TOPS-20"; 104 /** NTFS filesystem OS name. */ 105 public static final String OS_STRING_NTFS_FS = "NTFS filesystem (NT)"; 106 /** QDOS OS name. */ 107 public static final String OS_STRING_QDOS = "QDOS"; 108 /** Acorn OS name. */ 109 public static final String OS_STRING_ACORN = "Acorn RISCOS"; 110 /** Unknown OS name. */ 111 public static final String OS_STRING_UNKNOWN = "unknown"; 112 113 /** FAT filesystem OS value. */ 114 public static final int OS_FAT_FS = 0; 115 /** Amiga OS value. */ 116 public static final int OS_AMIGA = 1; 117 /** VMS OS value. */ 118 public static final int OS_VMS = 2; 119 /** Unix OS value. */ 120 public static final int OS_UNIX = 3; 121 /** VM/CMS OS value. */ 122 public static final int OS_VM = 4; 123 /** Atari TOS OS value. */ 124 public static final int OS_ATARI = 5; 125 /** HPFS filesystem OS value. */ 126 public static final int OS_HPFS_FS = 6; 127 /** Macintosh OS value. */ 128 public static final int OS_MACINTOSH = 7; 129 /** Z-System OS value. */ 130 public static final int OS_Z_SYSTEM = 8; 131 /** CP/M OS value. */ 132 public static final int OS_CPM = 9; 133 /** TOPS-20 OS value. */ 134 public static final int OS_TOPS_20 = 10; 135 /** NTFS filesystem OS value. */ 136 public static final int OS_NTFS_FS = 11; 137 /** QDOS OS value. */ 138 public static final int OS_QDOS = 12; 139 /** Acorn OS value. */ 140 public static final int OS_ACORN = 13; 141 /** Unknown OS value. */ 142 public static final int OS_UNKNOWN = 255; 143 144 /** Operating Systems lookup map used to identify OS values. */ 145 public static final Map<Integer, String> osIdxStr = new TreeMap<Integer, String>(); 146 147 /** 148 * Populate the lookup map with known Operating Systems. 149 */ 150 static { 151 osIdxStr.put(OS_FAT_FS, OS_STRING_FAT_FS); 152 osIdxStr.put(OS_AMIGA, OS_STRING_AMIGA); 153 osIdxStr.put(OS_VMS, OS_STRING_VMS); 154 osIdxStr.put(OS_UNIX, OS_STRING_UNIX); 155 osIdxStr.put(OS_VM, OS_STRING_VM); 156 osIdxStr.put(OS_ATARI, OS_STRING_ATARI); 157 osIdxStr.put(OS_HPFS_FS, OS_STRING_HPFS_FS); 158 osIdxStr.put(OS_MACINTOSH, OS_STRING_MACINTOSH); 159 osIdxStr.put(OS_Z_SYSTEM, OS_STRING_Z_SYSTEM); 160 osIdxStr.put(OS_CPM, OS_STRING_CPM); 161 osIdxStr.put(OS_TOPS_20, OS_STRING_TOPS_20); 162 osIdxStr.put(OS_NTFS_FS, OS_STRING_NTFS_FS); 163 osIdxStr.put(OS_QDOS, OS_STRING_QDOS); 164 osIdxStr.put(OS_ACORN, OS_STRING_ACORN); 165 osIdxStr.put(OS_UNKNOWN, OS_STRING_UNKNOWN); 166 } 167 168}