package stexfires.io;

import stexfires.core.Record;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.util.Objects;

/**
 * @author Mathias Kalb
 * @since 0.1
 */
public class BaseRecordFile<W extends Record, R extends W> implements ReadableRecordFile<R>, WritableRecordFile<W> {

    protected final Path path;

    public BaseRecordFile(final Path path) {
        Objects.requireNonNull(path);
        this.path = path;
    }

    @Override
    public final Path getPath() {
        return path;
    }

    @Override
    public ReadableRecordProducer<R> openProducer() throws IOException {
        throw new UnsupportedOperationException();
    }

    @Override
    public WritableRecordConsumer<W> openConsumer() throws IOException {
        throw new UnsupportedOperationException();
    }

    @Deprecated
    protected BufferedWriter newBufferedWriter(Charset charset,
                                               OpenOption... options) throws IOException {
        return Files.newBufferedWriter(path, charset, options);
    }

    protected BufferedWriter newBufferedWriter(CharsetEncoder charsetEncoder,
                                               OpenOption... options) throws IOException {
        return new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(path, options), charsetEncoder));
    }

    protected BufferedReader newBufferedReader(CharsetDecoder charsetDecoder,
                                               OpenOption... options) throws IOException {
        return new BufferedReader(new InputStreamReader(Files.newInputStream(path, options), charsetDecoder));
    }

    protected CharsetDecoder newCharsetDecoder(Charset charset,
                                               CodingErrorAction malformedInputAction) {
        return newCharsetDecoder(charset, malformedInputAction, null);
    }

    protected CharsetDecoder newCharsetDecoder(Charset charset,
                                               CodingErrorAction malformedInputAction,
                                               String replacement) {
        CharsetDecoder charsetDecoder = charset.newDecoder().onMalformedInput(malformedInputAction);
        if (malformedInputAction == CodingErrorAction.REPLACE && replacement != null) {
            charsetDecoder = charsetDecoder.replaceWith(replacement);
        }
        return charsetDecoder;
    }

    protected CharsetEncoder newCharsetEncoder(Charset charset,
                                               CodingErrorAction unmappableCharacterAction) {
        return newCharsetEncoder(charset, unmappableCharacterAction, null);
    }

    protected CharsetEncoder newCharsetEncoder(Charset charset,
                                               CodingErrorAction unmappableCharacterAction,
                                               byte[] replacement) {
        CharsetEncoder charsetEncoder = charset.newEncoder().onUnmappableCharacter(unmappableCharacterAction);
        if (unmappableCharacterAction == CodingErrorAction.REPLACE && replacement != null) {
            charsetEncoder = charsetEncoder.replaceWith(replacement);
        }
        return charsetEncoder;
    }

}

@@ -1159,250 +1159,8 @@
  %7D%0A%0A
-    @Deprecated%0A    protected BufferedWriter newBufferedWriter(Charset charset,%0A                                               OpenOption... options) throws IOException %7B%0A        return Files.newBufferedWriter(path, charset, options);%0A    %7D%0A%0A
     
@@ -1229,24 +1229,24 @@
 setEncoder,%0A
+
             
@@ -1723,32 +1723,180 @@
 coder));%0A    %7D%0A%0A
+    protected CharsetDecoder newCharsetDecoder(Charset charset) %7B%0A        return newCharsetDecoder(charset, CodingErrorAction.REPORT, null);%0A    %7D%0A%0A
     protected Ch
@@ -2591,32 +2591,32 @@
 ent);%0A        %7D%0A
-
         return c
@@ -2629,32 +2629,180 @@
 Decoder;%0A    %7D%0A%0A
+    protected CharsetEncoder newCharsetEncoder(Charset charset) %7B%0A        return newCharsetEncoder(charset, CodingErrorAction.REPORT, null);%0A    %7D%0A%0A
     protected Ch

Remove deprecated method and add two methods