Java IO Learning (18) chararraywriter (character array output stream)

Source: Internet
Author: User

Chararraywriter Introduction

CharArrayReader is used to write the data character, which inherits from writer. The data for the operation is in characters!

Chararraywriter Function List

Chararraywriter ()
chararraywriter (int initialsize)
     
chararraywriter     Append (charsequence csq, int start, int end)
chararraywriter     append (char c)
chararraywriter     append (charsequence csq)
void     Close ()
void     flush ()
void     reset ()
int     size ()
char[]     ToCharArray ()
String     toString ()
void     write (char[] buffer, int offset, int len)
void     write (int Onechar)
void     write (String str, int offset, int count)
void     WriteTo (Writer out)

Writer and Chararraywriter Source analysis

Writer is the chararraywriter of the parent class, we first look at the source of writer, and then learn Chararraywriter source code.

1. Writer Source analysis (based on jdk1.7.40)

Package java.io;
     
    Public abstract class Writer implements Appendable, Closeable, flushable {private char[] writebuffer;
     
    Private final int writebuffersize = 1024;
     
    protected Object Lock;
    Protected Writer () {this.lock = this;
        } protected Writer (Object Lock) {if (lock = null) {throw new NullPointerException ();
    } This.lock = lock; public void write (int c) throws IOException {synchronized (lock) {if (WriteBuffer = = nul
            L) {writebuffer = new char[writebuffersize];
            } Writebuffer[0] = (char) c;
        Write (WriteBuffer, 0, 1);
    } public void write (char cbuf[]) throws IOException {write (cbuf, 0, cbuf.length);
     
    Abstract public void write (char cbuf[], int off, int len) throws IOException; public void Write (String str) throws IOException {write (s)TR, 0, Str.length ());
            public void Write (String str, int off, int len) throws IOException {synchronized (lock) {
            Char cbuf[]; if (len <= writebuffersize) {if (WriteBuffer = null) {WriteBuffer = new Char[wri
                Tebuffersize];
            } cbuf = WriteBuffer;
                else {//Don ' t permanently allocate very large buffers.
            Cbuf = new Char[len];
            } str.getchars (off, (off + len), cbuf, 0);
        Write (cbuf, 0, Len); } public Writer Append (charsequence csq) throws IOException {if (CSQ = null) write ("
        Null ");
        else Write (csq.tostring ());
    return this;  Writer Append (charsequence csq, int start, int end) throws IOException {Charsequence cs = (csq = null?
        "NULL": CSQ);
        Write (Cs.subsequence (start, end). toString ()); ReTurn this;
        Public Writer Append (char c) throws IOException {write (c);
    return this;
     
    Abstract public void flush () throws IOException;
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.