Beispiel #1
0
        /*
         * Checks if the given argument is legal as this encoder's replacement byte
         * array.
         *
         * The given byte array is legal if and only if it can be decode into
         * sixteen bits Unicode characters.
         *
         * This method can be overridden for performance improvement.
         *
         * @param repl
         *            the given byte array to be checked.
         * @return true if the the given argument is legal as this encoder's
         *         replacement byte array.
         */
        public bool isLegalReplacement(byte[] repl)
        {
            if (decoder == null)
            {
                decoder = cs.newDecoder();
            }

            CodingErrorAction malform = decoder.malformedInputAction();
            CodingErrorAction unmap   = decoder.unmappableCharacterAction();

            decoder.onMalformedInput(CodingErrorAction.REPORT);
            decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
            java.nio.ByteBuffer inJ  = java.nio.ByteBuffer.wrap(repl);
            java.nio.CharBuffer outJ = java.nio.CharBuffer.allocate((int)(repl.Length * decoder
                                                                          .maxCharsPerByte()));
            CoderResult result = decoder.decode(inJ, outJ, true);

            decoder.onMalformedInput(malform);
            decoder.onUnmappableCharacter(unmap);
            return(!result.isError());
        }
        /**
         * Checks if the given argument is legal as this encoder's replacement byte
         * array.
         *
         * The given byte array is legal if and only if it can be decode into
         * sixteen bits Unicode characters.
         *
         * This method can be overridden for performance improvement.
         *
         * @param repl
         *            the given byte array to be checked.
         * @return true if the the given argument is legal as this encoder's
         *         replacement byte array.
         */
        public bool isLegalReplacement(byte[] repl)
        {
            if (decoder == null) {
                decoder = cs.newDecoder();
            }

            CodingErrorAction malform = decoder.malformedInputAction();
            CodingErrorAction unmap = decoder.unmappableCharacterAction();
            decoder.onMalformedInput(CodingErrorAction.REPORT);
            decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
            java.nio.ByteBuffer inJ = java.nio.ByteBuffer.wrap(repl);
            java.nio.CharBuffer outJ = java.nio.CharBuffer.allocate((int) (repl.Length * decoder
                    .maxCharsPerByte()));
            CoderResult result = decoder.decode(inJ, outJ, true);
            decoder.onMalformedInput(malform);
            decoder.onUnmappableCharacter(unmap);
            return !result.isError();
        }