Package 

Class ByteArrayBinaryResource

  • All Implemented Interfaces:
    com.facebook.binaryresource.BinaryResource

    
    public final class ByteArrayBinaryResource
     implements BinaryResource
                        

    A trivial implementation of BinaryResource that wraps a byte array

    • Method Summary

      Modifier and Type Method Description
      Long size() Returns the size of this source in bytes.
      InputStream openStream() Opens a new InputStream for reading from this source.
      ByteArray read() Get the underlying byte array
      • Methods inherited from class java.lang.Object

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

      • ByteArrayBinaryResource

        ByteArrayBinaryResource(ByteArray bytes)
    • Method Detail

      • size

         Long size()

        Returns the size of this source in bytes. This may be a heavyweight operation that will open a stream, read (or skip, if possible) to the end of the stream and return the total number of bytes that were read.

        For some sources, such as a file, this method may use a more efficient implementation. Note that in such cases, it is possible that this method will return a different number of bytes than would be returned by reading all of the bytes (for example, some special files may return a size of 0 despite actually having content when read).

        In either case, if this is a mutable source such as a file, the size it returns may not be the same number of bytes a subsequent read would return.

      • openStream

         InputStream openStream()

        Opens a new InputStream for reading from this source. This method should return a new, independent stream each time it is called.

        The caller is responsible for ensuring that the returned stream is closed.