Package java.nio.charset

Examples of java.nio.charset.CharsetDecoder.onUnmappableCharacter()


    }
    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;
  }

  /**
 
View Full Code Here


        Map<Charset, CharsetDecoder> map = decoders.get();
        CharsetDecoder d = map.get(charset);
        if (d != null) {
            d.reset();
            d.onMalformedInput(CodingErrorAction.REPLACE);
            d.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return d;
        }

        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
View Full Code Here

            return d;
        }

        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
        d.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, d);
        return d;
    }
}
View Full Code Here

  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);
View Full Code Here

    }
    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;
  }

  /**
 
View Full Code Here

  private static String decode(final ByteBuffer b, final Charset charset)
      throws CharacterCodingException {
    final CharsetDecoder d = charset.newDecoder();
    d.onMalformedInput(CodingErrorAction.REPORT);
    d.onUnmappableCharacter(CodingErrorAction.REPORT);
    return d.decode(b).toString();
  }

  /**
   * Locate the position of the commit message body.
View Full Code Here

        Map<Charset, CharsetDecoder> map = decoders.get();
        CharsetDecoder d = map.get(charset);
        if (d != null) {
            d.reset();
            d.onMalformedInput(CodingErrorAction.REPLACE);
            d.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return d;
        }

        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
View Full Code Here

            return d;
        }

        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
        d.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, d);
        return d;
    }

    private CharsetUtil() {
View Full Code Here

    public void testLoadFromFileWithWrongEncoding() {
        try {
            Yaml yaml = new Yaml();
            InputStream input = new FileInputStream("src/test/resources/issues/issue68.txt");
            CharsetDecoder decoder = Charset.forName("Cp1252").newDecoder();
            decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
            Object text = yaml.load(new InputStreamReader(input, decoder));
            input.close();
            fail("Invalid UTF-8 must not be accepted: " + text.toString());
        } catch (Exception e) {
            assertTrue(e.getMessage().endsWith("Exception: Input length = 1"));
View Full Code Here

            decBuf = null;
            return;
        }
        CharsetDecoder d = primaryCharset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPORT);
        d.onUnmappableCharacter(CodingErrorAction.REPORT);
        int origPos = buf.position();
        try {
            decBuf = d.decode(buf);
            lastCharset = primaryCharset;
        } catch(IOException e) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.