Class ByteSource

  • Direct Known Subclasses:
    TypeAwareByteSource

    public class ByteSource
    extends java.lang.Object
    A readable stateful source of bytes. Use it as supplier for InputStreams.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.InputStream openBufferedStream()
      Wrap result InputStream object into BufferedInputStream object.
      java.io.InputStream openStream()
      Return new InputStream object which can be read and closed naturally.
      byte[] read()
      Read internal byte source and return it as byte array.
      static ByteSource wrap​(byte[] source)
      Create an instance of the object from given bytes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ByteSource

        public ByteSource​(@Nonnull
                          ByteSource source)
      • ByteSource

        public ByteSource​(@Nonnull
                          java.net.URL sourceUrl)
    • Method Detail

      • wrap

        @Nonnull
        public static ByteSource wrap​(@Nonnull
                                      byte[] source)
        Create an instance of the object from given bytes.
        Parameters:
        source - bytes to use to create the instance
        Returns:
        current class instance
      • openStream

        @Nonnull
        public java.io.InputStream openStream()
                                       throws java.io.IOException
        Return new InputStream object which can be read and closed naturally.
        Returns:
        stream
        Throws:
        java.io.IOException - reading error or null byte source
      • openBufferedStream

        @Nonnull
        public java.io.InputStream openBufferedStream()
                                               throws java.io.IOException
        Wrap result InputStream object into BufferedInputStream object.
        Returns:
        buffered stream
        Throws:
        java.io.IOException - reading error or null byte source
      • read

        @Nonnull
        public byte[] read()
                    throws java.io.IOException
        Read internal byte source and return it as byte array. The result will be cached if not cached already.
        Returns:
        read data
        Throws:
        java.io.IOException - reading error or null byte source