public WriterOutputStream(Writer out) { this.writer = out; decoder = DEFAULT_CHARSET.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); }
HttpDoAsClient() { decoder = Charset.forName("UTF-8").newDecoder(); }
/** * 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); } } }
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder(); CharsetEncoder encoder = Charset.forName(encoding).newEncoder(); ByteBuffer tmp; try { decoder.decode(tmp); return true;
/** * 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; } }
CharsetDecoder UTF8Decoder = Charset.forName("UTF8").newDecoder().onMalformedInput(CodingErrorAction.REPORT);
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");
CharsetDecoder decoder = charset.newDecoder(); decoder.decode(buf);
InputStream in = ...; CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.IGNORE); Reader reader = new InputStreamReader(in, decoder);
CharsetDecoder decoder = encoding.newDecoder().onUnmappableCharacter( CodingErrorAction.REPORT); internalIn2 = new InputStreamReader(internalIn, decoder);
public RCFileCat() { super(); decoder = Charset.forName("UTF-8").newDecoder(). onMalformedInput(CodingErrorAction.REPLACE). onUnmappableCharacter(CodingErrorAction.REPLACE); }
DemoClient() { decoder = Charset.forName("UTF-8").newDecoder(); }
_bb = ByteBuffer.allocate(6); _cb = CharBuffer.allocate(1); _dc = Charset.forName("UTF-8").newDecoder(); } else { _bb.clear(); CoderResult result = _dc.decode(_bb, _cb, true);
/** * 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; }
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(); } }
CharsetDecoder decoder = charset.newDecoder(); CoderResult result = decoder.reset().decode(byteBuf, charBuf, true); try { if (!result.isUnderflow()) {
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(); } }
@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); }
/** * 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; }
String message = Charsets.UTF_8.newDecoder().decode(payload).toString(); callLogCallback(type, message); return true;