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

N

Novice

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
 
M

Mike Schilling

Novice said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top