Remove nullStream, add stdin, stdout & stderr
All checks were successful
PRs & Pushes / test (push) Successful in 1m44s
PRs & Pushes / build-jars (push) Successful in 1m52s
PRs & Pushes / build-apidoc (push) Successful in 1m50s

This commit is contained in:
JeremyStar™ 2024-12-26 00:37:31 +01:00
parent f3773f17a5
commit 6835823860
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 91 additions and 6 deletions

View file

@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementable.stream
import de.staropensource.engine.base.annotation.NonKotlinContact
import de.staropensource.engine.base.exception.io.IOAccessException
import de.staropensource.engine.base.implementation.stream.NullStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
@ -40,11 +39,96 @@ abstract class Stream(val streamMode: StreamMode) : AutoCloseable {
*/
companion object {
/**
* Returns a [Stream] which does nothing.
* Contains the standard input as a [Stream].
* It cannot be closed.
*
* @see <a href="https://man.archlinux.org/man/stdin.3">stdin(3)</a>
* @since v1-alpha10
*/
val nullStream: Stream = NullStream.instance
val standardInput: ReadStream = object : ReadStream() {
/**
* Contains the Java [InputStream]
* provided by [System.in].
*
* @since v1-alpha10
*/
val stream: InputStream = System.`in`
// -----> Closure
override fun close() = Unit
override fun closeStream() = Unit
// -----> Reading
override fun remaining(): Boolean? = null
override fun available(): UInt = stream.available().toUInt()
override fun readNextByte(): Byte? = stream.read().toByte()
override fun readNBytes(n: UInt): ByteArray = stream.readNBytes(n.toInt())
override fun readRemainingBytes(): ByteArray = stream.readAllBytes()
}
/**
* Contains the standard output as a [Stream].
* It cannot be closed.
*
* @see <a href="https://man.archlinux.org/man/stdout.3">stdout(3)</a>
* @since v1-alpha10
*/
val standardOutput: WriteStream = object : WriteStream() {
/**
* Contains the Java [OutputStream]
* provided by [System.out].
*
* @since v1-alpha10
*/
val stream: OutputStream = System.out
// -----> Closure
override fun close() = Unit
override fun closeStream() = Unit
// -----> Writing
override fun writeByte(byte: Byte): Stream {
stream.write(byte.toInt())
return this
}
override fun writeBytes(bytes: ByteArray): Stream {
stream.write(bytes)
return this
}
}
/**
* Contains the standard error as a [Stream].
*
* @see <a href="https://man.archlinux.org/man/stderr.3">stderr(3)</a>
* @since v1-alpha10
*/
val standardError: WriteStream = object : WriteStream() {
/**
* Contains the Java [OutputStream]
* provided by [System.err].
*
* @since v1-alpha10
*/
val stream: OutputStream = System.err
// -----> Closure
override fun close() = Unit
override fun closeStream() = Unit
// -----> Writing
override fun writeByte(byte: Byte): Stream {
stream.write(byte.toInt())
return this
}
override fun writeBytes(bytes: ByteArray): Stream {
stream.write(bytes)
return this
}
}
}
@ -58,7 +142,7 @@ abstract class Stream(val streamMode: StreamMode) : AutoCloseable {
private set
/**
* Contains the [java.io.InputStream]
* Contains the Java [InputStream]
* for this [Stream] instance.
*
* @since v1-alpha10
@ -66,7 +150,7 @@ abstract class Stream(val streamMode: StreamMode) : AutoCloseable {
private var inputStream: InputFileStream? = null
/**
* Contains the [java.io.OutputStream]
* Contains the Java [OutputStream]
* for this [Stream] instance.
*
* @since v1-alpha10

View file

@ -22,7 +22,8 @@ package de.staropensource.engine.base.implementation.stream
import de.staropensource.engine.base.implementable.stream.Stream
/**
* A [Stream] which does nothing.
* A [Stream] which does nothing
* and cannot even be closed.
*
* @since v1-alpha10
*/