@Override public void save(@NonNull ConfigurationNode node) throws IOException { if (sink == null) { throw new IOException("No sink present to write to!"); } try (Writer writer = sink.call()) { if (headerMode != HeaderMode.NONE) { String header = node.getOptions().getHeader(); if (header != null && !header.isEmpty()) { for (String line : getDefaultCommentHandler().toComment(ImmutableList.copyOf(LINE_SPLITTER.split(header)))) { writer.write(line); writer.write(SYSTEM_LINE_SEPARATOR); } writer.write(SYSTEM_LINE_SEPARATOR); } } saveInternal(node, writer); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }
@Override public void save(ConfigurationNode node) throws IOException { if (!canSave()) { throw new IOException("No sink present to write to!"); } try (Writer writer = sink.call()) { if (headerMode != HeaderMode.NONE) { String header = node.getOptions().getHeader(); if (header != null && !header.isEmpty()) { for (String line : getDefaultCommentHandler().toComment(ImmutableList.copyOf(LINE_SPLITTER.split(header)))) { writer.write(line); writer.write(SYSTEM_LINE_SEPARATOR); } writer.write(SYSTEM_LINE_SEPARATOR); } } saveInternal(node, writer); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }
@Override public void save(@NonNull ConfigurationNode node) throws IOException { if (sink == null) { throw new IOException("No sink present to write to!"); } try (Writer writer = sink.call()) { writeHeaderInternal(writer); if (headerMode != HeaderMode.NONE) { String header = node.getOptions().getHeader(); if (header != null && !header.isEmpty()) { for (String line : getDefaultCommentHandler().toComment(ImmutableList.copyOf(LINE_SPLITTER.split(header)))) { writer.write(line); writer.write(SYSTEM_LINE_SEPARATOR); } writer.write(SYSTEM_LINE_SEPARATOR); } } saveInternal(node, writer); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }
@Test public void testSplitLineCommentInput(@TempDirectory.TempDir Path tempDir) throws IOException { final Path saveTo = tempDir.resolve("text2.txt"); HoconConfigurationLoader loader = HoconConfigurationLoader.builder() .setPath(saveTo) .setURL(getClass().getResource("/splitline-comment-input.conf")) .build(); CommentedConfigurationNode node = loader.load(); System.out.println(node.getOptions().getHeader()); loader.save(node); assertEquals(Resources.readLines(getClass().getResource("/splitline-comment-output.conf"), UTF_8), Files.readAllLines(saveTo, UTF_8)); }