Java 8 PushbackInputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PushbackInputStream class.

This code example shows how to use the following methods: read, unread
     */ 
    public static UTFInputStreamReader create(InputStream input, String defaultEncoding) throws IOException {
        byte[] bom = new byte[4];
        String encoding = defaultEncoding;
        int unread;
        PushbackInputStream pushbackStream = new PushbackInputStream(input, 4);
        int n = pushbackStream.read(bom, 0, 4);
 
        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
            encoding = "UTF-8";
            unread = n - 3;
        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
            encoding = "UTF-32BE";
            unread = n - 4;
        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
            encoding = "UTF-32LE";
            unread = n - 4;
        } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
            encoding = "UTF-16BE";
            unread = n - 2;

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: read, skip, unread
                                      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 --- 
 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: read, unread
        // always accept the request 
        Socks5BytestreamSession session = request.accept();
 
        // test input stream 
        try { 
            PushbackInputStream stream = new PushbackInputStream(session.getInputStream());
            int firstByte = stream.read();
            stream.unread(firstByte);
            return stream;
        } 
        catch (IOException e) {
            throw new XMPPException("Error establishing input stream", e);
        } 
    } 
 
    @Override 
    public void cleanup() { 
        /* do nothing */ 
    } 
 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: read, unread
                    sDataObjectCount = 0;
                    return null; 
                } 
            } 
 
            PushbackInputStream pis = new PushbackInputStream(in);
            int tag = pis.read();
 
            if (tag == -1)
            { 
                return null; 
            } 
 
            pis.unread(tag);
 
            if (tag != 0x30)  // assume ascii PEM encoded.
            { 
                return readPEMCertificate(pis);
            } 
            else 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: read, unread
	protected void init() throws IOException {
		String charsetName;
 
		byte bom[] = new byte[4];
		int n, unread;
		n = pis.read(bom, 0, bom.length);
 
		if (bom[0] == _0xEF && bom[1] == _0xBB && bom[2] == _0xBF) {
			charsetName = "UTF-8";
			unread = n - 3;
		} else if (bom[0] == _0xFE && bom[1] == _0xFF) {
			charsetName = "UTF-16BE";
			unread = n - 2;
		} else if (bom[0] == _0xFF && bom[1] == _0xFE) {
			if (n == 4 && bom[2] == _0x00 && bom[3] == _0x00) {
				charsetName = "UTF-32LE";
				unread = 0;
			} else { 
				charsetName = "UTF-16LE";
				unread = n - 2;

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 PushbackInputStream Questions & Answers:

See Code Examples for Java 8 PushbackInputStream Methods: