Package ball.activation
Class ReaderWriterDataSource
- java.lang.Object
-
- ball.activation.AbstractDataSource
-
- ball.activation.FilterDataSource
-
- ball.activation.ReaderWriterDataSource
-
- All Implemented Interfaces:
DataSourceDefaultMethods
,DataSource
- Direct Known Subclasses:
JAXBDataSource
,TextTable
,ThrowableDataSource
public class ReaderWriterDataSource extends FilterDataSource
DataSource
implementation that provides aBufferedReader
wrapping theDataSource
InputStream
and aPrintWriter
wrapping theDataSource
OutputStream
.- Author:
- Allen D. Ball
-
-
Field Summary
Fields Modifier and Type Field Description protected static Charset
CHARSET
-
Fields inherited from interface ball.activation.DataSourceDefaultMethods
APPLICATION_OCTET_STREAM, APPLICATION_XML, CONTENT_TYPE, TEXT_HTML, TEXT_PLAIN
-
-
Constructor Summary
Constructors Constructor Description ReaderWriterDataSource(String name, String type)
ReaderWriterDataSource(String name, String type, Charset charset)
ReaderWriterDataSource(String name, String type, Charset charset, String content)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BufferedReader
getBufferedReader()
Method to return a newBufferedReader
to read the underlyingInputStream
.Charset
getCharset()
PrintStream
getPrintStream()
Method to return a newPrintStream
to write to the underlyingOutputStream
.PrintWriter
getPrintWriter()
Method to return a newPrintWriter
to write to the underlyingOutputStream
.Reader
getReader()
Method to return a newReader
to read the underlyingInputStream
.Writer
getWriter()
Method to return a newWriter
to write to the underlyingOutputStream
.protected static String
nameOf(Charset charset)
Convenience method to get the name of aCharset
.String
toString()
void
writeTo(PrintWriter writer)
Method to write the contents of thisDataSource
to aPrintWriter
.-
Methods inherited from class ball.activation.FilterDataSource
getContentType, getDataSource, getInputStream, getName, getOutputStream, setContentType, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ball.activation.DataSourceDefaultMethods
clear, getInputStream, getOutputStream, length, wrap, wrap
-
-
-
-
Constructor Detail
-
ReaderWriterDataSource
@ConstructorProperties({"name","contentType"}) public ReaderWriterDataSource(String name, String type)
- Parameters:
name
- Initial"Name"
attribute value.type
- Initial"ContentType"
attribute value.
-
ReaderWriterDataSource
@ConstructorProperties({"name","contentType","charset"}) public ReaderWriterDataSource(String name, String type, Charset charset)
- Parameters:
name
- Initial"Name"
attribute value.type
- Initial"ContentType"
attribute value.charset
- TheCharset
used to encode theOutputStream
.
-
ReaderWriterDataSource
@ConstructorProperties({"name","contentType","charset",""}) public ReaderWriterDataSource(String name, String type, Charset charset, String content)
- Parameters:
name
- Initial"Name"
attribute value.type
- Initial"ContentType"
attribute value.charset
- TheCharset
used to encode theOutputStream
.content
- The initial contentString
.
-
-
Method Detail
-
getCharset
public Charset getCharset()
- Returns:
- The Charset.
-
getReader
public Reader getReader() throws IOException
Method to return a newReader
to read the underlyingInputStream
.- Returns:
- A
Reader
wrapping theDataSource
InputStream
. - Throws:
IOException
- If an I/O exception occurs.- See Also:
FilterDataSource.getInputStream()
-
getWriter
public Writer getWriter() throws IOException
Method to return a newWriter
to write to the underlyingOutputStream
.- Returns:
- A
Writer
wrapping theDataSource
OutputStream
. - Throws:
IOException
- If an I/O exception occurs.- See Also:
FilterDataSource.getOutputStream()
-
getBufferedReader
public BufferedReader getBufferedReader() throws IOException
Method to return a newBufferedReader
to read the underlyingInputStream
.- Returns:
- A
BufferedReader
wrapping theDataSource
InputStream
. - Throws:
IOException
- If an I/O exception occurs.- See Also:
FilterDataSource.getInputStream()
-
getPrintWriter
public PrintWriter getPrintWriter() throws IOException
Method to return a newPrintWriter
to write to the underlyingOutputStream
.- Returns:
- A
PrintWriter
wrapping theDataSource
OutputStream
. - Throws:
IOException
- If an I/O exception occurs.- See Also:
FilterDataSource.getOutputStream()
-
getPrintStream
public PrintStream getPrintStream() throws IOException
Method to return a newPrintStream
to write to the underlyingOutputStream
.- Returns:
- A
PrintStream
wrapping theDataSource
OutputStream
. - Throws:
IOException
- If an I/O exception occurs.- See Also:
FilterDataSource.getOutputStream()
-
writeTo
public void writeTo(PrintWriter writer) throws IOException
Method to write the contents of thisDataSource
to aPrintWriter
.- Parameters:
writer
- The targetPrintWriter
.- Throws:
IOException
- If a problem is encountered opening or reading theBufferedReader
or writing to thePrintWriter
.- See Also:
getBufferedReader()
-
-