Package org.stianloader.mrjmania
Class MRJIO
java.lang.Object
org.stianloader.mrjmania.MRJIO
Polyfills concerning IO-operations, especially
regarding the
InputStream and OutputStream classes.-
Method Summary
Modifier and TypeMethodDescriptionstatic final byte @NotNull []readAllBytes(@NotNull InputStream in) Exhaustively read all bytes inside the givenInputStreaminand return the read bytes as a byte[]-array.static final @org.jetbrains.annotations.Range(from=0L, to=2147483647L) intreadNBytes(@NotNull InputStream is, byte @NotNull [] buffer, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int off, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int len) Attempt to read at mostlenamount of bytes, inserting the values into the byte-arraybufferstarting from offsetoff.static final longtransferTo(@NotNull InputStream in, @NotNull OutputStream out)
-
Method Details
-
readAllBytes
public static final byte @NotNull [] readAllBytes(@NotNull @NotNull InputStream in) throws IOException Exhaustively read all bytes inside the givenInputStreaminand return the read bytes as a byte[]-array.If the given stream is already exhausted, an empty array is returned.
After this operation,
inshould be considered as exhausted. However, it is not closed.This method is not intended for cases where large amounts of data need to be read.
- Parameters:
in- The input to read from.- Returns:
- The read data.
- Throws:
IOException- If it is not possible to read from the input stream.
-
readNBytes
@CheckReturnValue @Contract(pure=false, mutates="param1, param2") public static final @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int readNBytes(@NotNull @NotNull InputStream is, byte @NotNull [] buffer, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int off, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int len) throws IOException Attempt to read at mostlenamount of bytes, inserting the values into the byte-arraybufferstarting from offsetoff.This method may read fewer than
lenbytes if the . See the return value of this method- Parameters:
is- The input stream to read data from.buffer- The byte-array to write data to.off- The offset in the byte-array from which the data should be written to.len- The maximum amount of bytes to read.- Returns:
- The actually read amount of bytes.
- Throws:
IOException- If it is not possible to read from the input stream.
-
transferTo
public static final long transferTo(@NotNull @NotNull InputStream in, @NotNull @NotNull OutputStream out) throws IOException Transfers the contents of theInputStreaminto theOutputStreamout.After this operation,
inshould be considered as exhausted. However, it is not closed.- Parameters:
in- The input to transfer.out- The target of the transfer.- Returns:
- Amount of bytes transfered.
- Throws:
IOException- Raised when it is not possible to read from the input stream.
-