ByteStream
open class ByteStream : StreamBase, @unchecked Sendable
Abstract base class for byte streams.
-
Immutable empty byte stream, for which
readBytewill always return-1.Declaration
Swift
public static let empty: ByteStream -
Immutable empty byte stream (representing the case where there is no stream available), for which
readBytewill always return-1.See also
empty.Declaration
Swift
public static let none: ByteStream -
Default initializer.
Declaration
Swift
override public init() -
On platforms where the
binarytype is a mutable array, enable an optimization where the buffer used for the default implementation ofreadBinary(which callsreadBytein a loop) can reuse and return the internal buffer’s internal array (across multiplereadBinarycalls). If enabling this optimization, be aware that multiplereadBinarycalls can return the same array. Currently applicable only to C# and Java, and otherwise ignored.Declaration
Swift
open func allowReadBinaryToReuseBufferInternalArray() -
Assuming this stream is a UTF-8 byte stream, map it to a character stream (of UTF-16 code units).
Declaration
Swift
open func asText() -> CharStreamReturn Value
New character stream, which reads from this UTF-8 byte stream and converts to UTF-16 code units.
-
Does this stream support
undoRead?See also
withUndo.Declaration
Swift
open var canUndo: Bool { get } -
Close this stream. Automatically calls
flushbefore closing. This function can be safely called if the stream is already closed.Declaration
Swift
override open func close() throws -
Copy all remaining data until the end of this stream into a target stream, then close this stream. Also propagate the
entityTagandmediaTypeof this stream into the target stream.Declaration
Swift
open func copyTo(target: ByteStream, closeTarget: Bool = true) throwsParameters
targetOutput stream.
closeTargetClose target stream? (defaults to
true) -
Copy all remaining data until the end of the stream into a file, then close this stream.
Declaration
Swift
open func copyToFile(_ file: String) throwsParameters
fileOutput file name.
-
Data type with a
DataType.codeofDataType.BYTE_STREAM.Declaration
Swift
override open var dataType: DataType { get } -
Declaration
Swift
open class func fileWriter(file: String) throws -> ByteStreamParameters
fileOutput file name.
Return Value
A stream that will write the contents of a data file.
-
Declaration
Swift
open class func fromBinary(data: Data, offset: Int = (0 as Int), length: Int = (2147483647 as Int)) -> ByteStreamParameters
dataSource data.
offsetStarting offset (zero-based).
lengthMaximum number of bytes to read.
Return Value
A new stream for reading from a binary value.
-
Declaration
Swift
open class func fromFile(_ file: String) throws -> ByteStreamParameters
fileInput file name.
Return Value
A stream that will read the contents of a data file.
-
Declaration
Swift
open class func fromStream(_ stream: StreamBase) -> ByteStreamParameters
streamUnderlying stream.
Return Value
stream(ifstreamis a ByteStream) orByteStream.fromText(stream)(ifstreamis a CharStream). -
Declaration
Swift
open class func fromText(stream: CharStream) -> ByteStreamParameters
streamUnderlying character stream.
Return Value
A new UTF-8 byte stream which reads from an underlying UTF-16 character stream.
-
Read all remaining data until the end of the 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
readBinary.Declaration
Swift
open func readAndClose() throws -> DataReturn Value
The remaining data.
-
Read up to
lengthbytes from this stream (may read less, even if the end of stream is not reached).Declaration
Swift
open func readBinary(length: Int = (20000 as Int)) throws -> Data?Parameters
lengthMaximum number of bytes to read (must be greater than zero). Defaults to 20,000.
Return Value
Binary value with at most
lengthbytes, ornilif there is no remaining data in the stream. -
Read a single byte from this stream.
Declaration
Swift
open func readByte() throws -> IntReturn Value
Unsigned integer equivalent of the byte read, or
-1at end of stream. -
Declaration
Swift
open class func toBuffer(_ buffer: ByteBuffer) -> ByteStreamParameters
bufferBuffer to be written to.
Return Value
A new byte stream which writes to a provided buffer.
-
Convert this data value to a string. If the
dataTypeis defined by XML Schema Part 2: Datatypes, then the corresponding lexical format is used. JSON format is used for structured values (arrays and objects).Declaration
Swift
override open func toString() -> StringReturn Value
Lexical representation of this data value.
-
Data type code of the wrapped value, equivalent to
dataType.code.Declaration
Swift
override open var typeCode: Int { get } -
Undo read of one byte.
Throws
DataStreamExceptionif undo is not supported by this stream.Declaration
Swift
open func undoRead(_ value: Int) throwsParameters
valueByte value that was previously read by the caller and is to be made available to read again.
-
Fluent API to set the
mediaTypefor this stream.Declaration
Swift
open func withType(_ type: String?) -> ByteStreamParameters
typeMedia type.
Return Value
This stream.
-
See also
canUndo.Declaration
Swift
open func withUndo() throws -> ByteStreamReturn Value
A wrapper (if needed) of this stream supporting
undoRead, or this stream if it already supports undoRead. -
Write to this stream the portion of
datafrom the specifiedoffsetwith the specifiedlength.Declaration
Swift
open func writeBinary(data: Data) throwsParameters
dataSource data.
-
Write a single byte to this stream.
Declaration
Swift
open func writeByte(_ value: Int) throwsParameters
valueByte value to be written.