當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。