jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java
changeset 895 67f1dc69ad10
parent 2 90ce3da70b43
child 1247 b4c26443dee5
equal deleted inserted replaced
894:15e617238139 895:67f1dc69ad10
   301     protected void implReplaceWith($replType$ newReplacement) {
   301     protected void implReplaceWith($replType$ newReplacement) {
   302     }
   302     }
   303 
   303 
   304 #if[encoder]
   304 #if[encoder]
   305 
   305 
   306     private WeakReference cachedDecoder = null;
   306     private WeakReference<CharsetDecoder> cachedDecoder = null;
   307 
   307 
   308     /**
   308     /**
   309      * Tells whether or not the given byte array is a legal replacement value
   309      * Tells whether or not the given byte array is a legal replacement value
   310      * for this encoder.
   310      * for this encoder.
   311      *
   311      *
   320      *
   320      *
   321      * @return  <tt>true</tt> if, and only if, the given byte array
   321      * @return  <tt>true</tt> if, and only if, the given byte array
   322      *          is a legal replacement value for this encoder
   322      *          is a legal replacement value for this encoder
   323      */
   323      */
   324     public boolean isLegalReplacement(byte[] repl) {
   324     public boolean isLegalReplacement(byte[] repl) {
   325         WeakReference wr = cachedDecoder;
   325         WeakReference<CharsetDecoder> wr = cachedDecoder;
   326         CharsetDecoder dec = null;
   326         CharsetDecoder dec = null;
   327         if ((wr == null) || ((dec = (CharsetDecoder)wr.get()) == null)) {
   327         if ((wr == null) || ((dec = wr.get()) == null)) {
   328             dec = charset().newDecoder();
   328             dec = charset().newDecoder();
   329             dec.onMalformedInput(CodingErrorAction.REPORT);
   329             dec.onMalformedInput(CodingErrorAction.REPORT);
   330             dec.onUnmappableCharacter(CodingErrorAction.REPORT);
   330             dec.onUnmappableCharacter(CodingErrorAction.REPORT);
   331             cachedDecoder = new WeakReference(dec);
   331             cachedDecoder = new WeakReference<CharsetDecoder>(dec);
   332         } else {
   332         } else {
   333             dec.reset();
   333             dec.reset();
   334         }
   334         }
   335         ByteBuffer bb = ByteBuffer.wrap(repl);
   335         ByteBuffer bb = ByteBuffer.wrap(repl);
   336         CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
   336         CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()