public class ReaderWriterDataSource extends FilterDataSource
DataSource
implementation that provides a
BufferedReader
wrapping the DataSource
InputStream
and a PrintWriter
wrapping the
DataSource
OutputStream
.Modifier and Type | Field and Description |
---|---|
protected static Charset |
CHARSET |
APPLICATION_OCTET_STREAM, APPLICATION_XML, CONTENT_TYPE, TEXT_HTML, TEXT_PLAIN
Constructor and Description |
---|
ReaderWriterDataSource(String name,
String type) |
ReaderWriterDataSource(String name,
String type,
Charset charset) |
ReaderWriterDataSource(String name,
String type,
Charset charset,
String content) |
Modifier and Type | Method and Description |
---|---|
BufferedReader |
getBufferedReader()
Method to return a new
BufferedReader to read the underlying
InputStream . |
Charset |
getCharset()
|
PrintStream |
getPrintStream()
Method to return a new
PrintStream to write to the underlying
OutputStream . |
PrintWriter |
getPrintWriter()
Method to return a new
PrintWriter to write to the underlying
OutputStream . |
Reader |
getReader()
Method to return a new
Reader to read the underlying
InputStream . |
Writer |
getWriter()
Method to return a new
Writer to write to the underlying
OutputStream . |
protected static String |
nameOf(Charset charset)
Convenience method to get the name of a
Charset . |
String |
toString() |
void |
writeTo(PrintWriter writer)
Method to write the contents of this
DataSource to a PrintWriter . |
getContentType, getDataSource, getInputStream, getName, getOutputStream, setContentType, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
clear, getInputStream, getOutputStream, length, wrap, wrap, writeTo
@ConstructorProperties(value={"name","contentType"}) public ReaderWriterDataSource(String name, String type)
name
- Initial "Name"
attribute value.type
- Initial "ContentType"
attribute
value.@ConstructorProperties(value={"name","contentType","charset"}) public ReaderWriterDataSource(String name, String type, Charset charset)
name
- Initial "Name"
attribute value.type
- Initial "ContentType"
attribute
value.charset
- The Charset
used to encode the
OutputStream
.@ConstructorProperties(value={"name","contentType","charset",""}) public ReaderWriterDataSource(String name, String type, Charset charset, String content)
name
- Initial "Name"
attribute value.type
- Initial "ContentType"
attribute
value.charset
- The Charset
used to encode the
OutputStream
.content
- The initial content String
.public Charset getCharset()
public Reader getReader() throws IOException
Reader
to read the underlying
InputStream
.Reader
wrapping the
DataSource
InputStream
.IOException
- If an I/O exception occurs.FilterDataSource.getInputStream()
public Writer getWriter() throws IOException
Writer
to write to the underlying
OutputStream
.Writer
wrapping the
DataSource
OutputStream
.IOException
- If an I/O exception occurs.FilterDataSource.getOutputStream()
public BufferedReader getBufferedReader() throws IOException
BufferedReader
to read the underlying
InputStream
.BufferedReader
wrapping the
DataSource
InputStream
.IOException
- If an I/O exception occurs.FilterDataSource.getInputStream()
public PrintWriter getPrintWriter() throws IOException
PrintWriter
to write to the underlying
OutputStream
.PrintWriter
wrapping the
DataSource
OutputStream
.IOException
- If an I/O exception occurs.FilterDataSource.getOutputStream()
public PrintStream getPrintStream() throws IOException
PrintStream
to write to the underlying
OutputStream
.PrintStream
wrapping the
DataSource
OutputStream
.IOException
- If an I/O exception occurs.FilterDataSource.getOutputStream()
public void writeTo(PrintWriter writer) throws IOException
DataSource
to a PrintWriter
.writer
- The target PrintWriter
.IOException
- If a problem is encountered opening or
reading the BufferedReader
or
writing to the PrintWriter
.getBufferedReader()
Copyright © 2015–2020 Allen D. Ball. All rights reserved.