java.io.BufferedWriter and java.io.PrintStream - a seeming parameter/argument mismatch in method inv

Discussion in 'Java' started by Novice, Jul 19, 2003.

  1. Novice

    Novice Guest

    Hi, I was just examining the SDK API and noticed this method in PrintStream:
    private void write(char buf[]) {
    try {
    synchronized (this) {
    ensureOpen();
    textOut.write(buf);
    textOut.flushBuffer();
    charOut.flushBuffer();
    if (autoFlush) {
    for (int i = 0; i < buf.length; i++)
    if (buf == '\n')
    out.flush();
    }
    }
    }
    catch (InterruptedIOException x) {
    Thread.currentThread().interrupt();
    }
    catch (IOException x) {
    trouble = true;
    }
    }

    I also noticed that there is no write method in BufferedWriter that takes a
    char array as its only argument.

    However, I did notice this method in BufferedWriter:
    public void write(int c) throws IOException {
    synchronized (lock) {
    ensureOpen();
    if (nextChar >= nChars)
    flushBuffer();
    cb[nextChar++] = (char) c;
    }
    }

    Does Java just take the first element of the char array to accomodate the
    int parameter of BufferedWriter's write method?

    Thanks,
    Novice
    Novice, Jul 19, 2003
    #1
    1. Advertising

  2. "Novice" <> wrote in message
    news:bfa1jb$7du$...
    > Hi, I was just examining the SDK API and noticed this method in

    PrintStream:

    >
    > I also noticed that there is no write method in BufferedWriter that takes

    a
    > char array as its only argument.


    BufferedWriter inherits write(char[] arr) from Writer. The implementation
    in Writer is presumably

    public void write(char[] arr) throws IOException
    {
    write(arr, 0, arr.length);
    }

    and there's no need to override it.
    Mike Schilling, Jul 19, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    3
    Views:
    1,323
    Kumar Reddi
    Dec 8, 2004
  2. tshad
    Replies:
    6
    Views:
    415
    tshad
    Jan 27, 2005
  3. tshad
    Replies:
    9
    Views:
    485
    tshad
    Jun 10, 2005
  4. Dave
    Replies:
    2
    Views:
    436
    Martin Eisenberg
    Apr 5, 2004
  5. www
    Replies:
    1
    Views:
    1,482
Loading...

Share This Page