@Test public void testTypes() throws IOException { File props = new File(root, "/types.properties"); File hocon = Properties2HoconConverter.convert(props, true); PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props); Config config = load(hocon); assertThat(properties).isNotNull(); assertThat(properties.isEmpty()).isFalse(); assertThat(config.isEmpty()).isFalse(); assertThat(config.getString("conf.string")).isEqualTo("foo"); assertThat(config.getString("conf.int")).isEqualTo("1"); assertThat(config.getInt("conf.int")).isEqualTo(1); assertThat(config.getNumber("conf.int")).isEqualTo(1); assertThat(config.getString("conf.float")).isEqualTo("1.1"); assertThat(config.getNumber("conf.float")).isEqualTo(1.1); assertThat(config.getNumber("conf.float")).isEqualTo(1.1d); assertThat(config.getDouble("conf.float")).isEqualTo(1.1d); assertThat(config.getBoolean("conf.boolean.true")).isTrue(); assertThat(config.getBoolean("conf.boolean.false")).isFalse(); assertThat(config.getBoolean("conf.boolean.yes")).isTrue(); assertThat(config.getBoolean("conf.boolean.no")).isFalse(); assertThat(config.getBoolean("conf.boolean.on")).isTrue(); assertThat(config.getBoolean("conf.boolean.off")).isFalse(); assertThat(config.getDuration("conf.unit.time", TimeUnit.MILLISECONDS)).isEqualTo(10l); assertThat(config.getDuration("conf.unit.time", TimeUnit.MICROSECONDS)).isEqualTo(10000l); assertThat(config.getBytes("conf.unit.size")).isEqualTo(512*1024); assertThat(config.getBytes("conf.unit.size2")).isEqualTo(10); assertThat(config.getIntList("conf.list.int")).containsExactly(1, 2, 3); assertThat(config.getStringList("conf.list.string")).containsExactly("a", "b", "c"); assertThat(config.hasPath("conf.missing")).isFalse(); assertThat(config.getString("conf.quotes")).isEqualTo("http: }
public static File convert(File props, boolean backup) throws IOException { if (!props.isFile()) { throw new IllegalArgumentException("The given properties file does not exist : " + props.getAbsolutePath()); } Properties properties; try { properties = readFileAsProperties(props); } catch (IOException e) { throw new IllegalArgumentException("Cannot convert " + props.getName() + " to hocon - the file is not a " + "valid properties file", e); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Cannot convert an empty file : " + props.getAbsolutePath()); } if (backup) { try { generateBackup(props); } catch (IOException e) { throw new IllegalStateException("Cannot generate the backup for " + props.getName(), e); } } String hocon = convertToHocon(props); File output = props; if (!props.getName().endsWith(".conf")) { output = new File(props.getParentFile(), props.getName().substring(0, props.getName().lastIndexOf(".")) + ".conf"); } FileUtils.write(output, hocon); return output; }
Properties2HoconConverter { public static File convert(File props, boolean backup) throws IOException { if (!props.isFile()) { throw new IllegalArgumentException("The given properties file does not exist : " + props.getAbsolutePath()); } Properties properties; try { properties = readFileAsProperties(props); } catch (IOException e) { throw new IllegalArgumentException("Cannot convert " + props.getName() + " to hocon - the file is not a " + "valid properties file", e); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Cannot convert an empty file : " + props.getAbsolutePath()); } if (backup) { try { generateBackup(props); } catch (IOException e) { throw new IllegalStateException("Cannot generate the backup for " + props.getName(), e); } } String hocon = convertToHocon(props); File output = props; if (!props.getName().endsWith(".conf")) { output = new File(props.getParentFile(), props.getName().substring(0, props.getName().lastIndexOf(".")) + ".conf"); } FileUtils.write(output, hocon); return output; } }
Properties2HoconConverter { public static File convert(File props, boolean backup) throws IOException { if (!props.isFile()) { throw new IllegalArgumentException("The given properties file does not exist : " + props.getAbsolutePath()); } Properties properties; try { properties = readFileAsProperties(props); } catch (IOException e) { throw new IllegalArgumentException("Cannot convert " + props.getName() + " to hocon - the file is not a " + "valid properties file", e); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Cannot convert an empty file : " + props.getAbsolutePath()); } if (backup) { try { generateBackup(props); } catch (IOException e) { throw new IllegalStateException("Cannot generate the backup for " + props.getName(), e); } } String hocon = convertToHocon(props); File output = props; if (!props.getName().endsWith(".conf")) { output = new File(props.getParentFile(), props.getName().substring(0, props.getName().lastIndexOf(".")) + ".conf"); } FileUtils.write(output, hocon); return output; } private  Properties2HoconConverter(); }
Properties2HoconConverter { public static File convert(File props, boolean backup) throws IOException { if (!props.isFile()) { throw new IllegalArgumentException("The given properties file does not exist : " + props.getAbsolutePath()); } Properties properties; try { properties = readFileAsProperties(props); } catch (IOException e) { throw new IllegalArgumentException("Cannot convert " + props.getName() + " to hocon - the file is not a " + "valid properties file", e); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Cannot convert an empty file : " + props.getAbsolutePath()); } if (backup) { try { generateBackup(props); } catch (IOException e) { throw new IllegalStateException("Cannot generate the backup for " + props.getName(), e); } } String hocon = convertToHocon(props); File output = props; if (!props.getName().endsWith(".conf")) { output = new File(props.getParentFile(), props.getName().substring(0, props.getName().lastIndexOf(".")) + ".conf"); } FileUtils.write(output, hocon); return output; } private  Properties2HoconConverter(); static File convert(File props, boolean backup); static String convertToHocon(File props); }
Properties2HoconConverter { public static File convert(File props, boolean backup) throws IOException { if (!props.isFile()) { throw new IllegalArgumentException("The given properties file does not exist : " + props.getAbsolutePath()); } Properties properties; try { properties = readFileAsProperties(props); } catch (IOException e) { throw new IllegalArgumentException("Cannot convert " + props.getName() + " to hocon - the file is not a " + "valid properties file", e); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Cannot convert an empty file : " + props.getAbsolutePath()); } if (backup) { try { generateBackup(props); } catch (IOException e) { throw new IllegalStateException("Cannot generate the backup for " + props.getName(), e); } } String hocon = convertToHocon(props); File output = props; if (!props.getName().endsWith(".conf")) { output = new File(props.getParentFile(), props.getName().substring(0, props.getName().lastIndexOf(".")) + ".conf"); } FileUtils.write(output, hocon); return output; } private  Properties2HoconConverter(); static File convert(File props, boolean backup); static String convertToHocon(File props);  }