Example usage for java.nio.charset CodingErrorAction REPORT

List of usage examples for java.nio.charset CodingErrorAction REPORT

Introduction

In this page you can find the example usage for java.nio.charset CodingErrorAction REPORT.

Prototype

CodingErrorAction REPORT

To view the source code for java.nio.charset CodingErrorAction REPORT.

Click Source Link

Document

Action indicating that a coding error is to be reported, either by returning a CoderResult object or by throwing a CharacterCodingException , whichever is appropriate for the method implementing the coding process.

Usage

From source file:org.apache.http.HC4.impl.nio.conn.ManagedNHttpClientConnectionFactory.java

@Override
public ManagedNHttpClientConnection create(final IOSession iosession, final ConnectionConfig config) {
    final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
    CharsetDecoder chardecoder = null;
    CharsetEncoder charencoder = null;
    final Charset charset = config.getCharset();
    final CodingErrorAction malformedInputAction = config.getMalformedInputAction() != null
            ? config.getMalformedInputAction()
            : CodingErrorAction.REPORT;
    final CodingErrorAction unmappableInputAction = config.getUnmappableInputAction() != null
            ? config.getUnmappableInputAction()
            : CodingErrorAction.REPORT;
    if (charset != null) {
        chardecoder = charset.newDecoder();
        chardecoder.onMalformedInput(malformedInputAction);
        chardecoder.onUnmappableCharacter(unmappableInputAction);
        charencoder = charset.newEncoder();
        charencoder.onMalformedInput(malformedInputAction);
        charencoder.onUnmappableCharacter(unmappableInputAction);
    }/*w  w w  .  ja v  a 2  s.  c o  m*/
    final ManagedNHttpClientConnection conn = new ManagedNHttpClientConnectionImpl(id, this.log, this.headerlog,
            this.wirelog, iosession, config.getBufferSize(), config.getFragmentSizeHint(), this.allocator,
            chardecoder, charencoder, config.getMessageConstraints(), null, null, this.requestWriterFactory,
            this.responseParserFactory);
    iosession.setAttribute(IOEventDispatch.CONNECTION_KEY, conn);
    return conn;
}

From source file:org.apache.http.impl.nio.conn.DefaultClientAsyncConnectionFactory.java

@Override
public ManagedNHttpClientConnection create(final IOSession iosession, final ConnectionConfig config) {
    final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
    CharsetDecoder chardecoder = null;
    CharsetEncoder charencoder = null;
    final Charset charset = config.getCharset();
    final CodingErrorAction malformedInputAction = config.getMalformedInputAction() != null
            ? config.getMalformedInputAction()
            : CodingErrorAction.REPORT;
    final CodingErrorAction unmappableInputAction = config.getUnmappableInputAction() != null
            ? config.getUnmappableInputAction()
            : CodingErrorAction.REPORT;
    if (charset != null) {
        chardecoder = charset.newDecoder();
        chardecoder.onMalformedInput(malformedInputAction);
        chardecoder.onUnmappableCharacter(unmappableInputAction);
        charencoder = charset.newEncoder();
        charencoder.onMalformedInput(malformedInputAction);
        charencoder.onUnmappableCharacter(unmappableInputAction);
    }// www  .  j av  a2 s . com
    final ManagedNHttpClientConnection conn = new ManagedNHttpClientConnectionImpl(id, this.log, this.headerlog,
            this.wirelog, iosession, config.getBufferSize(), config.getFragmentSizeHint(), this.allocator,
            chardecoder, charencoder, config.getMessageConstraints(), null, null, null,
            this.responseParserFactory);
    iosession.setAttribute(IOEventDispatch.CONNECTION_KEY, conn);
    return conn;
}

From source file:org.apache.mahout.utils.nlp.collocations.llr.BloomTokenFilter.java

/** 
 * @param filter tokens will be checked for membership in this bloom filter
 * @param in the tokenstream to read.//w  w w . j a va  2s . c o m
 * @param keepMembers keep memoers of the bloom filter? If true works like
 *   a whitelist and members found in the list are kept and all others are
 *   dropped. If false works like a stoplist and members found in the 
 *   filter are dropped all others are kept.
 */
public BloomTokenFilter(Filter filter, boolean keepMembers, TokenStream in) {
    super(in);
    this.filter = filter;
    this.keepMembers = keepMembers;
    this.key = new Key();
    this.termAtt = addAttribute(CharTermAttribute.class);
    this.encoder = Charsets.UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);
}

From source file:org.apache.synapse.transport.utils.config.HttpTransportConfiguration.java

private CodingErrorAction getCodingErrorAction(String action) {
    if ("report".equals(action)) {
        return CodingErrorAction.REPORT;
    } else if ("ignore".equals(action)) {
        return CodingErrorAction.IGNORE;
    } else if ("replace".equals(action)) {
        return CodingErrorAction.REPLACE;
    } else {//from  www.  jav  a  2s .  c  o m
        return CodingErrorAction.REPORT;
    }
}

From source file:org.cloudata.core.common.io.CText.java

private static String decode(ByteBuffer utf8, boolean replace) throws CharacterCodingException {
    synchronized (DECODER) {
        if (replace) {
            DECODER.onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE);
            DECODER.onUnmappableCharacter(CodingErrorAction.REPLACE);
        }//from   w  w  w .j a va2s . c  o m
        String str = DECODER.decode(utf8).toString();
        // set decoder back to its default value: REPORT
        if (replace) {
            DECODER.onMalformedInput(CodingErrorAction.REPORT);
            DECODER.onUnmappableCharacter(CodingErrorAction.REPORT);
        }
        return str;
    }

}

From source file:org.cloudata.core.common.io.CText.java

/**
 * Converts the provided String to bytes using the
 * UTF-8 encoding. If <code>replace</code> is true, then
 * malformed input is replaced with the// w  ww.j  a va 2  s . c  om
 * substitution character, which is U+FFFD. Otherwise the
 * method throws a MalformedInputException.
 * @return ByteBuffer: bytes stores at ByteBuffer.array() 
 *                     and length is ByteBuffer.limit()
 */
public static ByteBuffer encode(String string, boolean replace) throws CharacterCodingException {
    synchronized (ENCODER) {
        if (replace) {
            ENCODER.onMalformedInput(CodingErrorAction.REPLACE);
            ENCODER.onUnmappableCharacter(CodingErrorAction.REPLACE);
        }
        ByteBuffer bytes = ENCODER.encode(CharBuffer.wrap(string.toCharArray()));
        if (replace) {
            ENCODER.onMalformedInput(CodingErrorAction.REPORT);
            ENCODER.onUnmappableCharacter(CodingErrorAction.REPORT);
        }
        return bytes;
    }
}

From source file:org.colombbus.tangara.io.ScriptReader.java

private static CharsetDecoder createDecoder(Charset cs) {
     CharsetDecoder decoder = cs.newDecoder();
     decoder.onMalformedInput(CodingErrorAction.REPORT);
     decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
     return decoder;
 }

From source file:org.diorite.config.impl.ConfigTemplateImpl.java

public ConfigTemplateImpl(Class<T> type, ConfigImplementationProvider provider) {
    this.type = type;
    this.comments = Serialization.getGlobal().getCommentsManager().getComments(type);
    this.implementationProvider = provider;
    this.name = type.getSimpleName();
    this.charsetEncoder = StandardCharsets.UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);
    this.charsetDecoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);
    this.setupActions();
}

From source file:org.exist.versioning.svn.core.internal.io.fs.FSFile.java

public FSFile(File file) {
    myFile = file;/*www.j av a2  s. com*/
    myPosition = 0;
    myBufferPosition = 0;
    myBuffer = ByteBuffer.allocate(1024);
    myReadLineBuffer = ByteBuffer.allocate(1024);
    myDecoder = Charset.forName("UTF-8").newDecoder();
    myDecoder = myDecoder.onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);
}

From source file:org.marketcetera.util.test.UnicodeDataTest.java

private static void singleInvalid(Charset cs, byte[] encoded) {
    CharsetDecoder dec = cs.newDecoder();
    dec.onMalformedInput(CodingErrorAction.REPORT);
    try {//from   w ww. j a  v  a 2 s . c  o  m
        dec.decode(ByteBuffer.wrap(encoded));
        fail();
    } catch (CharacterCodingException ex) {
        // Desired.
    }
}