public abstract class CharStream extends StreamBase
Abstract base class for char
streams, using UTF-16 code units.
Modifier and Type | Field and Description |
---|---|
static CharStream |
empty |
Constructor and Description |
---|
CharStream() |
Modifier and Type | Method and Description |
---|---|
void |
copyTo(CharStream target)
|
void |
copyTo(CharStream target,
boolean closeTarget)
Copy all remaining text until the end of this stream into a target stream, then close this stream.
|
void |
copyToFile(java.lang.String file)
Copy all remaining text until the end of this stream into a file, then close this stream.
|
static CharStream |
fileWriter(java.lang.String file)
Return a stream that will write the contents of a text file.
|
static CharStream |
fromFile(java.lang.String file)
Return a stream that will read the contents of a text file.
|
static CharStream |
fromInput(java.io.InputStream input) |
static CharStream |
fromString(java.lang.String text)
|
static CharStream |
fromString(java.lang.String text,
int offset)
|
static CharStream |
fromString(java.lang.String text,
int offset,
int length)
Return a new stream for reading from a string value.
|
boolean |
getCanUndo()
Return does this stream support
CharStream.undoRead ? |
DataType |
getDataType()
Return data type with a
DataType.code of DataType.CHAR_STREAM. |
java.lang.String |
readAndClose()
Read all remaining text until the end of this stream, then close this stream.
|
int |
readChar()
Read a single character (UTF-16 code unit) from this stream.
|
java.lang.String |
readLine()
Read a line of text content from the stream.
|
java.lang.String |
readString()
See readString(int).
|
java.lang.String |
readString(int length)
Read up to
length characters from this stream (may read less, even if the end of stream is not reached). |
static CharStream |
toBuffer(com.sap.cloud.server.odata.core.CharBuffer buffer)
Return a new byte stream which writes to a provided buffer.
|
java.lang.String |
toString()
Convert this data value to a string.
|
static CharStream |
toWriter(java.io.Writer writer) |
void |
undoRead(char value)
Undo read of one character.
|
CharStream |
withUndo()
Return a wrapper (if needed) of this stream supporting
CharStream.undoRead , or this stream if it already supports undoRead. |
void |
writeChar(char value)
Write a single character to this stream.
|
void |
writeLine(java.lang.String text)
Write line content to the stream, followed by a newline character.
|
void |
writeString(java.lang.String text)
Write to this stream the portion of
text from the specified offset with the specified length . |
close, flush, getEntityTag, getFileName, getMediaType, setEntityTag, setFileName, setMediaType
cloneMutable, equals, getTypeCode, hashCode
public static final CharStream empty
public static CharStream fromInput(java.io.InputStream input)
public static CharStream toWriter(java.io.Writer writer)
public void copyTo(CharStream target)
target
- Target parameter.public void copyTo(CharStream target, boolean closeTarget)
Copy all remaining text until the end of this stream into a target stream, then close this stream.
Also propagate the CharStream.entityTag
and CharStream.mediaType
of this stream into the target stream.
target
- Output stream.closeTarget
- Close target stream? (defaults to true
)public void copyToFile(java.lang.String file)
Copy all remaining text until the end of this stream into a file, then close this stream.
file
- Output file name.public static CharStream fileWriter(java.lang.String file)
Return a stream that will write the contents of a text file.
file
- Output file name.public static CharStream fromFile(java.lang.String file)
Return a stream that will read the contents of a text file.
file
- Input file name.public static CharStream fromString(java.lang.String text)
text
- Text parameter.public static CharStream fromString(java.lang.String text, int offset)
text
- Text parameter.offset
- Offset parameter.public static CharStream fromString(java.lang.String text, int offset, int length)
Return a new stream for reading from a string value.
text
- Source text.offset
- Starting offset (zero-based).length
- Maximum number of characters to read.public boolean getCanUndo()
Return does this stream support CharStream.undoRead
?
CharStream.undoRead
?public DataType getDataType()
Return data type with a DataType.code
of DataType.CHAR_STREAM.
getDataType
in class DataValue
DataType.code
of DataType.CHAR_STREAM.public java.lang.String readAndClose()
Read all remaining text until the end of this stream, then close this stream.
Caution: this function loads all stream content into memory at once. Consider reading a chunk-at-a-time in a loop, using CharStream.readString
.
public int readChar()
Read a single character (UTF-16 code unit) from this stream.
-1
at end of stream.public java.lang.String readLine()
Read a line of text content from the stream.
null
at end of stream.public java.lang.String readString()
public java.lang.String readString(int length)
Read up to length
characters from this stream (may read less, even if the end of stream is not reached).
length
- Maximum number of characters to read (must be greater than zero). Defaults to 20,000.length
characters, or null
if there is no remaining text in the stream.public static CharStream toBuffer(com.sap.cloud.server.odata.core.CharBuffer buffer)
Return a new byte stream which writes to a provided buffer.
buffer
- Buffer to be written to.public java.lang.String toString()
Convert this data value to a string.
If the CharStream.dataType
is defined by XML Schema Part 2: Datatypes, then the corresponding lexical format is used.
JSON format is used for structured values (arrays and objects).
public void undoRead(char value)
Undo read of one character.
DataStreamException
if undo is not supported by this stream.
value
- Character value that was previously read by the caller and is to be made available to read again.public CharStream withUndo()
Return a wrapper (if needed) of this stream supporting CharStream.undoRead
, or this stream if it already supports undoRead.
CharStream.undoRead
, or this stream if it already supports undoRead.public void writeChar(char value)
Write a single character to this stream.
value
- Character value to be written.public void writeLine(java.lang.String text)
Write line content to the stream, followed by a newline character.
text
- Line content.public void writeString(java.lang.String text)
Write to this stream the portion of text
from the specified offset
with the specified length
.
text
- Source text.