API: streams
Source:
io/streams.ts
Provides core functionality for input/output stream management, including stream creation, data transfer, and byte array handling.
Classes
Streams
The Streams class provides static utility methods for stream creation,
manipulation, and data copying.
Methods
copy
copy (input:InputStream, output:OutputStream):voidCopies all bytes from the input stream to the output stream.
This method is generally used for smaller streams.
@param input The source {@link InputStream}.
@param output The destination {@link OutputStream}.
copyLarge
copyLarge (input:InputStream, output:OutputStream):voidCopies all bytes from the input stream to the output stream using a large buffer,
suitable for large file transfers.
@param input The source {@link InputStream}.
@param output The destination {@link OutputStream}.
getResourceAsByteArrayInputStream
getResourceAsByteArrayInputStream (path:string):InputStreamCreates a new {@link InputStream} from a resource accessible via the class loader.
This is typically used to read bundled resources within the application runtime.
@param path The path to the resource.
@returns A new {@link InputStream} instance for the resource.
createByteArrayInputStream
createByteArrayInputStream (data:any[]):InputStreamCreates a new {@link InputStream} from a JavaScript byte array (
any[]).
@param data The JavaScript array of byte values (number[]).
@returns A new {@link InputStream} instance initialized with the byte data.
createByteArrayOutputStream
createByteArrayOutputStream ():OutputStreamCreates a new {@link OutputStream} that writes data into an in-memory byte array.
This is typically used as a buffer to capture output before processing it.
@returns A new {@link OutputStream} instance backed by a byte array.
createInputStream
createInputStream (native:any):InputStreamWraps a native (Java) InputStream object into a new JavaScript {@link InputStream} instance.
@param native The underlying native InputStream object.
@returns A new {@link InputStream} wrapper.
createOutputStream
createOutputStream (native:any):OutputStreamWraps a native (Java) OutputStream object into a new JavaScript {@link OutputStream} instance.
Note: This method is not static in the original definition, but is placed here for completeness
and consistency with other factory methods.
@param native The underlying native OutputStream object.
@returns A new {@link OutputStream} wrapper.
InputStream
Represents an input stream for reading bytes.
This class wraps a native stream object and provides methods for reading data.
Methods
read
read ():numberReads the next byte of data from this input stream.
@returns The next byte of data, or -1 if the end of the stream is reached.
readBytes
readBytes ():any[]Reads all remaining bytes from the stream and returns them as a JavaScript array.
@returns A JavaScript array (number[]) of the byte values.
readBytesNative
readBytesNative ():any[]Reads all remaining bytes from the stream and returns the native Java byte array.
@returns The native Java byte array object.
readText
readText ():stringReads all remaining bytes from the stream and converts them to a string
using the platform's default character encoding.
@returns The content of the stream as a string.
close
close ():voidCloses this input stream and releases any system resources associated with it.
isValid
isValid ():booleanChecks if the underlying native stream object is defined and non-null.
@returns True if the stream is valid, false otherwise.
OutputStream
Represents an output stream for writing bytes.
This class wraps a native stream object and provides methods for writing data.
Methods
write
write (byte:number):voidWrites the specified byte to this output stream.
@param byte The byte (as a number 0-255) to write.
writeBytes
writeBytes (data:any[]):voidWrites the entire content of a JavaScript byte array to this output stream.
@param data The JavaScript array (number[]) of byte values to write.
writeBytesNative
writeBytesNative (data:any[]):voidWrites the entire content of a native Java byte array to this output stream.
@param data The native Java byte array object to write.
writeText
writeText (text:string):voidConverts the string to bytes using the platform's default character encoding
and writes them to this output stream.
@param text The string content to write.
close
close ():voidCloses this output stream and releases any system resources associated with it.
getBytes
getBytes ():any[]Retrieves the content written to this stream as a JavaScript byte array.
This is typically used with a ByteArrayOutputStream.
@returns A JavaScript array (number[]) of the byte values written to the stream.
getBytesNative
getBytesNative ():any[]Retrieves the content written to this stream as the native Java byte array.
This is typically used with a ByteArrayOutputStream.
@returns The native Java byte array object.
getText
getText ():stringRetrieves the content written to this stream as a string using the platform's
default character encoding. This is typically used with a ByteArrayOutputStream.
@returns The content of the stream as a string.
isValid
isValid ():booleanChecks if the underlying native stream object is defined and non-null.
@returns True if the stream is valid, false otherwise.