content: /*
   * DazzleConf
   * Copyright © 2025 Anand Beh
   *
   * DazzleConf is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * DazzleConf is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with DazzleConf. If not, see <https://www.gnu.org/licenses/>
   * and navigate to version 3 of the GNU Lesser General Public License.
   */
  
  package space.arim.dazzleconf.internals;
  
  import java.io.IOException;
  import java.io.Reader;
  import java.io.Writer;
  import java.nio.charset.Charset;
  import java.nio.file.Files;
  import java.nio.file.Path;
  
  public final class ReadWriteIO {
  
      private ReadWriteIO() {}
  
      public static String readString(Path path, Charset cs) throws IOException {
          return new String(Files.readAllBytes(path), cs);
      }
  
      public static void writeString(Path path, CharSequence csq, Charset cs) throws IOException {
          Files.write(path, csq.toString().getBytes(cs));
      }
  
      private static final int TRANSFER_BUFFER_SIZE = 8192;
      public static void transferToWriter(Reader in, Writer out) throws IOException {
          char[] buffer = new char[TRANSFER_BUFFER_SIZE];
          int nRead;
          while ((nRead = in.read(buffer, 0, TRANSFER_BUFFER_SIZE)) >= 0) {
              out.write(buffer, 0, nRead);
          }
      }
  }
  