当前位置: 首页>>代码示例>>Java>>正文


Java CharsetDecoder.onMalformedInput方法代码示例

本文整理汇总了Java中java.nio.charset.CharsetDecoder.onMalformedInput方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetDecoder.onMalformedInput方法的具体用法?Java CharsetDecoder.onMalformedInput怎么用?Java CharsetDecoder.onMalformedInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.charset.CharsetDecoder的用法示例。


在下文中一共展示了CharsetDecoder.onMalformedInput方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
private static String decode(ByteBuffer utf8, boolean replace) 
  throws CharacterCodingException {
  CharsetDecoder decoder = DECODER_FACTORY.get();
  if (replace) {
    decoder.onMalformedInput(
        java.nio.charset.CodingErrorAction.REPLACE);
    decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
  }
  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;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:Text.java

示例2: convertToUnicodeWithSubstitutions

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
 * Convert text in a given character set to a Unicode string.  Any invalid
 * characters are replaced with U+FFFD.  Returns null if the character set
 * is not recognized.
 * @param text ByteBuffer containing the character array to convert.
 * @param charsetName Character set it's in encoded in.
 * @return: Unicode string on success, null on failure.
 */
@CalledByNative
private static String convertToUnicodeWithSubstitutions(
        ByteBuffer text,
        String charsetName) {
    try {
        Charset charset = Charset.forName(charsetName);

        // TODO(mmenke):  Investigate if Charset.decode() can be used
        // instead.  The question is whether it uses the proper replace
        // character.  JDK CharsetDecoder docs say U+FFFD is the default,
        // but Charset.decode() docs say it uses the "charset's default
        // replacement byte array".
        CharsetDecoder decoder = charset.newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPLACE);
        decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
        decoder.replaceWith("\uFFFD");
        return decoder.decode(text).toString();
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:30,代码来源:NetStringUtil.java

示例3: decode

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
private static String decode(ByteBuffer utf8, boolean replace) 
  throws CharacterCodingException {
  CharsetDecoder decoder = DECODER_FACTORY.get();
  if (replace) {
    decoder.onMalformedInput(
        CodingErrorAction.REPLACE);
    decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
  }
  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;
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:17,代码来源:Text.java

示例4: prepareDecoder

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public CharsetDecoder prepareDecoder(Charset charset) {
    CharsetDecoder decoder = charset.newDecoder();
    if (strict) {
        decoder.onMalformedInput(CodingErrorAction.REPORT);
        decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    } else {
        decoder.onMalformedInput(CodingErrorAction.IGNORE);
        decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    }
    return decoder;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AbstractMatcher.java

示例5: fromUtf8

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static String fromUtf8(byte[] bytes, int off, int len) {
	CharsetDecoder decoder = UTF_8.newDecoder();
	decoder.onMalformedInput(IGNORE);
	decoder.onUnmappableCharacter(IGNORE);
	ByteBuffer buffer = ByteBuffer.wrap(bytes, off, len);
	try {
		return decoder.decode(buffer).toString();
	} catch (CharacterCodingException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:12,代码来源:StringUtils.java

示例6: stringUtf8

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static String stringUtf8( ByteBuffer bytes ) throws InvalidDataException {
	CharsetDecoder decode = Charset.forName( "UTF8" ).newDecoder();
	decode.onMalformedInput( codingErrorAction );
	decode.onUnmappableCharacter( codingErrorAction );
	// decode.replaceWith( "X" );
	String s;
	try {
		bytes.mark();
		s = decode.decode( bytes ).toString();
		bytes.reset();
	} catch ( CharacterCodingException e ) {
		throw new InvalidDataException( CloseFrame.NO_UTF8, e );
	}
	return s;
}
 
开发者ID:LDLN,项目名称:Responder-Android,代码行数:16,代码来源:Charsetfunctions.java

示例7: create

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public ManagedHttpClientConnection create(final HttpRoute route, final ConnectionConfig config) {
    final ConnectionConfig cconfig = config != null ? config : ConnectionConfig.DEFAULT;
    CharsetDecoder chardecoder = null;
    CharsetEncoder charencoder = null;
    final Charset charset = cconfig.getCharset();
    final CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
            cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
    final CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
            cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
    if (charset != null) {
        chardecoder = charset.newDecoder();
        chardecoder.onMalformedInput(malformedInputAction);
        chardecoder.onUnmappableCharacter(unmappableInputAction);
        charencoder = charset.newEncoder();
        charencoder.onMalformedInput(malformedInputAction);
        charencoder.onUnmappableCharacter(unmappableInputAction);
    }
    final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
    return new LoggingManagedHttpClientConnection(
            id,
            log,
            headerlog,
            wirelog,
            cconfig.getBufferSize(),
            cconfig.getFragmentSizeHint(),
            chardecoder,
            charencoder,
            cconfig.getMessageConstraints(),
            null,
            null,
            requestWriterFactory,
            responseParserFactory);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:34,代码来源:ManagedHttpClientConnectionFactory.java

示例8: stringUtf8

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static String stringUtf8(ByteBuffer bytes) throws InvalidDataException {
    CharsetDecoder decode = Charset.forName("UTF8").newDecoder();
    decode.onMalformedInput(codingErrorAction);
    decode.onUnmappableCharacter(codingErrorAction);
    // decode.replaceWith( "X" );
    String s;
    try {
        bytes.mark();
        s = decode.decode(bytes).toString();
        bytes.reset();
    } catch (CharacterCodingException e) {
        throw new InvalidDataException(CloseFrame.NO_UTF8, e);
    }
    return s;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:16,代码来源:Charsetfunctions.java

示例9: stringUtf8

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static String stringUtf8(ByteBuffer bytes) throws InvalidDataException {
    CharsetDecoder decode = Charset.forName("UTF8").newDecoder();
    decode.onMalformedInput(codingErrorAction);
    decode.onUnmappableCharacter(codingErrorAction);
    try {
        bytes.mark();
        String s = decode.decode(bytes).toString();
        bytes.reset();
        return s;
    } catch (Throwable e) {
        throw new InvalidDataException((int) CloseFrame.NO_UTF8, e);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:Charsetfunctions.java

示例10: a

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static String a(ByteBuffer byteBuffer) {
    CharsetDecoder newDecoder = Charset.forName("UTF8").newDecoder();
    newDecoder.onMalformedInput(a);
    newDecoder.onUnmappableCharacter(a);
    try {
        byteBuffer.mark();
        String charBuffer = newDecoder.decode(byteBuffer).toString();
        byteBuffer.reset();
        return charBuffer;
    } catch (Throwable e) {
        throw new b((int) CloseFrame.NO_UTF8, e);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:c.java


注:本文中的java.nio.charset.CharsetDecoder.onMalformedInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。