Package java.nio.charset

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


  /**
   * @see org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String)
   */
  public boolean canEncode(String name) {
    CharsetEncoder enc = this.charset.newEncoder();
    enc.onMalformedInput(CodingErrorAction.REPORT);
    enc.onUnmappableCharacter(CodingErrorAction.REPORT);

    return enc.canEncode(name);
  }

View Full Code Here


   * @see org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
   */
  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);

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

        return encoder;
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();
View Full Code Here

            e.onUnmappableCharacter(CodingErrorAction.REPLACE);
            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;
    }

    /**
 
View Full Code Here

        CharsetEncoder enc = Chars.getEncoder();
        // Blocking finite Pool - does not happen.
        // Plain Pool (sync wrapped) - might - allocate an extra one.
        if ( enc == null )
            enc = Chars.createEncoder() ;
        enc
          .onMalformedInput(CodingErrorAction.REPLACE)
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
          .reset() ;
       
        return enc ;
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) {
View Full Code Here

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

    assertByteArray(out, addSurrogate(unibytes));
       
        // Regression test for harmony-3378
        Charset cs = Charset.forName("UTF-8");
        CharsetEncoder encoder = cs.newEncoder();
        encoder.onMalformedInput(CodingErrorAction.REPLACE);
        encoder = encoder.replaceWith(new byte[] { (byte) 0xef, (byte) 0xbf,
                (byte) 0xbd, });
        CharBuffer in = CharBuffer.wrap("\ud800");
        out = encoder.encode(in);
        assertNotNull(out);
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.