package org.springframework.security.crypto.codec;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.util.*;

/**
 * UTF-8 Charset encoder/decoder.
 * <p>
 * For internal use only.
 *
 * @author Luke Taylor
 */
public final class Utf8 {
    private static final Charset CHARSET = Charset.forName("UTF-8");

    /**
     * Get the bytes of the String in UTF-8 encoded form.
     */
    public static byte[] encode(CharSequence string) {
        try {
            ByteBuffer bytes = CHARSET.newEncoder().encode(CharBuffer.wrap(string));

            return Arrays.copyOfRange(bytes.array(), 0, bytes.limit());
        } catch (CharacterCodingException e) {
            throw new IllegalArgumentException("Encoding failed", e);
        }
    }

    /**
     * Decode the bytes in UTF-8 form into a String.
     */
    public static String decode(byte[] bytes) {
        try {
            return CHARSET.newDecoder().decode(ByteBuffer.wrap(bytes)).toString();
        } catch (CharacterCodingException e) {
            throw new IllegalArgumentException("Decoding failed", e);
        }
    }
}

@@ -630,17 +630,16 @@
 ring));%0A
-%0A
         
@@ -646,33 +646,80 @@
     
-return A
+byte%5B%5D bytesCopy = new byte%5Bbytes.limit()%5D;%0A            System.a
 rray
-s.
 copy
-OfRange
 (byt
@@ -742,17 +742,62 @@
 ytes
-.limit())
+Copy, 0, bytes.limit());%0A%0A            return bytesCopy
 ;%0A  

Remove use of Java 6 method Arrays.copyOfRange.