@Test public void testProperties() throws Exception { File dest = tmp.newFile("dst.properties"); File src = tmp.newFile("src1.properties"); FileUtils.writeStringToFile(dest, "key1=value1", UTF_8); FileUtils.writeStringToFile(src, "key2=value2", UTF_8); append(src, dest); Properties props = new Properties(); try (Reader reader = new FileReader(dest)) { props.load(reader); } assertEquals(2, props.size()); }
private void append(File srcFile, File dstFile, boolean appendNewLine) throws IOException { String srcExt = FileUtils.getFileExtension(srcFile.getName()); String dstExt = FileUtils.getFileExtension(dstFile.getName()); boolean isDstEmpty = dstFile.length() == 0; if (!isDstEmpty && StringUtils.equalsIgnoreCase(srcExt, dstExt) && "json".equalsIgnoreCase(srcExt)) { ObjectMapper m = new ObjectMapper(); ObjectNode destNode = m.readValue(dstFile, ObjectNode.class); ObjectNode srcNode = m.readValue(srcFile, ObjectNode.class); destNode.setAll(srcNode); m.writeValue(dstFile, destNode); } else { try (InputStream in = new FileInputStream(srcFile); OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile, true))) { if (appendNewLine) { out.write(System.getProperty("line.separator").getBytes()); } IOUtils.copy(in, out); } } }
AppendCommand implements Command { private void append(File srcFile, File dstFile, boolean appendNewLine) throws IOException { String srcExt = FileUtils.getFileExtension(srcFile.getName()); String dstExt = FileUtils.getFileExtension(dstFile.getName()); boolean isDstEmpty = dstFile.length() == 0; if (!isDstEmpty && StringUtils.equalsIgnoreCase(srcExt, dstExt) && "json".equalsIgnoreCase(srcExt)) { ObjectMapper m = new ObjectMapper(); ObjectNode destNode = m.readValue(dstFile, ObjectNode.class); ObjectNode srcNode = m.readValue(srcFile, ObjectNode.class); destNode.setAll(srcNode); m.writeValue(dstFile, destNode); } else { try (InputStream in = new FileInputStream(srcFile); OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile, true))) { if (appendNewLine) { out.write(System.getProperty("line.separator").getBytes()); } IOUtils.copy(in, out); } } } }
AppendCommand implements Command { private void append(File srcFile, File dstFile, boolean appendNewLine) throws IOException { String srcExt = FileUtils.getFileExtension(srcFile.getName()); String dstExt = FileUtils.getFileExtension(dstFile.getName()); boolean isDstEmpty = dstFile.length() == 0; if (!isDstEmpty && StringUtils.equalsIgnoreCase(srcExt, dstExt) && "json".equalsIgnoreCase(srcExt)) { ObjectMapper m = new ObjectMapper(); ObjectNode destNode = m.readValue(dstFile, ObjectNode.class); ObjectNode srcNode = m.readValue(srcFile, ObjectNode.class); destNode.setAll(srcNode); m.writeValue(dstFile, destNode); } else { try (InputStream in = new FileInputStream(srcFile); OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile, true))) { if (appendNewLine) { out.write(System.getProperty("line.separator").getBytes()); } IOUtils.copy(in, out); } } } AppendCommand(Path src, Path dst, boolean addNewLine, FileNamePattern pattern);  AppendCommand(Path src, Path dst); }
AppendCommand implements Command { private void append(File srcFile, File dstFile, boolean appendNewLine) throws IOException { String srcExt = FileUtils.getFileExtension(srcFile.getName()); String dstExt = FileUtils.getFileExtension(dstFile.getName()); boolean isDstEmpty = dstFile.length() == 0; if (!isDstEmpty && StringUtils.equalsIgnoreCase(srcExt, dstExt) && "json".equalsIgnoreCase(srcExt)) { ObjectMapper m = new ObjectMapper(); ObjectNode destNode = m.readValue(dstFile, ObjectNode.class); ObjectNode srcNode = m.readValue(srcFile, ObjectNode.class); destNode.setAll(srcNode); m.writeValue(dstFile, destNode); } else { try (InputStream in = new FileInputStream(srcFile); OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile, true))) { if (appendNewLine) { out.write(System.getProperty("line.separator").getBytes()); } IOUtils.copy(in, out); } } } AppendCommand(Path src, Path dst, boolean addNewLine, FileNamePattern pattern);  AppendCommand(Path src, Path dst); @Override void exec(CommandContext ctx); @Override String toString(); @Override String toString(CommandContext ctx); }
AppendCommand implements Command { private void append(File srcFile, File dstFile, boolean appendNewLine) throws IOException { String srcExt = FileUtils.getFileExtension(srcFile.getName()); String dstExt = FileUtils.getFileExtension(dstFile.getName()); boolean isDstEmpty = dstFile.length() == 0; if (!isDstEmpty && StringUtils.equalsIgnoreCase(srcExt, dstExt) && "json".equalsIgnoreCase(srcExt)) { ObjectMapper m = new ObjectMapper(); ObjectNode destNode = m.readValue(dstFile, ObjectNode.class); ObjectNode srcNode = m.readValue(srcFile, ObjectNode.class); destNode.setAll(srcNode); m.writeValue(dstFile, destNode); } else { try (InputStream in = new FileInputStream(srcFile); OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile, true))) { if (appendNewLine) { out.write(System.getProperty("line.separator").getBytes()); } IOUtils.copy(in, out); } } } AppendCommand(Path src, Path dst, boolean addNewLine, FileNamePattern pattern);  AppendCommand(Path src, Path dst); @Override void exec(CommandContext ctx); @Override String toString(); @Override String toString(CommandContext ctx);  }