Class BeanByteSource

    • Constructor Detail

      • BeanByteSource

        protected BeanByteSource()
        Creates an instance.
    • Method Detail

      • getFileName

        public Optional<String> getFileName()
        Gets the file name of the source.

        Most sources originate from a file-based location. This is captured and returned here where available.

        Returns:
        the file name, empty if not known
      • getFileNameOrThrow

        public String getFileNameOrThrow()
        Gets the file name of the source.

        Most sources originate from a file-based location. This is captured and returned here where available.

        Returns:
        the file name
        Throws:
        IllegalArgumentException - if the file name is not known
      • readUtf8

        public String readUtf8()
        Reads the source, converting to UTF-8.
        Returns:
        the UTF-8 string
        Throws:
        UncheckedIOException - if an IO error occurs
      • readUtf8UsingBom

        public String readUtf8UsingBom()
        Reads the source, converting to UTF-8 using a Byte-Order Mark if available.
        Returns:
        the UTF-8 string
        Throws:
        UncheckedIOException - if an IO error occurs
      • asCharSourceUtf8

        public BeanCharSource asCharSourceUtf8()
        Returns a CharSource for the same bytes, converted to UTF-8.
        Returns:
        the equivalent CharSource
      • asCharSourceUtf8UsingBom

        public BeanCharSource asCharSourceUtf8UsingBom()
        Returns a CharSource for the File, converted to UTF-8 using a Byte-Order Mark if available.
        Returns:
        the equivalent CharSource
      • toHash

        public ArrayByteSource toHash​(HashFunction hashFunction)
        Returns a new byte source containing the hash of the content of this byte source.

        The returned hash is in byte form.

        Parameters:
        hashFunction - the hash function to use, see Hashing
        Returns:
        the new byte source representing the hash
        Throws:
        UncheckedIOException - if an IO error occurs
      • toHashString

        public String toHashString​(HashFunction hashFunction)
        Returns a new byte source containing the hash of the content of this byte source.

        The returned hash is in string form. This form is intended to be compatible with tools like the UNIX md5sum command.

        Parameters:
        hashFunction - the hash function to use, see Hashing
        Returns:
        the new byte source representing the hash
        Throws:
        UncheckedIOException - if an IO error occurs
      • toBase64String

        public String toBase64String()
        Encodes the byte source using base-64, returning a string.

        Equivalent to toBase64().readUtf8().

        Returns:
        the base-64 encoded string