243 *
244 * @return This $coder$'s current replacement,
245 * which is never <tt>null</tt> and is never empty
246 */
247 public final $replType$ replacement() {
248 #if[decoder]
249 return replacement;
250 #end[decoder]
251 #if[encoder]
252 return Arrays.copyOf(replacement, replacement.$replLength$);
253 #end[encoder]
254 }
255
256 /**
257 * Changes this $coder$'s replacement value.
258 *
259 * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
260 * method, passing the new replacement, after checking that the new
261 * replacement is acceptable. </p>
262 *
263 * @param newReplacement
264 *
265 #if[decoder]
266 * The new replacement; must not be <tt>null</tt>
267 * and must have non-zero length
268 #end[decoder]
269 #if[encoder]
270 * The new replacement; must not be <tt>null</tt>, must have
271 * non-zero length, must not be longer than the value returned by
272 * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
273 * must be {@link #isLegalReplacement </code>legal<code>}
274 #end[encoder]
275 *
276 * @return This $coder$
277 *
278 * @throws IllegalArgumentException
279 * If the preconditions on the parameter do not hold
280 */
281 public final Charset$Coder$ replaceWith($replType$ newReplacement) {
282 if (newReplacement == null)
283 throw new IllegalArgumentException("Null replacement");
288 throw new IllegalArgumentException("Replacement too long");
289 #if[decoder]
290 this.replacement = newReplacement;
291 #end[decoder]
292 #if[encoder]
293 if (!isLegalReplacement(newReplacement))
294 throw new IllegalArgumentException("Illegal replacement");
295 this.replacement = Arrays.copyOf(newReplacement, newReplacement.$replLength$);
296 #end[encoder]
297 implReplaceWith(this.replacement);
298 return this;
299 }
300
301 /**
302 * Reports a change to this $coder$'s replacement value.
303 *
304 * <p> The default implementation of this method does nothing. This method
305 * should be overridden by $coder$s that require notification of changes to
306 * the replacement. </p>
307 *
308 * @param newReplacement
309 */
310 protected void implReplaceWith($replType$ newReplacement) {
311 }
312
313 #if[encoder]
314
315 private WeakReference<CharsetDecoder> cachedDecoder = null;
316
317 /**
318 * Tells whether or not the given byte array is a legal replacement value
319 * for this encoder.
320 *
321 * <p> A replacement is legal if, and only if, it is a legal sequence of
322 * bytes in this encoder's charset; that is, it must be possible to decode
323 * the replacement into one or more sixteen-bit Unicode characters.
324 *
325 * <p> The default implementation of this method is not very efficient; it
326 * should generally be overridden to improve performance. </p>
327 *
328 * @param repl The byte array to be tested
|
243 *
244 * @return This $coder$'s current replacement,
245 * which is never <tt>null</tt> and is never empty
246 */
247 public final $replType$ replacement() {
248 #if[decoder]
249 return replacement;
250 #end[decoder]
251 #if[encoder]
252 return Arrays.copyOf(replacement, replacement.$replLength$);
253 #end[encoder]
254 }
255
256 /**
257 * Changes this $coder$'s replacement value.
258 *
259 * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
260 * method, passing the new replacement, after checking that the new
261 * replacement is acceptable. </p>
262 *
263 * @param newReplacement The replacement value
264 *
265 #if[decoder]
266 * The new replacement; must not be <tt>null</tt>
267 * and must have non-zero length
268 #end[decoder]
269 #if[encoder]
270 * The new replacement; must not be <tt>null</tt>, must have
271 * non-zero length, must not be longer than the value returned by
272 * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
273 * must be {@link #isLegalReplacement </code>legal<code>}
274 #end[encoder]
275 *
276 * @return This $coder$
277 *
278 * @throws IllegalArgumentException
279 * If the preconditions on the parameter do not hold
280 */
281 public final Charset$Coder$ replaceWith($replType$ newReplacement) {
282 if (newReplacement == null)
283 throw new IllegalArgumentException("Null replacement");
288 throw new IllegalArgumentException("Replacement too long");
289 #if[decoder]
290 this.replacement = newReplacement;
291 #end[decoder]
292 #if[encoder]
293 if (!isLegalReplacement(newReplacement))
294 throw new IllegalArgumentException("Illegal replacement");
295 this.replacement = Arrays.copyOf(newReplacement, newReplacement.$replLength$);
296 #end[encoder]
297 implReplaceWith(this.replacement);
298 return this;
299 }
300
301 /**
302 * Reports a change to this $coder$'s replacement value.
303 *
304 * <p> The default implementation of this method does nothing. This method
305 * should be overridden by $coder$s that require notification of changes to
306 * the replacement. </p>
307 *
308 * @param newReplacement The replacement value
309 */
310 protected void implReplaceWith($replType$ newReplacement) {
311 }
312
313 #if[encoder]
314
315 private WeakReference<CharsetDecoder> cachedDecoder = null;
316
317 /**
318 * Tells whether or not the given byte array is a legal replacement value
319 * for this encoder.
320 *
321 * <p> A replacement is legal if, and only if, it is a legal sequence of
322 * bytes in this encoder's charset; that is, it must be possible to decode
323 * the replacement into one or more sixteen-bit Unicode characters.
324 *
325 * <p> The default implementation of this method is not very efficient; it
326 * should generally be overridden to improve performance. </p>
327 *
328 * @param repl The byte array to be tested
|