Code example for PushbackInputStream

Methods: read, unread

0
    } 
 
    private static final Logger LOG = Logger.getLogger(LogRecords.class.getName());
     
    public static void scan(InputStream is, Handler h) throws IOException {
        PushbackInputStream wrap = new PushbackInputStream(is, 32);
        byte[] arr = new byte[5];
        int len = wrap.read(arr);
        if (len == -1) {
            return; 
        } 
        wrap.unread(arr, 0, len);
        if (arr[0] == 0x1f && arr[1] == -117) {
            wrap = new PushbackInputStream(new GZIPInputStream(wrap), 32);
            len = wrap.read(arr);
            if (len == -1) {
                return; 
            } 
            wrap.unread(arr, 0, len);
        }