private static int readHeaderFromStream(final InputStream is,final byte[] imageHeaderBytes) throws IOException {
  Preconditions.checkNotNull(is);
  Preconditions.checkNotNull(imageHeaderBytes);
  Preconditions.checkArgument(imageHeaderBytes.length >= MAX_HEADER_LENGTH);
  if (is.markSupported()) {
    try {
      is.mark(MAX_HEADER_LENGTH);
      return ByteStreams.read(is,imageHeaderBytes,0,MAX_HEADER_LENGTH);
    }
  finally {
      is.reset();
    }
  }
 else {
    return ByteStreams.read(is,imageHeaderBytes,0,MAX_HEADER_LENGTH);
  }
}

private static int readHeaderFromStream ( final InputStream is , final byte [ ] imageHeaderBytes ) throws IOException { Preconditions . checkNotNull ( is ) ; Preconditions . checkNotNull ( imageHeaderBytes ) ; Preconditions . checkArgument ( imageHeaderBytes . length >= MAX_HEADER_LENGTH ) ; if ( is . markSupported ( ) ) { try { is . mark ( MAX_HEADER_LENGTH ) ; return ByteStreams . read ( is , imageHeaderBytes , 0 , MAX_HEADER_LENGTH ) ; } finally { is . reset ( ) ; } } else { return ByteStreams . read ( is , imageHeaderBytes , 0 , MAX_HEADER_LENGTH ) ; } }
reads up to max_header_length bytes from is inputstream . if mark is supported by is , it is used to restore content of the stream after appropriate amount of data is read . read bytes are stored in imageheaderbytes , which should be capable of storing max_header_length bytes .
