java.nio.charset.Charset.newDecoder()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中java.nio.charset.Charset.newDecoder()方法的一些代码示例,展示了Charset.newDecoder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Charset.newDecoder()方法的具体详情如下:
包路径:java.nio.charset.Charset
类名称:Charset
方法名:newDecoder

Charset.newDecoder介绍

[英]Returns a new instance of a decoder for this charset.
[中]返回此字符集的解码器的新实例。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public WriterOutputStream(Writer out) {
  this.writer = out;
  decoder = DEFAULT_CHARSET.newDecoder();
  decoder.onMalformedInput(CodingErrorAction.REPLACE);
  decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
}

代码示例来源:origin: apache/hbase

HttpDoAsClient() {
 decoder = Charset.forName("UTF-8").newDecoder();
}

代码示例来源:origin: spring-projects/spring-security

/**
   * Decode the bytes in UTF-8 form into a String.
   */
  public static String decode(byte[] bytes) {
    try {
      return CHARSET.newDecoder().decode(ByteBuffer.wrap(bytes)).toString();
    }
    catch (CharacterCodingException e) {
      throw new IllegalArgumentException("Decoding failed", e);
    }
  }
}

代码示例来源:origin: stackoverflow.com

CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
CharsetEncoder encoder = Charset.forName(encoding).newEncoder();
ByteBuffer tmp;
try {
  decoder.decode(tmp);
  return true;

代码示例来源:origin: apache/pdfbox

/**
 * Returns true if a byte sequence is valid UTF-8.
 */
private boolean isValidUTF8(byte[] input)
{
  CharsetDecoder cs = Charsets.UTF_8.newDecoder();
  try
  {
    cs.decode(ByteBuffer.wrap(input));
    return true;
  }
  catch (CharacterCodingException e)
  {
    LOG.debug("Character could not be decoded using Charsets.UTF_8 - returning false", e);
    return false;
  }
}

代码示例来源:origin: stackoverflow.com

CharsetDecoder UTF8Decoder =
  Charset.forName("UTF8").newDecoder().onMalformedInput(CodingErrorAction.REPORT);

代码示例来源:origin: commons-io/commons-io

final byte[] bytes = TEST_STRING_2.getBytes(charset);
final CharsetDecoder charsetDecoder2 = charset.newDecoder();
final ByteBuffer bb2 = ByteBuffer.allocate(16);
final CharBuffer cb2 = CharBuffer.allocate(TEST_STRING_2.length());
  bb2.flip();
  try {
    charsetDecoder2.decode(bb2, cb2, i == (len - 1));
  } catch ( final IllegalArgumentException e){
    throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. " +
if (!TEST_STRING_2.equals(cb2.toString())){
  throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. " +
      "Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream");

代码示例来源:origin: apache/ignite

CharsetDecoder decoder = charset.newDecoder();
  decoder.decode(buf);

代码示例来源:origin: stackoverflow.com

InputStream in = ...;
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
decoder.onMalformedInput(CodingErrorAction.IGNORE);
Reader reader = new InputStreamReader(in, decoder);

代码示例来源:origin: redisson/redisson

CharsetDecoder decoder = encoding.newDecoder().onUnmappableCharacter(
    CodingErrorAction.REPORT);
internalIn2 = new InputStreamReader(internalIn, decoder);

代码示例来源:origin: apache/hive

public RCFileCat() {
 super();
 decoder = Charset.forName("UTF-8").newDecoder().
  onMalformedInput(CodingErrorAction.REPLACE).
  onUnmappableCharacter(CodingErrorAction.REPLACE);
}

代码示例来源:origin: apache/hbase

DemoClient() {
  decoder = Charset.forName("UTF-8").newDecoder();
}

代码示例来源:origin: i2p/i2p.i2p

_bb = ByteBuffer.allocate(6);
  _cb = CharBuffer.allocate(1);
  _dc = Charset.forName("UTF-8").newDecoder();
} else {
  _bb.clear();
CoderResult result = _dc.decode(_bb, _cb, true);

代码示例来源:origin: apache/ignite

/**
 * Creates charset decoder block.
 *
 * @param charset The charset encoding to decode bytes from.
 */
public CharsetDecoderBlock(Charset charset) {
  charsetDecoder = charset.newDecoder()
    .onMalformedInput(CodingErrorAction.REPLACE)
    .onUnmappableCharacter(CodingErrorAction.REPLACE);
  isEndOfInput = false;
  leftover = null;
}

代码示例来源:origin: redisson/redisson

private String decode() {
  if (null == decoder) {
    decoder = UTF8.newDecoder();
  }
  snapshot();
  try {
    if (null == chars || chars.remaining() < buffer.remaining()) {
      chars = CharBuffer.allocate(buffer.remaining());
    } else {
      chars.rewind();
    }
    decoder.reset();
    CoderResult cr = decoder.decode(buffer, chars, true);
    if (cr.isUnderflow()) {
      decoder.flush(chars);
    }
    chars.flip();
    return chars.toString();
  } finally {
    reset();
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

CharsetDecoder decoder = charset.newDecoder();
  CoderResult result = decoder.reset().decode(byteBuf, charBuf, true);
  try {
    if (!result.isUnderflow()) {

代码示例来源:origin: k9mail/k-9

public String decode(String encodedFolderName) throws CharacterCodingException {
    CharsetDecoder decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
    ByteBuffer byteBuffer = ByteBuffer.wrap(encodedFolderName.getBytes(asciiCharset));
    CharBuffer charBuffer = decoder.decode(byteBuffer);

    return charBuffer.toString();
  }
}

代码示例来源:origin: apache/flink

@Override
public void configure(Configuration parameters) {
  super.configure(parameters);
  if (charsetName == null || !Charset.isSupported(charsetName)) {
    throw new RuntimeException("Unsupported charset: " + charsetName);
  }
  if (charsetName.equalsIgnoreCase(StandardCharsets.US_ASCII.name())) {
    ascii = true;
  }
  this.decoder = Charset.forName(charsetName).newDecoder();
  this.byteWrapper = ByteBuffer.allocate(1);
}

代码示例来源:origin: netty/netty

/**
 * Returns a new {@link CharsetDecoder} for the {@link Charset} with specified error actions.
 *
 * @param charset The specified charset
 * @param malformedInputAction The decoder's action for malformed-input errors
 * @param unmappableCharacterAction The decoder's action for unmappable-character errors
 * @return The decoder for the specified {@code charset}
 */
public static CharsetDecoder decoder(Charset charset, CodingErrorAction malformedInputAction,
                   CodingErrorAction unmappableCharacterAction) {
  checkNotNull(charset, "charset");
  CharsetDecoder d = charset.newDecoder();
  d.onMalformedInput(malformedInputAction).onUnmappableCharacter(unmappableCharacterAction);
  return d;
}

代码示例来源:origin: fabric8io/docker-maven-plugin

String message = Charsets.UTF_8.newDecoder().decode(payload).toString();
callLogCallback(type, message);
return true;

相关文章