Class MRJIO

java.lang.Object
org.stianloader.mrjmania.MRJIO

public class MRJIO extends Object
Polyfills concerning IO-operations, especially regarding the InputStream and OutputStream classes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final byte @NotNull []
    Exhaustively read all bytes inside the given InputStream in and return the read bytes as a byte[]-array.
    static final @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int
    readNBytes(@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 most len amount of bytes, inserting the values into the byte-array buffer starting from offset off.
    static final long
    transferTo(@NotNull InputStream in, @NotNull OutputStream out)
    Transfers the contents of the InputStream in to the OutputStream out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • readAllBytes

      public static final byte @NotNull [] readAllBytes(@NotNull @NotNull InputStream in) throws IOException
      Exhaustively read all bytes inside the given InputStream in and return the read bytes as a byte[]-array.

      If the given stream is already exhausted, an empty array is returned.

      After this operation, in should 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 most len amount of bytes, inserting the values into the byte-array buffer starting from offset off.

      This method may read fewer than len bytes 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 the InputStream in to the OutputStream out.

      After this operation, in should 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.