Class Slice

java.lang.Object
com.unascribed.ears.api.Slice

public final class Slice extends Object
An immutable view into a byte array.
  • Field Details

    • EMPTY

      public static final Slice EMPTY
  • Constructor Details

    • Slice

      public Slice(byte[] arr)
    • Slice

      public Slice(byte[] arr, int ofs, int len)
  • Method Details

    • get

      public byte get(int idx)
    • size

      public int size()
    • slice

      public Slice slice(int offset, int length)
    • slice

      public Slice slice(int offset)
    • toByteArray

      public byte[] toByteArray()
    • writeTo

      public void writeTo(OutputStream os) throws IOException
      Throws:
      IOException
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(byte[] bys)
    • equals

      public boolean equals(byte[] bys, int ofs, int len)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static byte[] of(byte[] arr, int ofs, int len)
    • parse

      public static Slice parse(String str)
      Convenience method to construct a Slice from a readable literal. Not intended for data parsing - no validation is performed and various errors can be thrown by this method for malformed data.

      The format is simple; every pair of characters is interpreted as a hex byte, and any chars between square brackets ([ and ]) have their lower 8 bits passed through as-is. For example:
      89[PNG\r\n]1A[\n]
      will become
      89 50 4E 47 0D 0A 1A 0A | .PNG....