java.io

Class CharArrayReader

Implemented Interfaces:
Closeable, Readable

public class CharArrayReader
extends Reader

This class implements a character buffer that can be used as a character-input stream.
Since:
JDK1.1

Field Summary

protected char[]
buf
The character buffer.
protected int
count
The index of the end of this buffer.
protected int
markedPos
The position of mark in buffer.
protected int
pos
The current buffer position.

Fields inherited from class java.io.Reader

lock

Constructor Summary

CharArrayReader(buf[] )
Create an CharArrayReader from the specified array of chars.
CharArrayReader(buf[] , int offset, int length)
Create an CharArrayReader from the specified array of chars.

Method Summary

void
close()
Close the stream.
void
mark(int readAheadLimit)
Mark the present position in the stream.
boolean
markSupported()
Tell whether this stream supports the mark() operation, which it does.
int
read()
Read a single character.
int
read(b[] , int off, int len)
Read characters into a portion of an array.
boolean
ready()
Tell whether this stream is ready to be read.
void
reset()
Reset the stream to the most recent mark, or to the beginning if it has never been marked.
long
skip(long n)
Skip characters.

Methods inherited from class java.io.Reader

close, mark, markSupported, read, read, read, read, ready, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

buf

protected char[] buf
The character buffer.

count

protected int count
The index of the end of this buffer. There is not valid data at or beyond this index.

markedPos

protected int markedPos
The position of mark in buffer.

pos

protected int pos
The current buffer position.

Constructor Details

CharArrayReader

public CharArrayReader(buf[] )
Create an CharArrayReader from the specified array of chars.
Parameters:
Usages and Demos :

View More Examples of CharArrayReader(buf[] )
   1:   public CharArrayLineReader(char[] chars) {
   2:     super(new CharArrayReader(chars));
   3:   }
   4: }

View Full Code Here
   1:         }
   2:         return new CharArrayReader(docChars);
   3:     }
   4:     private void readDocument() {
   5:         CharArrayWriter writer = new CharArrayWriter();

View Full Code Here
   1:    {
   2:       return (chars != null ? new CharArrayReader(chars) : null);
   3:    }
   4: 
   5:    @Override

View Full Code Here
   1:             }
   2:             CharArrayReader reader = new CharArrayReader( chars );
   3:             st.setCharacterStream( index, reader, chars.length );
   4:         }
   5:         else {

View Full Code Here
   1:             System.out.println("Bytes read: " + read);
   2:             xml = builder.build(new CharArrayReader(buf));
   3:             
   4:         } catch (Exception e) {
   5:             

View Full Code Here

CharArrayReader

public CharArrayReader(buf[] ,
                       int offset,
                       int length)
Create an CharArrayReader from the specified array of chars.

The resulting reader will start reading at the given offset. The total number of char values that can be read from this reader will be either length or buf.length-offset, whichever is smaller.

Parameters:
offset - Offset of the first char to read
length - Number of chars to read
Throws:
IllegalArgumentException - If offset is negative or greater than buf.length, or if length is negative, or if the sum of these two values is negative.
Usages and Demos :

View More Examples of CharArrayReader(buf[] ,int offset,int length)
   1:    {
   2:       return new CharArrayReader(chars, 0, index);
   3:    }
   4: 
   5:    public int length()

View Full Code Here
   1:   {
   2:     pushReader(new CharArrayReader(buf, off, len), null, null);
   3:   }
   4: }

View Full Code Here
   1:         Object model =
   2:             _modelParser.parse(new CharArrayReader(chars, offset, length));
   3:         _currentPage.setModel(model);
   4:     }

View Full Code Here
   1:                 if(null == dst && null == s)
   2:                     s = new CharArrayReader(v, first, last - first);
   3:                 else
   4:         ...
   5:                         dst = new char[0];
   6:                     s = new CharArrayReader(dst, 0, i);
   7:                 }
   8:                 return s;
   9:             }

View Full Code Here
   1:     public Reader getReader() {
   2:     return (writer == null) ? new CharArrayReader(cb, 0, nextChar) : null;
   3:     }
   4: 
   5:     public String getString() {

View Full Code Here

Method Details

close

public void close()
Close the stream.
Specified by:
close in interface Closeable
Overrides:
close in interface Reader
Usages and Demos :

View More Examples of close()
   1:       gos.write(bytes, 0, bytes.length);
   2:       gos.close();
   3:         ...
   4:       baos.close();
   5: 
   6:         ...
   7: 
   8:     CharArrayReader car = new CharArrayReader(chars);
   9:     JavaReader      jr  = new JavaReader(car);
  10:         ...
  11: 
  12:     bos.close();

View Full Code Here
   1: import java.io.ByteArrayOutputStream;
   2: import java.io.CharArrayReader;
   3: import java.io.CharArrayWriter;
   4:         ...
   5:             gos.write(bytes, 0, bytes.length);
   6:             gos.close();
   7:         ...
   8:             baos.close();
   9:             bytes = baos.toByteArray();
  10:         ...
  11:         char[] chars = s.toCharArray();
  12:         CharArrayReader car = new CharArrayReader(chars);

View Full Code Here

mark

public void mark(int readAheadLimit)
            throws IOException
Mark the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.
Overrides:
mark in interface Reader
Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a character array, there is no actual limit; hence this argument is ignored.
Throws:
IOException - If an I/O error occurs

markSupported

public boolean markSupported()
Tell whether this stream supports the mark() operation, which it does.
Overrides:
markSupported in interface Reader

read

public int read()
            throws IOException
Read a single character.
Overrides:
read in interface Reader
Throws:
IOException - If an I/O error occurs

read

public int read(b[] ,
                int off,
                int len)
            throws IOException
Read characters into a portion of an array.
Parameters:
off - Offset at which to start storing characters
len - Maximum number of characters to read
Returns:
The actual number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs

ready

public boolean ready()
            throws IOException
Tell whether this stream is ready to be read. Character-array readers are always ready to be read.
Overrides:
ready in interface Reader
Throws:
IOException - If an I/O error occurs

reset

public void reset()
            throws IOException
Reset the stream to the most recent mark, or to the beginning if it has never been marked.
Overrides:
reset in interface Reader
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of reset()
   1: import java.io.ByteArrayOutputStream;
   2: import java.io.CharArrayReader;
   3: import java.io.Writer;
   4:         ...
   5: 
   6:                 CharArrayReader car = copy(reader);
   7:                 XmlEncodingSniffer xes = new XmlEncodingSniffer(car, null);
   8:         ...
   9: 
  10:                 car.reset();
  11:                 return car;
  12:         ...
  13: 
  14:                 bais.reset();

View Full Code Here

skip

public long skip(long n)
            throws IOException
Skip characters. Returns the number of characters that were skipped.

The n parameter may be negative, even though the skip method of the Reader superclass throws an exception in this case. If n is negative, then this method does nothing and returns 0.

Overrides:
skip in interface Reader
Parameters:
n - The number of characters to skip
Returns:
The number of characters actually skipped
Throws:
IOException - If the stream is closed, or an I/O error occurs