@Override public NodeType load(ConfigurationOptions options) throws IOException { if (!canLoad()) { throw new IOException("No source present to read from!"); } try (BufferedReader reader = source.call()) { NodeType node; if (headerMode == HeaderMode.PRESERVE || headerMode == HeaderMode.NONE) { String comment = CommentHandlers.extractComment(reader, commentHandlers); if (comment != null && comment.length() > 0) { options = options.setHeader(comment); } } node = createEmptyNode(options); loadInternal(node, reader); return node; } catch (FileNotFoundException | NoSuchFileException e) { // Squash -- there's nothing to read } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } return createEmptyNode(options); }
@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); } } }
@NonNull @Override public NodeType load(@NonNull ConfigurationOptions options) throws IOException { if (source == null) { throw new IOException("No source present to read from!"); } try (BufferedReader reader = source.call()) { if (headerMode == HeaderMode.PRESERVE || headerMode == HeaderMode.NONE) { String comment = CommentHandlers.extractComment(reader, commentHandlers); if (comment != null && comment.length() > 0) { options = options.setHeader(comment); } } NodeType node = createEmptyNode(options); loadInternal(node, reader); return node; } catch (FileNotFoundException | NoSuchFileException e) { // Squash -- there's nothing to read return createEmptyNode(options); } 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()) { 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); } } }
@NonNull @Override public NodeType load(@NonNull ConfigurationOptions options) throws IOException { if (source == null) { throw new IOException("No source present to read from!"); } try (BufferedReader reader = source.call()) { if (headerMode == HeaderMode.PRESERVE || headerMode == HeaderMode.NONE) { String comment = CommentHandlers.extractComment(reader, commentHandlers); if (comment != null && comment.length() > 0) { options = options.setHeader(comment); } } NodeType node = createEmptyNode(options); loadInternal(node, reader); return node; } catch (FileNotFoundException | NoSuchFileException e) { // Squash -- there's nothing to read return createEmptyNode(options); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }