/** * Gets the named property as a Charset value. * * @param name the name of the property to look up * @return the Charset value of the property or {@link Charset#defaultCharset()} if undefined. */ public Charset getCharsetProperty(final String name) { return getCharsetProperty(name, Charset.defaultCharset()); }
@Test public void testGetCharsetProperty() throws Exception { final Properties p = new Properties(); p.setProperty("e.1", StandardCharsets.US_ASCII.name()); p.setProperty("e.2", "wrong-charset-name"); final PropertiesUtil pu = new PropertiesUtil(p); assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.0")); assertEquals(StandardCharsets.US_ASCII, pu.getCharsetProperty("e.1")); assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.2")); }
@Test public void testGetMappedProperty_sun_stdout_encoding() { final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding")); }
@Test public void testGetMappedProperty_sun_stderr_encoding() { final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; assertEquals(expected, pu.getCharsetProperty("sun.err.encoding")); }
/** * Gets the named property as a Charset value. * * @param name the name of the property to look up * @return the Charset value of the property or {@link Charset#defaultCharset()} if undefined. */ public Charset getCharsetProperty(final String name) { return getCharsetProperty(name, Charset.defaultCharset()); }
protected Charset getCharset(final String property, Charset defaultCharset) { return new PropertiesUtil(PropertiesUtil.getSystemProperties()).getCharsetProperty(property, defaultCharset); }