Package com.bc.ceres.util
Class TemplateReader
java.lang.Object
java.io.Reader
java.io.FilterReader
com.bc.ceres.util.TemplateReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
A template reader replaces any occurences of
${key} or $key
in the underlying stream with the string representations of any non-null value returned by a given
resolver for that key.-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class java.io.FilterReader
in -
Constructor Summary
ConstructorsConstructorDescriptionTemplateReader(Reader in, TemplateReader.Resolver resolver) Constructs a template reader for the given reader stream and the given resolver.TemplateReader(Reader in, Map map) Constructs a template reader for the given reader stream and a resolver given by aMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the stream.charGets the key indicator.voidmark(int readAheadLimit) Mark the present position in the stream.booleanTell whether this stream supports the mark() operation.intread()Read a single character.intread(char[] cbuf) Read characters into an array.intread(char[] cbuf, int off, int len) Read characters into a portion of an array.intread(CharBuffer target) Attempts to read characters into the specified character buffer.readAll()Reads all content.booleanready()Tell whether this stream is ready to be read.voidreset()Reset the stream.voidsetKeyIndicator(char keyIndicator) Sets the key indicator.longskip(long n) Skip characters.Methods inherited from class java.io.Reader
nullReader, transferTo
-
Constructor Details
-
TemplateReader
Constructs a template reader for the given reader stream and a resolver given by aMap.- Parameters:
in- the underlying readermap- the map to serve as resolver
-
TemplateReader
Constructs a template reader for the given reader stream and the given resolver.- Parameters:
in- the underlying readerresolver- the resolver
-
-
Method Details
-
getKeyIndicator
public char getKeyIndicator()Gets the key indicator.- Returns:
- the key indicator, defaults to '$'.
-
setKeyIndicator
public void setKeyIndicator(char keyIndicator) Sets the key indicator.- Parameters:
keyIndicator- the key indicator, must not be a digit, letter or whitespace.
-
readAll
Reads all content.- Returns:
- the content
- Throws:
IOException- if an I/O error occurs
-
read
Read a single character.- Overrides:
readin classFilterReader- Throws:
IOException- If an I/O error occurs
-
read
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.- Overrides:
readin classReader- Parameters:
cbuf- Destination buffer- 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
-
read
Read characters into a portion of an array.- Overrides:
readin classFilterReader- Throws:
IOException- If an I/O error occurs
-
read
Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.- Specified by:
readin interfaceReadable- Overrides:
readin classReader- Parameters:
target- the buffer to read characters into- Returns:
- The number of characters added to the buffer, or -1 if this source of characters is at its end
- Throws:
IOException- if an I/O error occursNullPointerException- if target is nullReadOnlyBufferException- if target is a read only buffer
-
skip
Skip characters.- Overrides:
skipin classFilterReader- Throws:
IOException- If an I/O error occurs
-
ready
Tell whether this stream is ready to be read.- Overrides:
readyin classFilterReader- Throws:
IOException- If an I/O error occurs
-
markSupported
public boolean markSupported()Tell whether this stream supports the mark() operation.- Overrides:
markSupportedin classFilterReader
-
mark
Mark the present position in the stream.- Overrides:
markin classFilterReader- Throws:
IOException- If an I/O error occurs
-
reset
Reset the stream.- Overrides:
resetin classFilterReader- Throws:
IOException- If an I/O error occurs
-
close
Close the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterReader- Throws:
IOException- If an I/O error occurs
-