17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #warn This file is preprocessed before being compiled
27
28 package java.nio.charset;
29
30 import java.nio.Buffer;
31 import java.nio.ByteBuffer;
32 import java.nio.CharBuffer;
33 import java.nio.BufferOverflowException;
34 import java.nio.BufferUnderflowException;
35 import java.lang.ref.WeakReference;
36 import java.nio.charset.CoderMalfunctionError; // javadoc
37
38
39 /**
40 * An engine that can transform a sequence of $itypesPhrase$ into a sequence of
41 * $otypesPhrase$.
42 *
43 * <a name="steps">
44 *
45 * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series
46 * of such buffers. The output $otype$ sequence is written to a $otype$ buffer
47 * or a series of such buffers. $A$ $coder$ should always be used by making
48 * the following sequence of method invocations, hereinafter referred to as $a$
49 * <i>$coding$ operation</i>:
50 *
51 * <ol>
52 *
53 * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it
54 * has not been used before; </p></li>
55 *
56 * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as
227 average$ItypesPerOtype$, max$ItypesPerOtype$,
228 $defaultRepl$);
229 }
230
231 /**
232 * Returns the charset that created this $coder$. </p>
233 *
234 * @return This $coder$'s charset
235 */
236 public final Charset charset() {
237 return charset;
238 }
239
240 /**
241 * Returns this $coder$'s replacement value. </p>
242 *
243 * @return This $coder$'s current replacement,
244 * which is never <tt>null</tt> and is never empty
245 */
246 public final $replType$ replacement() {
247 return replacement;
248 }
249
250 /**
251 * Changes this $coder$'s replacement value.
252 *
253 * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
254 * method, passing the new replacement, after checking that the new
255 * replacement is acceptable. </p>
256 *
257 * @param newReplacement
258 *
259 #if[decoder]
260 * The new replacement; must not be <tt>null</tt>
261 * and must have non-zero length
262 #end[decoder]
263 #if[encoder]
264 * The new replacement; must not be <tt>null</tt>, must have
265 * non-zero length, must not be longer than the value returned by
266 * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
267 * must be {@link #isLegalReplacement </code>legal<code>}
268 #end[encoder]
269 *
270 * @return This $coder$
271 *
272 * @throws IllegalArgumentException
273 * If the preconditions on the parameter do not hold
274 */
275 public final Charset$Coder$ replaceWith($replType$ newReplacement) {
276 if (newReplacement == null)
277 throw new IllegalArgumentException("Null replacement");
278 int len = newReplacement.$replLength$;
279 if (len == 0)
280 throw new IllegalArgumentException("Empty replacement");
281 if (len > max$ItypesPerOtype$)
282 throw new IllegalArgumentException("Replacement too long");
283 #if[encoder]
284 if (!isLegalReplacement(newReplacement))
285 throw new IllegalArgumentException("Illegal replacement");
286 #end[encoder]
287 this.replacement = newReplacement;
288 implReplaceWith(newReplacement);
289 return this;
290 }
291
292 /**
293 * Reports a change to this $coder$'s replacement value.
294 *
295 * <p> The default implementation of this method does nothing. This method
296 * should be overridden by $coder$s that require notification of changes to
297 * the replacement. </p>
298 *
299 * @param newReplacement
300 */
301 protected void implReplaceWith($replType$ newReplacement) {
302 }
303
304 #if[encoder]
305
306 private WeakReference<CharsetDecoder> cachedDecoder = null;
307
308 /**
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #warn This file is preprocessed before being compiled
27
28 package java.nio.charset;
29
30 import java.nio.Buffer;
31 import java.nio.ByteBuffer;
32 import java.nio.CharBuffer;
33 import java.nio.BufferOverflowException;
34 import java.nio.BufferUnderflowException;
35 import java.lang.ref.WeakReference;
36 import java.nio.charset.CoderMalfunctionError; // javadoc
37 import java.util.Arrays;
38
39
40 /**
41 * An engine that can transform a sequence of $itypesPhrase$ into a sequence of
42 * $otypesPhrase$.
43 *
44 * <a name="steps">
45 *
46 * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series
47 * of such buffers. The output $otype$ sequence is written to a $otype$ buffer
48 * or a series of such buffers. $A$ $coder$ should always be used by making
49 * the following sequence of method invocations, hereinafter referred to as $a$
50 * <i>$coding$ operation</i>:
51 *
52 * <ol>
53 *
54 * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it
55 * has not been used before; </p></li>
56 *
57 * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as
228 average$ItypesPerOtype$, max$ItypesPerOtype$,
229 $defaultRepl$);
230 }
231
232 /**
233 * Returns the charset that created this $coder$. </p>
234 *
235 * @return This $coder$'s charset
236 */
237 public final Charset charset() {
238 return charset;
239 }
240
241 /**
242 * Returns this $coder$'s replacement value. </p>
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");
284 int len = newReplacement.$replLength$;
285 if (len == 0)
286 throw new IllegalArgumentException("Empty replacement");
287 if (len > max$ItypesPerOtype$)
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 /**
|