Exemple #1
0
 /*
  * original output is full and doesn't have remaining. allocate more space
  * to new CharBuffer and return it, the contents in the given buffer will be
  * copied into the new buffer.
  */
 private java.nio.CharBuffer allocateMore(java.nio.CharBuffer output)
 {
     if (output.capacity() == 0)
     {
         return(java.nio.CharBuffer.allocate(1));
     }
     java.nio.CharBuffer result = java.nio.CharBuffer.allocate(output.capacity() * 2);
     output.flip();
     result.put(output);
     return(result);
 }
Exemple #2
0
        /*
         * This is a facade method for the decoding operation.
         * <p>
         * This method decodes the remaining byte sequence of the given byte buffer
         * into a new character buffer. This method performs a complete decoding
         * operation, resets at first, then decodes, and flushes at last.
         * <p>
         * This method should not be invoked while another {@code decode} operation
         * is ongoing.
         *
         * @param in
         *            the input buffer.
         * @return a new <code>CharBuffer</code> containing the the characters
         *         produced by this decoding operation. The buffer's limit will be
         *         the position of the last character in the buffer, and the
         *         position will be zero.
         * @throws IllegalStateException
         *             if another decoding operation is ongoing.
         * @throws MalformedInputException
         *             if an illegal input byte sequence for this charset was
         *             encountered, and the action for malformed error is
         *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}
         * @throws UnmappableCharacterException
         *             if a legal but unmappable input byte sequence for this
         *             charset was encountered, and the action for unmappable
         *             character error is
         *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}.
         *             Unmappable means the byte sequence at the input buffer's
         *             current position cannot be mapped to a Unicode character
         *             sequence.
         * @throws CharacterCodingException
         *             if another exception happened during the decode operation.
         */
        public java.nio.CharBuffer decode(java.nio.ByteBuffer inJ) //throws CharacterCodingException
        {
            reset();
            int length = (int)(inJ.remaining() * averChars);

            java.nio.CharBuffer output = java.nio.CharBuffer.allocate(length);
            CoderResult         result = null;

            while (true)
            {
                result = decode(inJ, output, false);
                checkCoderResult(result);
                if (result.isUnderflow())
                {
                    break;
                }
                else if (result.isOverflow())
                {
                    output = allocateMore(output);
                }
            }
            result = decode(inJ, output, true);
            checkCoderResult(result);

            while (true)
            {
                result = flush(output);
                checkCoderResult(result);
                if (result.isOverflow())
                {
                    output = allocateMore(output);
                }
                else
                {
                    break;
                }
            }

            output.flip();
            status = FLUSH;
            return(output);
        }