Code example for PushbackInputStream

Methods: readskipunread

0
                                      String[] encoding) 
        throws IOException { 
        byte[] bytes = new byte[1024];
        int byteCount = -1;
 
        PushbackInputStream in2 = new PushbackInputStream(in, bytes.length);
        try { 
            int count = in2.read(bytes, 0, bytes.length);
            if (count > 0) {
                in2.unread(bytes, 0, count);
            } 
            byteCount = count;
        } catch (IOException ignored) {}
 
        String charset = null;
 
        if (byteCount > 0) {
            if (byteCount >= 2) {
                // Use BOM --- 
 
                int b0 = (bytes[0] & 0xFF);
                int b1 = (bytes[1] & 0xFF);
 
                switch ((b0 << 8) | b1) {
                case 0xFEFF: 
                    charset = "UTF-16BE";
                    // We don't want to read the BOM. 
                    in2.skip(2);
                    break; 
                case 0xFFFE: 
                    charset = "UTF-16LE";
                    in2.skip(2);
                    break; 
                case 0xEFBB: 
                    if (byteCount >= 3 && (bytes[2] & 0xFF) == 0xBF) {
                        charset = "UTF-8";
                        in2.skip(3);
                    } 
                    break; 
                } 
            } 
 
Connect your IDE to all the code out there  Get Codota for Java