public static InputStream tryGzipInput(InputStream in) throws IOException {
  if (!in.markSupported()) {
    PushbackInputStream pb=new PushbackInputStream(in,16);
    in=pb;
    byte[] magic={0,0};
    pb.read(magic);
    pb.unread(magic);
    if (magic[0] == 31 && magic[1] == -117) {
      return new GZIPInputStream(pb);
    }
    return in;
  }
  in.mark(16);
  boolean isgzip=(in.read() == 31 && in.read() == -117);
  in.reset();
  if (isgzip) {
    in=new GZIPInputStream(in);
  }
  return in;
}

public static InputStream tryGzipInput ( InputStream in ) throws IOException { if ( ! in . markSupported ( ) ) { PushbackInputStream pb = new PushbackInputStream ( in , 16 ) ; in = pb ; byte [ ] magic = { 0 , 0 } ; pb . read ( magic ) ; pb . unread ( magic ) ; if ( magic [ 0 ] == 31 && magic [ 1 ] == - 117 ) { return new GZIPInputStream ( pb ) ; } return in ; } in . mark ( 16 ) ; boolean isgzip = ( in . read ( ) == 31 && in . read ( ) == - 117 ) ; in . reset ( ) ; if ( isgzip ) { in = new GZIPInputStream ( in ) ; } return in ; }
try to open a stream as gzip , if it starts with the gzip magic . todo : move to utils package .
