Class CharacterStreamDescriptor.Builder

  • Enclosing class:
    CharacterStreamDescriptor

    public static class CharacterStreamDescriptor.Builder
    extends java.lang.Object
    The builder for the CharacterStreamDescriptor class. The builder is used to avoid having a large set of constructors. See the build() method for pre-build field validation. Note that the validation is only performed in sane builds.
    • Field Detail

      • DEFAULT_MAX_CHAR_LENGTH

        private static final long DEFAULT_MAX_CHAR_LENGTH
        Default max character length is unlimited.
        See Also:
        Constant Field Values
      • bufferable

        private boolean bufferable
      • positionAware

        private boolean positionAware
      • curBytePos

        private long curBytePos
      • curCharPos

        private long curCharPos
      • byteLength

        private long byteLength
      • charLength

        private long charLength
      • dataOffset

        private long dataOffset
      • maxCharLength

        private long maxCharLength
      • stream

        private java.io.InputStream stream
    • Constructor Detail

      • Builder

        public Builder()
        Creates a builder object.
    • Method Detail

      • bufferable

        public CharacterStreamDescriptor.Builder bufferable​(boolean bufferable)
        Sets if the stream should be buffered, defaults to false.
        Parameters:
        bufferable - true if buffering is advised, false if not
        Returns:
        The builder.
      • positionAware

        public CharacterStreamDescriptor.Builder positionAware​(boolean positionAware)
        Sets if the stream can reposition itself or not, defaults to false.
        Parameters:
        positionAware - true if the stream can reposition itself, false if not
        Returns:
        The builder.
      • curBytePos

        public CharacterStreamDescriptor.Builder curBytePos​(long pos)
        Sets the current byte position, defaults to 0.
        Parameters:
        pos - the current byte position
        Returns:
        The builder.
      • curCharPos

        public CharacterStreamDescriptor.Builder curCharPos​(long pos)
        Sets the current character position, defaults to 1.

        There is a special value for when the stream is position in the header area - BEFORE_FIRST.

        Parameters:
        pos - the current character position,starting at 1
        Returns:
        The builder.
        See Also:
        CharacterStreamDescriptor.BEFORE_FIRST
      • byteLength

        public CharacterStreamDescriptor.Builder byteLength​(long length)
        Sets the byte length of the stream, defaults to 0.

        A length of 0 means the length is unknown.

        Parameters:
        length - the byte length of the stream (including header)
        Returns:
        The builder.
      • charLength

        public CharacterStreamDescriptor.Builder charLength​(long length)
        Sets the character length of the stream, defaults to 0.

        Headers are not included in this length, only the user data. A length of 0 means the length is unknown.

        Parameters:
        length - the character length of the stream
        Returns:
        The builder.
      • dataOffset

        public CharacterStreamDescriptor.Builder dataOffset​(long offset)
        Sets the offset of the user data, defaults to 0.
        Parameters:
        offset - first index with user data, zero based
        Returns:
        The builder.
      • maxCharLength

        public CharacterStreamDescriptor.Builder maxCharLength​(long length)
        Imposes a length limit on the stream, expressed in number of characters, defaults to Long.MAX_VALUE.
        Parameters:
        length - maximum number of characters
        Returns:
        The builder.
      • stream

        public CharacterStreamDescriptor.Builder stream​(java.io.InputStream stream)
        Sets the stream described by the descriptor.

        The stream is not allowed to be null.

        Parameters:
        stream - the stream
        Returns:
        The builder.
      • build

        public CharacterStreamDescriptor build()
        Creates a descriptor object based on the parameters kept in the builder instance.

        Default values will be used for parameters for which a value hasn't been set.

        NOTE: Parameter validation is only performed in sane builds.

        Returns:
        A character stream descriptor instance.
      • toString

        public java.lang.String toString()
        Returns a textual representation of the builder.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The textual representation of the builder.