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() |