public abstract class RResult extends Object implements RResponse
Should be sub-classed to implement createReader(),
getString(), or getEncoding() and one of
createInputStream(), createByteBuffer(),
createURLConnection(), or getResourceURL().
The base class contains many convenience methods to convert between all
supported data formats (String, Reader, InputStream, ByteBuffer, URL).
The conversion between character data and binary data is done with the
Charset returned by getCharset(), which by default returns
the Charset specified by getEncoding().
If the correct encoding was not set by the resource look-up, it should be set
before converting data. Otherwise, the results depend on the default locale.
BytesResult,
FileResult,
InputStreamResult,
StringResult,
URLResult| Modifier and Type | Class and Description |
|---|---|
protected static class |
RResult.ByteBufferInputStream |
protected static class |
RResult.InputStreamURLConnection |
static class |
RResult.ResultType
Describes the format of the result data.
|
| Constructor and Description |
|---|
RResult(RRequest request) |
RResult(RRequest request,
String systemId) |
RResult(String uri,
String publicId,
String systemId,
String baseUri) |
| Modifier and Type | Method and Description |
|---|---|
BufferedInputStream |
asBufferedInputStream()
Like
asInputStream(), but always returns a buffered stream. |
ByteBuffer |
asByteBuffer()
Returns the resource as a byte buffer, converting it if necessary.
|
ResolvingException |
asException()
Represents the warnings as single exception.
|
InputStream |
asInputStream()
Returns the resource as an input stream, converting it if necessary.
|
Reader |
asReader()
Returns the resource as a reader, converting it if necessary.
|
String |
asString()
Returns the resource as a string, converting it if necessary.
|
URLConnection |
asURLConnection()
Returns the resource as URL connection, converting it if necessary.
|
protected ByteBuffer |
bufferFrom(InputStream is) |
protected ByteBuffer |
bufferFrom(String s) |
protected byte[] |
bytesFrom(String s) |
protected ByteBuffer |
createByteBuffer()
Optional: creates a byte buffer to access the resource.
|
protected InputStream |
createInputStream()
Optional: creates an input stream to access the resource.
|
protected Reader |
createReader()
Optional: creates a reader to access the resource.
|
protected URLConnection |
createURLConnection()
Optional: creates a URL connection to access the resource.
|
protected String |
expandSystemId(String baseId,
String systemId)
Calculates the resource location.
|
protected InputStream |
fromStreamOrBuffer() |
protected InputStream |
fromStreamOrBufferOrUrl() |
protected InputStream |
fromStreamOrUrl() |
protected String |
fromStringOrReader() |
String |
getBaseUri()
Returns the base URI of the request
|
ByteBuffer |
getByteBuffer()
Returns the resource as byte buffer, or
null |
Charset |
getCharset()
Returns the charset for the result's encoding,
or the default charset of this JVM.
|
protected Map<String,String> |
getDefaultUrlConnectionHeader() |
String |
getEncoding()
Returns the resource's encoding.
|
InputStream |
getInputStream()
Returns the resource as input stream, or
null |
String |
getPublicId()
Returns the request public ID
|
Reader |
getReader()
Returns the resource as a reader, or
null. |
RRequest |
getRequest()
Returns the request for this result.
|
String |
getResolvedSystemId()
|
URL |
getResourceURL()
Returns the resource as URL, or
null |
protected URL |
getResourceURLOrSystemId()
Return the resource URL,
or the system ID as URL.
|
RResult |
getResult()
Returns result if present, otherwise throws
RResponse.asException(). |
abstract RResult.ResultType |
getResultType()
Indicates the native format of this result.
|
String |
getString()
Returns the resource as string, or
null |
String |
getSystemId()
Returns the system ID of the resolved resource.
|
String |
getUri()
Returns the request URI
|
String |
getUriOrId()
Returns uri or resolved system id.
|
URLConnection |
getURLConnection()
Returns the resource as URL connection, or
null |
List<Exception> |
getWarningsLog()
Returns a list of non-critical exceptions that occurred during look-up.
|
boolean |
hasResult()
Returns true if look-up found a result.
|
protected Reader |
readerFrom(InputStream is) |
protected String |
resolveSystemId() |
protected RuntimeException |
resolvingException(Throwable t) |
protected RuntimeException |
resourceUnaccessible() |
void |
setDefaultEncoding(String enc)
Sets the default encoding, which is used when no other encoding is defined.
|
void |
setEncoding(String enc)
Sets the result's encoding.
|
protected InputStream |
streamFrom(ByteBuffer bb) |
protected InputStream |
streamFrom(String s) |
protected InputStream |
streamFrom(URLConnection uc) |
protected InputStream |
streamFromURLConnection() |
protected String |
stringFrom(ByteBuffer bb) |
protected String |
stringFrom(Reader r) |
String |
toString() |
boolean |
trySetEncoding(String enc)
Tries to set the result's encoding, returns true iff it was successful.
|
public RResult(RRequest request)
public boolean hasResult()
RResponsepublic RResult getResult()
RResponseRResponse.asException().public List<Exception> getWarningsLog()
RResponsegetWarningsLog in interface RResponsepublic ResolvingException asException()
RResponseasException in interface RResponsepublic RRequest getRequest()
getRequest in interface RResponsepublic String getUri()
public String getPublicId()
public String getSystemId()
getResolvedSystemId()public String getBaseUri()
public String getUriOrId()
public String getResolvedSystemId()
protected String resolveSystemId()
protected String expandSystemId(String baseId, String systemId)
baseId - systemId - public abstract RResult.ResultType getResultType()
public Reader getReader()
null.asReader()protected Reader createReader() throws Exception
Exceptionpublic InputStream getInputStream()
nullasInputStream()protected InputStream createInputStream() throws Exception
Exceptionpublic String getString()
nullpublic ByteBuffer getByteBuffer()
nullprotected ByteBuffer createByteBuffer() throws Exception
Exceptionpublic URLConnection getURLConnection()
nullprotected URLConnection createURLConnection() throws Exception
Exceptionpublic URL getResourceURL() throws Exception
nullExceptionprotected URL getResourceURLOrSystemId() throws Exception
Exceptionpublic void setDefaultEncoding(String enc)
enc - public boolean trySetEncoding(String enc)
enc - public void setEncoding(String enc)
enc - IllegalStateException - if encoding could not be changed.public String getEncoding()
public Charset getCharset()
public Reader asReader()
See the docs of RResult for notes on data conversion.
public InputStream asInputStream()
See the docs of RResult for notes on data conversion.
public ByteBuffer asByteBuffer()
See the docs of RResult for notes on data conversion.
public String asString()
See the docs of RResult for notes on data conversion.
public URLConnection asURLConnection()
See the docs of RResult for notes on data conversion.
public BufferedInputStream asBufferedInputStream()
asInputStream(), but always returns a buffered stream.protected String fromStringOrReader()
protected InputStream fromStreamOrBuffer()
protected InputStream fromStreamOrBufferOrUrl()
protected InputStream fromStreamOrUrl()
protected String stringFrom(ByteBuffer bb)
protected Reader readerFrom(InputStream is) throws ResolvingException
ResolvingExceptionprotected InputStream streamFrom(String s) throws ResolvingException
ResolvingExceptionprotected InputStream streamFrom(ByteBuffer bb)
protected InputStream streamFromURLConnection()
protected InputStream streamFrom(URLConnection uc)
protected ByteBuffer bufferFrom(String s) throws ResolvingException
ResolvingExceptionprotected ByteBuffer bufferFrom(InputStream is)
protected byte[] bytesFrom(String s) throws ResolvingException
ResolvingExceptionprotected RuntimeException resolvingException(Throwable t)
protected RuntimeException resourceUnaccessible()
Copyright © 2015. All rights reserved.