View Javadoc
1   package fr.inrae.agroclim.indicators.util;
2   
3   import java.io.BufferedWriter;
4   import java.io.File;
5   import java.io.FileNotFoundException;
6   import java.io.FileOutputStream;
7   import java.io.OutputStreamWriter;
8   import java.nio.charset.StandardCharsets;
9   import java.nio.file.Path;
10  
11  /**
12   * Shortcut class to write UTF-8 files.
13   *
14   * Last change $Date$
15   *
16   * @author $Author$
17   * @version $Revision$
18   */
19  public class Utf8BufferedWriter extends BufferedWriter {
20  
21      /**
22       * Constructor.
23       *
24       * @param file file to write
25       * @throws FileNotFoundException if file does not exist.
26       */
27      public Utf8BufferedWriter(final File file) throws FileNotFoundException {
28          super(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8));
29      }
30  
31      /**
32       * Constructor.
33       *
34       * @param path path of file to write
35       * @throws FileNotFoundException if file does not exist.
36       */
37      public Utf8BufferedWriter(final Path path) throws FileNotFoundException {
38          super(new OutputStreamWriter(new FileOutputStream(path.toFile(), false), StandardCharsets.UTF_8));
39      }
40  
41      /**
42       * Constructor.
43       *
44       * @param fileName system-dependent name of file to write
45       * @throws FileNotFoundException if file does not exist.
46       */
47      public Utf8BufferedWriter(final String fileName) throws FileNotFoundException {
48          super(new OutputStreamWriter(new FileOutputStream(new File(fileName), true), StandardCharsets.UTF_8));
49      }
50  }