diff --git a/src/net/sourceforge/plantuml/SourceFileReader.java b/src/net/sourceforge/plantuml/SourceFileReader.java index 5c6852aca..162130a2f 100644 --- a/src/net/sourceforge/plantuml/SourceFileReader.java +++ b/src/net/sourceforge/plantuml/SourceFileReader.java @@ -38,12 +38,10 @@ package net.sourceforge.plantuml; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.Reader; import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.preproc.Defines; -import net.sourceforge.plantuml.preproc.FileWithSuffix; import net.sourceforge.plantuml.security.SFile; public class SourceFileReader extends SourceFileReaderAbstract implements ISourceFileReader { @@ -70,11 +68,7 @@ public class SourceFileReader extends SourceFileReaderAbstract implements ISourc public SourceFileReader(Defines defines, final File file, File outputDirectory, List config, String charset, FileFormatOption fileFormatOption) throws IOException { - this.file = file; - this.fileFormatOption = fileFormatOption; - if (file.exists() == false) { - throw new IllegalArgumentException(); - } + super(file, fileFormatOption, defines, config, charset); FileSystem.getInstance().setCurrentDir(SFile.fromFile(file.getAbsoluteFile().getParentFile())); if (outputDirectory == null) { outputDirectory = file.getAbsoluteFile().getParentFile(); @@ -86,9 +80,6 @@ public class SourceFileReader extends SourceFileReaderAbstract implements ISourc } this.outputDirectory = outputDirectory; - final Reader reader = getReader(charset); - builder = new BlockUmlBuilder(config, charset, defines, reader, - SFile.fromFile(file.getAbsoluteFile().getParentFile()), FileWithSuffix.getFileName(file)); } private File getDirIfDirectory(String newName) throws FileNotFoundException { diff --git a/src/net/sourceforge/plantuml/SourceFileReaderAbstract.java b/src/net/sourceforge/plantuml/SourceFileReaderAbstract.java index 40b1f6726..7e33495b4 100644 --- a/src/net/sourceforge/plantuml/SourceFileReaderAbstract.java +++ b/src/net/sourceforge/plantuml/SourceFileReaderAbstract.java @@ -53,6 +53,7 @@ import java.util.Set; import net.sourceforge.plantuml.api.ImageDataSimple; import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.error.PSystemError; +import net.sourceforge.plantuml.preproc.Defines; import net.sourceforge.plantuml.preproc.FileWithSuffix; import net.sourceforge.plantuml.security.SFile; import net.sourceforge.plantuml.security.SecurityUtils; @@ -68,6 +69,19 @@ public abstract class SourceFileReaderAbstract implements ISourceFileReader { private boolean checkMetadata; private boolean noerror; + public SourceFileReaderAbstract(File file, FileFormatOption fileFormatOption, Defines defines, List config, String charset) + throws IOException { + + if (!file.exists()) { + throw new IllegalArgumentException(); + } + + this.file = file; + this.fileFormatOption = fileFormatOption; + this.builder = new BlockUmlBuilder(config, charset, defines, getReader(charset), + SFile.fromFile(file.getAbsoluteFile().getParentFile()), FileWithSuffix.getFileName(file)); + } + public void setCheckMetadata(boolean checkMetadata) { this.checkMetadata = checkMetadata; } diff --git a/src/net/sourceforge/plantuml/SourceFileReaderCopyCat.java b/src/net/sourceforge/plantuml/SourceFileReaderCopyCat.java index 180eba81c..215ecc512 100644 --- a/src/net/sourceforge/plantuml/SourceFileReaderCopyCat.java +++ b/src/net/sourceforge/plantuml/SourceFileReaderCopyCat.java @@ -40,18 +40,12 @@ import java.io.IOException; import java.util.List; import net.sourceforge.plantuml.preproc.Defines; -import net.sourceforge.plantuml.preproc.FileWithSuffix; -import net.sourceforge.plantuml.security.SFile; public class SourceFileReaderCopyCat extends SourceFileReaderAbstract implements ISourceFileReader { public SourceFileReaderCopyCat(Defines defines, final File file, File outputDirectory, List config, String charset, FileFormatOption fileFormatOption) throws IOException { - this.file = file; - this.fileFormatOption = fileFormatOption; - if (file.exists() == false) { - throw new IllegalArgumentException(); - } + super(file, fileFormatOption, defines, config, charset); final String path = file.getParentFile().getPath(); // System.err.println("SourceFileReaderCopyCat::path=" + path); // System.err.println("SourceFileReaderCopyCat::outputDirectory=" + @@ -63,8 +57,6 @@ public class SourceFileReaderCopyCat extends SourceFileReaderAbstract implements // System.err.println("SourceFileReaderCopyCat=" + // this.outputDirectory.getPath() + " " // + this.outputDirectory.getAbsolutePath()); - builder = new BlockUmlBuilder(config, charset, defines, getReader(charset), - SFile.fromFile(file.getAbsoluteFile().getParentFile()), FileWithSuffix.getFileName(file)); } @Override diff --git a/src/net/sourceforge/plantuml/SourceFileReaderHardFile.java b/src/net/sourceforge/plantuml/SourceFileReaderHardFile.java index 053d6e76c..a5e9fda6b 100644 --- a/src/net/sourceforge/plantuml/SourceFileReaderHardFile.java +++ b/src/net/sourceforge/plantuml/SourceFileReaderHardFile.java @@ -5,12 +5,12 @@ * (C) Copyright 2009-2020, Arnaud Roques * * Project Info: http://plantuml.com - * + * * If you like this project or if you find it useful, you can support us at: - * + * * http://plantuml.com/patreon (only 1$ per month!) * http://plantuml.com/paypal - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -40,24 +40,15 @@ import java.io.IOException; import java.util.List; import net.sourceforge.plantuml.preproc.Defines; -import net.sourceforge.plantuml.preproc.FileWithSuffix; import net.sourceforge.plantuml.security.SFile; public class SourceFileReaderHardFile extends SourceFileReaderAbstract implements ISourceFileReader { public SourceFileReaderHardFile(Defines defines, final File file, File outputFile, List config, String charset, FileFormatOption fileFormatOption) throws IOException { - this.file = file; - this.fileFormatOption = fileFormatOption; + super(file, fileFormatOption, defines, config, charset); this.outputFile = outputFile; - if (file.exists() == false) { - throw new IllegalArgumentException(); - } FileSystem.getInstance().setCurrentDir(SFile.fromFile(file.getAbsoluteFile().getParentFile())); - - final SFile parentFile = SFile.fromFile(file.getAbsoluteFile().getParentFile()); - builder = new BlockUmlBuilder(config, charset, defines, getReader(charset), parentFile, - FileWithSuffix.getFileName(file)); } @Override