Class Encode.Buffer

  • Enclosing class:
    Encode

    static class Encode.Buffer
    extends java.lang.Object
    A buffer used for encoding.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.nio.CharBuffer _input
      The input buffer.
      (package private) java.nio.CharBuffer _output
      The output buffer.
      (package private) static int INPUT_BUFFER_SIZE
      Input buffer size, used to extract a copy of the input from a string and then send to the encoder.
      (package private) static int OUTPUT_BUFFER_SIZE
      Output buffer size used to store the encoded output before wrapping in a string.
    • Constructor Summary

      Constructors 
      Constructor Description
      Buffer()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void encode​(Encoder encoder, java.io.Writer out, java.lang.String str, int j)
      The core Writer encoding routing of this class.
      (package private) java.lang.String encode​(Encoder encoder, java.lang.String str, int j)
      The core String encoding routine of this class.
      • Methods inherited from class java.lang.Object

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

      • INPUT_BUFFER_SIZE

        static final int INPUT_BUFFER_SIZE
        Input buffer size, used to extract a copy of the input from a string and then send to the encoder.
        See Also:
        Constant Field Values
      • OUTPUT_BUFFER_SIZE

        static final int OUTPUT_BUFFER_SIZE
        Output buffer size used to store the encoded output before wrapping in a string.
        See Also:
        Constant Field Values
      • _input

        final java.nio.CharBuffer _input
        The input buffer. A heap-allocated, array-backed buffer of INPUT_BUFFER_SIZE used for holding the characters to encode.
      • _output

        final java.nio.CharBuffer _output
        The output buffer. A heap-allocated, array-backed buffer of OUTPUT_BUFFER_SIZE used for holding the encoded output.
    • Constructor Detail

      • Buffer

        Buffer()
    • Method Detail

      • encode

        java.lang.String encode​(Encoder encoder,
                                java.lang.String str,
                                int j)
        The core String encoding routine of this class. It uses the input and output buffers to allow the encoders to work in reuse arrays. When the input and/or output exceeds the capacity of the reused arrays, temporary ones are allocated and then discarded after the encode is done.
        Parameters:
        encoder - the encoder to use
        str - the string to encode
        j - the offset in str to start encoding
        Returns:
        the encoded result
      • encode

        void encode​(Encoder encoder,
                    java.io.Writer out,
                    java.lang.String str,
                    int j)
             throws java.io.IOException
        The core Writer encoding routing of this class. It uses the input and output buffers to allow the encoders to reuse arrays. Unlike the string version, this method will never allocate more memory, instead encoding is done in batches and flushed to the writer in batches as large as possible.
        Parameters:
        encoder - the encoder to use
        out - where to write the encoded output
        str - the string to encode
        j - the position in the string at which the first character needs encoding.
        Throws:
        java.io.IOException - if thrown by the writer.