Search in sources :

Example 1 with DirectoryWriter

use of com.joliciel.talismane.utils.io.DirectoryWriter in project talismane by joliciel-informatique.

the class TalismaneMain method getWriter.

private static Writer getWriter(File outFile, File inFile, boolean keepDirectoryStructure, Reader reader, String sessionId) throws IOException {
    if (outFile == null)
        return new BufferedWriter(new OutputStreamWriter(System.out, TalismaneSession.get(sessionId).getOutputCharset()));
    if (inFile.isDirectory() && keepDirectoryStructure) {
        outFile.mkdirs();
        DirectoryWriter directoryWriter = new DirectoryWriter(inFile, outFile, TalismaneSession.get(sessionId).getSuffix(), TalismaneSession.get(sessionId).getOutputCharset());
        return directoryWriter;
    } else {
        File outDir = outFile.getParentFile();
        if (outDir != null)
            outDir.mkdirs();
        outFile.delete();
        outFile.createNewFile();
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), TalismaneSession.get(sessionId).getOutputCharset()));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) DirectoryWriter(com.joliciel.talismane.utils.io.DirectoryWriter) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

DirectoryWriter (com.joliciel.talismane.utils.io.DirectoryWriter)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1