java.io

Class StringReader

Implemented Interfaces:
Closeable, Readable

public class StringReader
extends Reader

A character stream whose source is a string.
Since:
JDK1.1

Field Summary

Fields inherited from class java.io.Reader

lock

Constructor Summary

StringReader(String s)
Create a new string reader.

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(cbuf[] , 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 of the string if it has never been marked.
long
skip(long ns)
Skips the specified number of characters in the stream.

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

Constructor Details

StringReader

public StringReader(String s)
Create a new string reader.
Parameters:
s - String providing the character stream.
Usages and Demos :

View More Examples of StringReader(String s)
   1:         }
   2:         StringReader reader = new StringReader("");
   3:         InputSource is = new InputSource(reader);
   4:         return (is);
   5:     }

View Full Code Here
   1: 
   2:         Template template = new Template("strTemplate", new StringReader("${test1}${test2}"), new Configuration());
   3: 
   4:         HashMap templateObjects = new HashMap();

View Full Code Here
   1:     public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
   2:         return new InputSource(new StringReader(""));
   3:     }
   4: 
   5:     public boolean hasDTD() {

View Full Code Here
   1:         XMLInputFactory inputFactory = XMLInputFactory.newInstance();
   2:         XMLEventReader reader = inputFactory.createXMLEventReader(new StringReader(""));
   3:         XMLEventAllocator allocator = (XMLEventAllocator) reader.getProperty(XMLInputFactory.ALLOCATOR);
   4:         System.out.println(allocator);

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: import java.io.IOException;
   2: import java.io.StringReader;
   3: import java.io.StringWriter;
   4:         ...
   5:         
   6:         StringReader sr = new StringReader(strCleanedSource);
   7:         StringWriter sw = new StringWriter();
   8:         ...
   9:         
  10:         sr.close( );
  11:         sw.flush( );
  12:         ...
  13:         {
  14:             sw.close( );

View Full Code Here
   1: import java.awt.event.ActionListener;
   2: import java.io.StringReader;
   3: import java.util.Iterator;
   4:         ...
   5:     protected void apply(String wkt, PlugInContext context) throws Exception {
   6:         StringReader stringReader = new StringReader(wkt);
   7:         try {
   8:         ...
   9:         } finally {
  10:             stringReader.close();
  11:         }

View Full Code Here
   1:         GMLInputTemplate template = new GMLInputTemplate();
   2:         StringReader sr = new StringReader(s);
   3: 
   4:         ...
   5:         } finally {
   6:             sr.close();
   7:         }
   8:         ...
   9:         throws Exception {
  10:         StringReader r = new StringReader(gml);
  11: 
  12:         ...
  13:         } finally {
  14:             r.close();

View Full Code Here
   1: 
   2: import java.io.StringReader;
   3: import java.util.*;
   4:         ...
   5: 
   6:         StringReader reader = new StringReader( buffer.getText( 0, buffer.getLength() ) );
   7:         try {
   8:         ...
   9:         finally {
  10:             reader.close();
  11:         }

View Full Code Here
   1:         
   2:         StringReader in = new StringReader(content);
   3:         StringWriter out = new StringWriter();
   4:         ...
   5:         tidy.parse(in, out);
   6:         in.close();
   7:         ...
   8:         out.close();
   9:         String results = out.toString();
  10:         ...
  11:         StringWriter out = new StringWriter();
  12:         StringReader in = new StringReader(content);

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 string, there is no actual limit, so this argument must not be negative, but is otherwise ignored.
Throws:
IllegalArgumentException - If readAheadLimit is <320
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of mark(int readAheadLimit)
   1: 
   2: import java.io.StringReader;
   3: import java.util.LinkedList;
   4:         ...
   5:     public static LinkedList getTokenList(String expr) throws InvalidFormulaException {
   6:         StringReader in = new StringReader(expr);
   7:         LinkedList tokenList = new LinkedList();
   8:         ...
   9:         int c;
  10:         in.mark(1);
  11:         minusIsChar = true;
  12:         ...
  13:             str.append((char)c);
  14:             in.mark(1);

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.StringReader;
   3: import java.util.Vector;
   4:         ...
   5:     {
   6:         StringReader r = new StringReader(s);
   7:         String[] qName = parseMultiPartSQLIdentifier(r);
   8:         ...
   9:             try {
  10:                 r.mark(0);
  11:                 dot = r.read();
  12:         ...
  13:         try {
  14:             r.mark(0);

View Full Code Here

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
Returns:
The character read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read()
   1:   throws IOException {
   2:     StringReader in = new StringReader(
   3:       BufferedInputFile.read("MemoryInput.java"));
   4:         ...
   5:     int c;
   6:     while((c = in.read()) != -1)
   7:       System.out.print((char)c);
   8:   }

View Full Code Here
   1:          
   2:          StringReader in2=new StringReader(s2);
   3:          int c;
   4:         ...
   5:         while((c=in2.read())!=-1)
   6:         System.out.print((char)c);
   7:         
   8:      }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.StringReader;
   3: 
   4:         ...
   5: {
   6:     private final StringReader reader;
   7:     
   8:         ...
   9:     public StringReaderInputStream(StringReader reader)
  10:     {
  11:         ...
  12:     {
  13:         return reader.read();

View Full Code Here
   1:     {
   2:         StringReader stringReader=new StringReader(s2);
   3:         int c;
   4:         ...
   5:         while((c=stringReader.read())!=-1)
   6:             System.out.println((char)c);
   7:     }
   8:     

View Full Code Here
   1:         
   2:         StringReader in2=new StringReader(s2);
   3:         int c;
   4:         ...
   5:         while((c=in2.read())!=-1)
   6:         System.out.print((char)c);
   7:         ...
   8:         {
   9:             BufferedReader in4=new BufferedReader(new StringReader(s2));
  10:             PrintWriter out1=new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));;

View Full Code Here

read

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

View More Examples of read(cbuf[] ,int off,int len)
   1: import java.io.PrintWriter;
   2: import java.io.StringReader;
   3: import java.io.IOException;
   4:         ...
   5:         
   6:         StringReader rdr = new StringReader (SimpleTransform.transform( content_, stylesheet_, params_ ) );
   7:         int count = 0;
   8:         ...
   9:         char buff[] = new char[1024];
  10:         while( (count = rdr.read( buff, 0, buff.length ) ) > 0 ) {
  11:             out.write( buff, 0, count );

View Full Code Here
   1: 
   2:     private StringReader   m_data = new StringReader("");
   3: 
   4:         ...
   5: 
   6:         m_data = new StringReader( buf.toString() );
   7:     }
   8:         ...
   9:     {
  10:         return m_data.read( buf, off, len );
  11:     }

View Full Code Here

ready

public boolean ready()
            throws IOException
Tell whether this stream is ready to be read.
Overrides:
ready in interface Reader
Returns:
True if the next read() is guaranteed not to block for input
Throws:
IOException - If the stream is closed
Usages and Demos :

View More Examples of ready()
   1: 
   2:     private StringReader   m_data = new StringReader("");
   3: 
   4:         ...
   5: 
   6:         m_data = new StringReader( buf.toString() );
   7:     }
   8:         ...
   9:     {
  10:         log.debug("ready ? "+m_data.ready() );
  11:         ...
  12:         if(!m_data.ready())

View Full Code Here

reset

public void reset()
            throws IOException
Reset the stream to the most recent mark, or to the beginning of the string 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: 
   2: import java.io.StringReader;
   3: import java.util.LinkedList;
   4:         ...
   5:     public static LinkedList getTokenList(String expr) throws InvalidFormulaException {
   6:         StringReader in = new StringReader(expr);
   7:         LinkedList tokenList = new LinkedList();
   8:         ...
   9:         }
  10:         in.reset();
  11:         return str.toString();
  12:         ...
  13:         }
  14:         in.reset();

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.StringReader;
   3: import java.util.LinkedList;
   4:         ...
   5:     LinkedList compileString(String value) throws InvalidVariableException {
   6:         StringReader reader = new StringReader(value);
   7:         LinkedList result = new LinkedList();
   8:         StringBuffer buffer = new StringBuffer();
   9:         char previous = ' ';

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.StringReader;
   3: import java.util.Vector;
   4:         ...
   5:     {
   6:         StringReader r = new StringReader(s);
   7:         String[] qName = parseMultiPartSQLIdentifier(r);
   8:         ...
   9:                 {
  10:                     if (dot!=-1) r.reset();
  11:                     break;
  12:         ...
  13:                 throw StandardException.newException(SQLState.ID_PARSE_ERROR);
  14:              r.reset();

View Full Code Here

skip

public long skip(long ns)
            throws IOException
Skips the specified number of characters in the stream. Returns the number of characters that were skipped.

The ns parameter may be negative, even though the skip method of the Reader superclass throws an exception in this case. Negative values of ns cause the stream to skip backwards. Negative return values indicate a skip backwards. It is not possible to skip backwards past the beginning of the string.

If the entire string has been read or skipped, then this method has no effect and always returns 0.

Overrides:
skip in interface Reader
Throws:
IOException - If an I/O error occurs