Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder.onUnmappableCharacter()


   */
  public ByteBuffer encode(String name) {
    CharsetEncoder enc = this.charset.newEncoder();

    enc.onMalformedInput(CodingErrorAction.REPORT);
    enc.onUnmappableCharacter(CodingErrorAction.REPORT);

    CharBuffer cb = CharBuffer.wrap(name);
    ByteBuffer out = ByteBuffer.allocate(name.length() + (name.length() + 1) / 2);

    while (cb.remaining() > 0) {
View Full Code Here


        if (CHARSET == null)
            return new FileWriter(f);

        FileOutputStream fileStream = new FileOutputStream(f);
        CharsetEncoder ce = CHARSET.newEncoder();
        ce.onUnmappableCharacter(CodingErrorAction.REPORT);
        return new OutputStreamWriter(fileStream, ce);
    }

    static class IncrFileWriter extends StringWriter
    {
View Full Code Here

        @Override
    public byte[] generateBytes(String password) {
            final CharsetEncoder encoder = createCharsetEncoder();
            if (this.replacementByte != null) {
                encoder.replaceWith(new byte[]{this.replacementByte});
                encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
            } else {
                encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
            }
            try {
                final ByteBuffer b = encoder.encode(CharBuffer.wrap(password));
View Full Code Here

            final CharsetEncoder encoder = createCharsetEncoder();
            if (this.replacementByte != null) {
                encoder.replaceWith(new byte[]{this.replacementByte});
                encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
            } else {
                encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
            }
            try {
                final ByteBuffer b = encoder.encode(CharBuffer.wrap(password));
                final byte[] bytes = new byte[b.remaining()];
                b.get(bytes);
View Full Code Here

    }

    private CharsetEncoder getCharsetEncoder(Charset charset) {
        CharsetEncoder encoder = charset.newEncoder();
       
        encoder.onUnmappableCharacter(actions.onUnmappableCharacter);
        encoder.onMalformedInput(actions.onMalformedInput);
        if (actions.replaceWith != null) {
            encoder.replaceWith(actions.replaceWith.getBytes());
        }
View Full Code Here

        Map<Charset, CharsetEncoder> map = encoders.get();
        CharsetEncoder e = map.get(charset);
        if (e != null) {
            e.reset();
            e.onMalformedInput(CodingErrorAction.REPLACE);
            e.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return e;
        }

        e = charset.newEncoder();
        e.onMalformedInput(CodingErrorAction.REPLACE);
View Full Code Here

            return e;
        }

        e = charset.newEncoder();
        e.onMalformedInput(CodingErrorAction.REPLACE);
        e.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, e);
        return e;
    }

    /**
 
View Full Code Here

     * @return a new {@link CharsetEncoder} instance for this server.
     */
    public CharsetEncoder newEncoder() {
        CharsetEncoder encoder = this.encoding.newEncoder();
        encoder.onMalformedInput(this.errorAction);
        encoder.onUnmappableCharacter(this.errorAction);
        return encoder;
    }

    /**
     * Start the server in the specified directory. The directory is
View Full Code Here

  public static ByteBuffer encode(String string, boolean replace)
    throws CharacterCodingException {
    CharsetEncoder encoder = ENCODER_FACTORY.get();
    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    }
    ByteBuffer bytes =
      encoder.encode(CharBuffer.wrap(string.toCharArray()));
    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPORT);
View Full Code Here

    }
    ByteBuffer bytes =
      encoder.encode(CharBuffer.wrap(string.toCharArray()));
    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPORT);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    }
    return bytes;
  }

  /** Read a UTF8 encoded string from in
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.