if (magic != (GZIP_MAGIC >> 8)) throw new IOException("Error in GZIP header, first byte doesn't match");  magic = in.read(); if (magic != (GZIP_MAGIC & 0xff)) throw new IOException("Error in GZIP header, second byte doesn't match"); headCRC.update(magic);
headCRC.update(magic2);
  private void readHeader() throws IOException  {    /* 1. Check the two magic bytes */    CRC32 headCRC = new CRC32();    int magic = in.read();    if (magic < 0)    {      eos = true;      return;    }    headCRC.update(magic);    if (magic != (GZIP_MAGIC >> 8))      throw new IOException("Error in GZIP header, first byte doesn't match");        magic = in.read();    if (magic != (GZIP_MAGIC & 0xff))      throw new IOException("Error in GZIP header, second byte doesn't match");    headCRC.update(magic);        /* 2. Check the compression type (must be 8) */    int CM = in.read();    if (CM != 8)      throw new IOException("Error in GZIP header, data not in deflate format");    headCRC.update(CM);    /* 3. Check the flags */    int flags = in.read();    if (flags < 0)      throw new EOFException("Early EOF in GZIP header");    headCRC.update(flags);        /*    This flag byte is divided into individual bits as follows:	  	  bit 0   FTEXT	  bit 1   FHCRC	  bit 2   FEXTRA	  bit 3   FNAME	  bit 4   FCOMMENT	  bit 5   reserved	  bit 6   reserved	  bit 7   reserved    */        /* 3.1 Check the reserved bits are zero */        if ((flags & 0xd0) != 0)      throw new IOException("Reserved flag bits in GZIP header != 0");        /* 4.-6. Skip the modification time, extra flags, and OS type */    for (int i=0; i< 6; i++)    {      int readByte = in.read();      if (readByte < 0)	throw new EOFException("Early EOF in GZIP header");      headCRC.update(readByte);    }        /* 7. Read extra field */    if ((flags & FEXTRA) != 0)    {      /* Skip subfield id */      for (int i=0; i< 2; i++)      {        int readByte = in.read();	if (readByte < 0)	  throw new EOFException("Early EOF in GZIP header");	headCRC.update(readByte);      }      if (in.read() < 0 || in.read() < 0)	throw new EOFException("Early EOF in GZIP header");	      int len1, len2, extraLen;      len1 = in.read();      len2 = in.read();      if ((len1 < 0) || (len2 < 0))	throw new EOFException("Early EOF in GZIP header");      headCRC.update(len1);      headCRC.update(len2);      extraLen = (len1 << 8) | len2;      for (int i = 0; i < extraLen;i++)      {	int readByte = in.read();	if (readByte < 0)	  throw new EOFException("Early EOF in GZIP header");	headCRC.update(readByte);      }    }        /* 8. Read file name */    if ((flags & FNAME) != 0)    {      int readByte;      while ( (readByte = in.read()) > 0)	headCRC.update(readByte);      if (readByte < 0)	throw new EOFException("Early EOF in GZIP file name");      headCRC.update(readByte);    }    /* 9. Read comment */    if ((flags & FCOMMENT) != 0)    {      int readByte;      while ( (readByte = in.read()) > 0)        headCRC.update(readByte);      if (readByte < 0)        throw new EOFException("Early EOF in GZIP comment");      headCRC.update(readByte);    }        /* 10. Read header CRC */    if ((flags & FHCRC) != 0)    {      int tempByte;      int crcval = in.read();      if (crcval < 0)        throw new EOFException("Early EOF in GZIP header");	      tempByte = in.read();      if (tempByte < 0)        throw new EOFException("Early EOF in GZIP header");	      crcval = (crcval << 8) | tempByte;      if (crcval != ((int) headCRC.getValue() & 0xffff))        throw new IOException("Header CRC value mismatch");    }        readGZIPHeader = true;    //System.err.println("Read GZIP header");  }