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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: read, unread
      return; 
 
    String encoding;
    byte bom[] = new byte[BOM_SIZE];
    int n, unread;
    n = internalIn.read(bom, 0, bom.length);
 
    if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF) && (bom[3] == (byte) 0xEF) && (bom[4] == (byte) 0xBB) && (bom[5] == (byte) 0xBF)) {
      encoding = "UTF-8";
      unread = n - 6;
    } else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
      encoding = "UTF-8";
      unread = n - 3;
    } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
      encoding = "UTF-16BE";
      unread = n - 2;
    } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
      encoding = "UTF-16LE";
      unread = n - 2;
    } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: read, unread
     * @return 
     * @throws java.io.IOException 
     */ 
    public static InputStream removeBom(InputStream in) throws IOException {
 
        PushbackInputStream testin = new PushbackInputStream(in);
        int ch = testin.read();
        if (ch != 0xEF) {
            testin.unread(ch);
        } else if ((ch = testin.read()) != 0xBB) { // if ch==0xef
            testin.unread(ch);
            testin.unread(0xef);
        } else if ((ch = testin.read()) != 0xBF) { // if ch ==0xbb
            throw new IOException("´íÎóµÄUTF-8¸ñʽÎļþ");
        } else { // if ch ==0xbf 
            // ²»ÐèÒª×ö£¬ÕâÀïÊÇbomÍ·±»¶ÁÍêÁË 
            // // System.out.println("still exist bom"); 
        } 
        return testin;
 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: mark
            // expected 
        } 
    } 
 
    public void test_mark() { 
        PushbackInputStream pb = new PushbackInputStream(
                new ByteArrayInputStream(new byte[] { 0 }), 2);
        pb.mark(Integer.MAX_VALUE);
        pb.mark(0);
        pb.mark(-1);
        pb.mark(Integer.MIN_VALUE);
    } 
 
 
	/** 
	 * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream) 
	 */ 
	public void test_ConstructorLjava_io_InputStream() { 
        try { 
            PushbackInputStream str = new PushbackInputStream(null);
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: unread
 
                PushbackInputStream pbis;
                if (input instanceof PushbackInputStream) {
                    pbis = (PushbackInputStream) input;
                } else { 
                    pbis = new PushbackInputStream(input, 1);
                    input = pbis;
                } 
                pbis.unread(b);
 
                return false; 
            } 
        } catch (IOException ex) {
            throw new ProcessingException(ex);
        } 
    } 
 
    /** 
     * Check that the entity input stream has not been closed yet. 
     * 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: read, unread
    authentication NONE. 
    */ 
   public ServerAuthenticator startSession(Socket s)
                                  throws IOException{
 
     PushbackInputStream in =  new PushbackInputStream(s.getInputStream());
     OutputStream out = s.getOutputStream();
 
     int version = in.read();
     if(version == 5){
       if(!selectSocks5Authentication(in,out,0))
          return null; 
     }else if(version == 4){
       //Else it is the request message allready, version 4 
       in.unread(version);
     }else 
       return null; 
      
 
     return new ServerAuthenticatorNone(in,out);
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 PushbackInputStream Questions & Answers:

See Code Examples for Java 8 PushbackInputStream Methods: