Commit e89268b6 by Bryce McKinlay Committed by Bryce McKinlay

* java/io/PushbackReader.java: Reformat.

From-SVN: r51291
parent 1bd6476f
2002-03-24 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* java/io/PushbackReader.java: Reformat.
2002-03-24 Tom Tromey <tromey@redhat.com> 2002-03-24 Tom Tromey <tromey@redhat.com>
* java/awt/TextComponent.java (TextComponent): Editable by * java/awt/TextComponent.java (TextComponent): Editable by
......
...@@ -55,60 +55,38 @@ package java.io; ...@@ -55,60 +55,38 @@ package java.io;
*/ */
public class PushbackReader extends FilterReader public class PushbackReader extends FilterReader
{ {
/**
/*************************************************************************/
/*
* Class Variables
*/
/**
* This is the default buffer size * This is the default buffer size
*/ */
private static final int DEFAULT_BUFFER_SIZE = 1; private static final int DEFAULT_BUFFER_SIZE = 1;
/*************************************************************************/
/*
* Instance Variables
*/
/** /**
* This is the buffer that is used to store the pushed back data * This is the buffer that is used to store the pushed back data
*/ */
private char[] buf; private char[] buf;
/** /**
* This is the position in the buffer from which the next char will be * This is the position in the buffer from which the next char will be
* read. Bytes are stored in reverse order in the buffer, starting from * read. Bytes are stored in reverse order in the buffer, starting from
* <code>buf[buf.length - 1]</code> to <code>buf[0]</code>. Thus when * <code>buf[buf.length - 1]</code> to <code>buf[0]</code>. Thus when
* <code>pos</code> is 0 the buffer is full and <code>buf.length</code> when * <code>pos</code> is 0 the buffer is full and <code>buf.length</code> when
* it is empty * it is empty
*/ */
private int pos; private int pos;
/*************************************************************************/
/*
* Constructors
*/
/** /**
* This method initializes a <code>PushbackReader</code> to read from the * This method initializes a <code>PushbackReader</code> to read from the
* specified subordinate <code>Reader</code> with a default pushback buffer * specified subordinate <code>Reader</code> with a default pushback buffer
* size of 1. * size of 1.
* *
* @code in The subordinate stream to read from * @code in The subordinate stream to read from
*/ */
public public PushbackReader(Reader in)
PushbackReader(Reader in) {
{
this(in, DEFAULT_BUFFER_SIZE); this(in, DEFAULT_BUFFER_SIZE);
} }
/*************************************************************************/
/** /**
* This method initializes a <code>PushbackReader</code> to read from the * This method initializes a <code>PushbackReader</code> to read from the
* specified subordinate <code>Reader</code> with the specified buffer * specified subordinate <code>Reader</code> with the specified buffer
* size * size
...@@ -116,9 +94,8 @@ PushbackReader(Reader in) ...@@ -116,9 +94,8 @@ PushbackReader(Reader in)
* @param in The subordinate <code>Reader</code> to read from * @param in The subordinate <code>Reader</code> to read from
* @param bufsize The pushback buffer size to use * @param bufsize The pushback buffer size to use
*/ */
public public PushbackReader(Reader in, int bufsize)
PushbackReader(Reader in, int bufsize) {
{
super(in); super(in);
if (bufsize < 0) if (bufsize < 0)
...@@ -126,32 +103,23 @@ PushbackReader(Reader in, int bufsize) ...@@ -126,32 +103,23 @@ PushbackReader(Reader in, int bufsize)
buf = new char[bufsize]; buf = new char[bufsize];
pos = bufsize; pos = bufsize;
} }
/*************************************************************************/
/*
* Instance Methods
*/
/** /**
* This method closes the stream and frees any associated resources. * This method closes the stream and frees any associated resources.
* *
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
*/ */
public void public void close() throws IOException
close() throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
buf = null; buf = null;
super.close(); super.close();
} }
} }
/*************************************************************************/
/** /**
* This method throws an exception when called since this class does * This method throws an exception when called since this class does
* not support mark/reset. * not support mark/reset.
* *
...@@ -159,44 +127,35 @@ close() throws IOException ...@@ -159,44 +127,35 @@ close() throws IOException
* *
* @exception IOException Always thrown to indicate mark/reset not supported. * @exception IOException Always thrown to indicate mark/reset not supported.
*/ */
public void public void mark(int read_limit) throws IOException
mark(int read_limit) throws IOException {
{
throw new IOException("mark not supported in this class"); throw new IOException("mark not supported in this class");
} }
/*************************************************************************/
/** /**
* This method returns <code>false</code> to indicate that it does not support * This method returns <code>false</code> to indicate that it does not support
* mark/reset functionality. * mark/reset functionality.
* *
* @return This method returns <code>false</code> to indicate that this class does not support mark/reset functionality * @return This method returns <code>false</code> to indicate that this class does not support mark/reset functionality
* *
*/ */
public boolean public boolean markSupported()
markSupported() {
{
return(false); return(false);
} }
/*************************************************************************/
/** /**
* This method always throws an IOException in this class because * This method always throws an IOException in this class because
* mark/reset functionality is not supported. * mark/reset functionality is not supported.
* *
* @exception IOException Always thrown for this class * @exception IOException Always thrown for this class
*/ */
public void public void reset() throws IOException
reset() throws IOException {
{
throw new IOException("reset not supported in this class"); throw new IOException("reset not supported in this class");
} }
/*************************************************************************/
/** /**
* This method determines whether or not this stream is ready to be read. * This method determines whether or not this stream is ready to be read.
* If it returns <code>false</code> to indicate that the stream is not * If it returns <code>false</code> to indicate that the stream is not
* ready, any attempt to read from the stream could (but is not * ready, any attempt to read from the stream could (but is not
...@@ -210,9 +169,8 @@ reset() throws IOException ...@@ -210,9 +169,8 @@ reset() throws IOException
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public boolean public boolean ready() throws IOException
ready() throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
...@@ -223,13 +181,11 @@ ready() throws IOException ...@@ -223,13 +181,11 @@ ready() throws IOException
else else
return(false); return(false);
} }
} }
/*************************************************************************/
// Don't delete this method just because the spec says it shouldn't be there! // Don't delete this method just because the spec says it shouldn't be there!
// See the CVS log for details. // See the CVS log for details.
/** /**
* This method skips the specified number of chars in the stream. It * This method skips the specified number of chars in the stream. It
* returns the actual number of chars skipped, which may be less than the * returns the actual number of chars skipped, which may be less than the
* requested amount. * requested amount.
...@@ -244,9 +200,8 @@ ready() throws IOException ...@@ -244,9 +200,8 @@ ready() throws IOException
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public long public long skip(long num_chars) throws IOException
skip(long num_chars) throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
if (num_chars <= 0) if (num_chars <= 0)
...@@ -264,12 +219,10 @@ skip(long num_chars) throws IOException ...@@ -264,12 +219,10 @@ skip(long num_chars) throws IOException
long chars_skipped = in.skip(num_chars - chars_discarded); long chars_skipped = in.skip(num_chars - chars_discarded);
return(chars_discarded + chars_skipped); return(chars_discarded + chars_skipped);
} // synchronized }
} }
/*************************************************************************/
/** /**
* This method reads an unsigned char from the input stream and returns it * This method reads an unsigned char from the input stream and returns it
* as an int in the range of 0-65535. This method also will return -1 if * as an int in the range of 0-65535. This method also will return -1 if
* the end of the stream has been reached. The char returned will be read * the end of the stream has been reached. The char returned will be read
...@@ -282,9 +235,8 @@ skip(long num_chars) throws IOException ...@@ -282,9 +235,8 @@ skip(long num_chars) throws IOException
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public int public int read() throws IOException
read() throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
...@@ -296,11 +248,9 @@ read() throws IOException ...@@ -296,11 +248,9 @@ read() throws IOException
++pos; ++pos;
return((buf[pos - 1] & 0xFFFF)); return((buf[pos - 1] & 0xFFFF));
} }
} }
/*************************************************************************/
/** /**
* This method read chars from a stream and stores them into a caller * This method read chars from a stream and stores them into a caller
* supplied buffer. It starts storing the data at index <code>offset</code> into * supplied buffer. It starts storing the data at index <code>offset</code> into
* the buffer and attempts to read <code>len</code> chars. This method can * the buffer and attempts to read <code>len</code> chars. This method can
...@@ -323,9 +273,8 @@ read() throws IOException ...@@ -323,9 +273,8 @@ read() throws IOException
* *
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
*/ */
public synchronized int public synchronized int read(char[] b, int offset, int len) throws IOException
read(char[] b, int offset, int len) throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
...@@ -344,11 +293,9 @@ read(char[] b, int offset, int len) throws IOException ...@@ -344,11 +293,9 @@ read(char[] b, int offset, int len) throws IOException
return super.read(b, offset, len); return super.read(b, offset, len);
} }
} }
/*************************************************************************/
/** /**
* This method pushes a single char of data into the pushback buffer. * This method pushes a single char of data into the pushback buffer.
* The char pushed back is the one that will be returned as the first char * The char pushed back is the one that will be returned as the first char
* of the next read. * of the next read.
...@@ -362,9 +309,8 @@ read(char[] b, int offset, int len) throws IOException ...@@ -362,9 +309,8 @@ read(char[] b, int offset, int len) throws IOException
* *
* @exception IOException If the pushback buffer is full. * @exception IOException If the pushback buffer is full.
*/ */
public void public void unread(int b) throws IOException
unread(int b) throws IOException {
{
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
...@@ -374,12 +320,10 @@ unread(int b) throws IOException ...@@ -374,12 +320,10 @@ unread(int b) throws IOException
--pos; --pos;
buf[pos] = (char)(b & 0xFFFF); buf[pos] = (char)(b & 0xFFFF);
} // synchronized }
} }
/*************************************************************************/
/** /**
* This method pushes all of the chars in the passed char array into * This method pushes all of the chars in the passed char array into
* the pushback buffer. These chars are pushed in reverse order so that * the pushback buffer. These chars are pushed in reverse order so that
* the next char read from the stream after this operation will be * the next char read from the stream after this operation will be
...@@ -392,15 +336,12 @@ unread(int b) throws IOException ...@@ -392,15 +336,12 @@ unread(int b) throws IOException
* *
* @exception IOException If the pushback buffer is full * @exception IOException If the pushback buffer is full
*/ */
public synchronized void public synchronized void unread(char[] buf) throws IOException
unread(char[] buf) throws IOException {
{
unread(buf, 0, buf.length); unread(buf, 0, buf.length);
} }
/*************************************************************************/
/** /**
* This method pushed back chars from the passed in array into the pushback * This method pushed back chars from the passed in array into the pushback
* buffer. The chars from <code>buf[offset]</code> to <code>buf[offset + len]</code> * buffer. The chars from <code>buf[offset]</code> to <code>buf[offset + len]</code>
* are pushed in reverse order so that the next char read from the stream * are pushed in reverse order so that the next char read from the stream
...@@ -416,9 +357,9 @@ unread(char[] buf) throws IOException ...@@ -416,9 +357,9 @@ unread(char[] buf) throws IOException
* *
* @exception IOException If the pushback buffer is full * @exception IOException If the pushback buffer is full
*/ */
public synchronized void public synchronized void unread(char[] b, int offset, int len)
unread(char[] b, int offset, int len) throws IOException throws IOException
{ {
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
...@@ -435,6 +376,5 @@ unread(char[] b, int offset, int len) throws IOException ...@@ -435,6 +376,5 @@ unread(char[] b, int offset, int len) throws IOException
// and in that case we don't want to modify pos. // and in that case we don't want to modify pos.
pos -= len; pos -= len;
} }
}
} }
} // class PushbackReader
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment