Java IO Learning (17) CharArrayReader (character array input stream)

Source: Internet
Author: User
Tags abstract min reset

CharArrayReader Introduction

CharArrayReader is a character array input stream. It is similar to Bytearrayinputstream, except that Bytearrayinputstream is a byte array input stream, and Chararray is a character array input stream. CharArrayReader is used to read a character array, which inherits from reader. The data for the operation is in characters!

CharArrayReader Function List

CharArrayReader (char[] buf)
CharArrayReader (char[] buf, int offset, int length)
     
void Close      ()
void      mark (int readlimit)
boolean   marksupported ()
int       read ()
int       read (char[] buffer, int offset, int len)
boolean   ready ()
void      Reset ()
long      Skip (long charcount)

Reader and CharArrayReader source analysis

Reader is the chararrayreader of the parent class, we first look at the source code reader, and then learn CharArrayReader source code.

1. Reader source analysis (based on jdk1.7.40)

Package java.io;
     
    Public abstract class Reader implements readable, closeable {protected Object lock;
    Protected Reader () {this.lock = this;
        } protected Reader (Object Lock) {if (lock = null) {throw new NullPointerException ();
    } This.lock = lock;
        public int read (Java.nio.CharBuffer target) throws IOException {int len = target.remaining ();
        char[] Cbuf = new Char[len];
        int n = read (cbuf, 0, Len);
        if (n > 0) target.put (cbuf, 0, N);
    return n;
        public int read () throws IOException {char cb[] = new CHAR[1];
        if (read (CB, 0, 1) = = 1) return-1;
    else return cb[0];
    public int read (char cbuf[]) throws IOException {return read (cbuf, 0, cbuf.length);
     
    Abstract public int read (char cbuf[], int off, int len) throws IOException; Private static final int maxskipbuffersize = 8192;
     
    Private char skipbuffer[] = null; Public long Skip (long N) throws IOException {if (n < 0L) throw new IllegalArgumentException ("Skip
        Value is negative ");
        int nn = (int) math.min (n, maxskipbuffersize); Synchronized (lock) {if (Skipbuffer = = null) | |
                (Skipbuffer.length < NN))
            Skipbuffer = new CHAR[NN];
            Long r = N;
                while (R > 0) {int NC = read (skipbuffer, 0, (int) math.min (r, nn));
                if (NC = = 1) break;
            R-= NC;
        return n-r;
    } public Boolean Ready () throws IOException {return false;
    public boolean marksupported () {return false; public void mark (int readaheadlimit) throws IOException {throw new IOException ("Mark () not supported"
    ); } public void Reset () throws IOException {throw new IOException ("Reset () not supported");
Abstract public void Close () throws IOException; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.