class TexFileUtils extends Object
org.apache.commons.io..| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFAULT_BUFFER_SIZE
The default buffer size (4096) to use for
copyStream(InputStream, OutputStream) |
private LogWrapper |
log |
private static String |
PATTERN_INS_LATEX_MAIN |
private static String |
PREFIX_HIDDEN |
| Constructor and Description |
|---|
TexFileUtils(LogWrapper log) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
cleanUp(DirNode orgNode,
File texDir)
Deletes all files in
texDir including subdirectories
which are not in orgNode. |
private void |
cleanUpRec(File dir,
DirNode orgNode,
DirNode currNode)
Deletes all files in
currNode
which are not in orgNode recursively
including subdirectories. |
private void |
closeQuietly(Closeable closeable)
Unconditionally close a
Closeable. |
(package private) Collection<String> |
collectMatches(File file,
String regex,
int idxGroup)
Returns the set of strings representing the
idxGroup
of the pattern regex matching a line
in file file or returns null
in case of problems reading file. |
(package private) void |
copyOutputToTargetFolder(File texFile,
FileFilter fileFilter,
File targetDir)
Copies output of the current goal to target folder.
|
private static void |
copyStream(InputStream input,
OutputStream output)
Copy bytes from a large (over 2GB)
InputStream to an
OutputStream. |
(package private) void |
deleteOrError(File delFile)
Deletes
delFile or logs a warning. |
(package private) void |
deleteX(File pFile,
FileFilter filter)
Deletes all files in the same folder as
pFile directly,
i.e. not in subfolders, which are accepted by filter. |
private void |
doCopyFile(File srcFile,
File destFile)
Internal copy file method.
|
(package private) FileFilter |
getFileFilter(File texFile,
String pattern)
Returns a file filter matching neither directories
nor
texFile
but else all files with names matching pattern,
where the special sequence PATTERN_INS_LATEX_MAIN
is replaced by the prefix of texFile. |
(package private) FileFilter |
getFileFilterReplace(File idxFile,
String pattern)
Returns a file filter matching no directories
but else all files with names matching
xxx,
where idxFile has the form xxx.idx. |
(package private) String |
getFileNameWithoutSuffix(File file)
Return the name of the given file without the suffix.
|
(package private) String |
getSuffix(File file)
Return the suffix of the name of the given file
including the
. |
(package private) File |
getTargetDirectory(File srcFile,
File srcBaseDir,
File targetBaseDir)
Returns the directory containing
sourceFile
with the prefix sourceBaseDir
replaced by targetBaseDir. |
(package private) File[] |
listFilesOrWarn(File dir)
Returns the listing of the directory
dir
or null if it is not readable
and emit an according warning if so. |
(package private) File[] |
listFilesOrWarn(File dir,
FileFilter filter)
Returns the listing of the directory
dir
filtered by filter
or null if dir is not readable
and emit an according warning if so. |
static void |
main(String[] args) |
(package private) Boolean |
matchInFile(File file,
String regex)
Returns whether the given file
file (which shall exist)
contains the given pattern pattern
or null in case of problems reading file. |
(package private) void |
moveOrError(File fromFile,
File toFile)
Moves file
fromFile to toFile
or logs a warning. |
(package private) File |
replaceSuffix(File file,
String suffix) |
private void |
warnIfNull(File[] files,
File dir) |
private static final String PREFIX_HIDDEN
private static final String PATTERN_INS_LATEX_MAIN
private final LogWrapper log
private static final int DEFAULT_BUFFER_SIZE
copyStream(InputStream, OutputStream)TexFileUtils(LogWrapper log)
File[] listFilesOrWarn(File dir)
dir
or null if it is not readable
and emit an according warning if so.
Logging: WFU01: Cannot read directory
dir - an existing directory.dir
or null if it is not readable.File[] listFilesOrWarn(File dir, FileFilter filter)
dir
filtered by filter
or null if dir is not readable
and emit an according warning if so.
Logging: WFU01: Cannot read directory
dir - an existing directory.filter - a file filterdir
accepted by filter
or null if dir is not readable.File getTargetDirectory(File srcFile, File srcBaseDir, File targetBaseDir) throws BuildFailureException
sourceFile
with the prefix sourceBaseDir
replaced by targetBaseDir.
E.g. sourceFile=/tmp/adir/afile,
sourceBaseDir=/tmp, targetBaseDir=/home
returns /home/adir/.srcFile - the source file the parent directory of which
shall be converted to the target.srcBaseDir - the base directory of the source.
Immediately or not,
sourceFile shall be in sourceBaseDir.targetBaseDir - the base directory of the target.targetBaseDir
which corresponds to the parent directory of sourceFile
which is below sourceBaseDir.BuildFailureException - TFU01: if the target directory that would be returned
exists already as a regular file.FileFilter getFileFilter(File texFile, String pattern)
texFile
but else all files with names matching pattern,
where the special sequence PATTERN_INS_LATEX_MAIN
is replaced by the prefix of texFile.texFile - a latex main file for which a file filter has to be created.pattern - a pattern
for which the special sequence PATTERN_INS_LATEX_MAIN
is replaced by the prefix of texFile
before a file filter is created from it.texFile
but else all files with names matching pattern,
where the special sequence PATTERN_INS_LATEX_MAIN
is replaced by the prefix of texFile.FileFilter getFileFilterReplace(File idxFile, String pattern)
xxx.idx ,
where idxFile has the form xxx.idx.idxFile - an idx file for which a file filter has to be created.pattern - a pattern which is inserted in the name of idxFile
right before the suffix.xxx.idx .void copyOutputToTargetFolder(File texFile, FileFilter fileFilter, File targetDir) throws BuildFailureException
texFile,
all its files passing fileFilter
are considered as output files and
are copied to targetDir.
This is invoked by LatexProcessor.create() only.
Logging:
texFile - the latex main file which was processed.
Its parent directory
is the working directory of the compilation process
in which the output files are created.
Thus it must be readable (in fact it must also be writable;
otherwise the output files could not have been created).fileFilter - the filter accepting the files (and best only the files)
which are the result of the processing.targetDir - the target directory the output files have to be copied to.
If this exists already, it must be a directory
and it must be writable.
If it does not exist, it must be creatable.BuildFailureException - private void doCopyFile(File srcFile, File destFile) throws IOException
Logging: WFU03: Cannot close
srcFile - the source file.destFile - the destination file.IOException - if an error occurs: opening input/output streams,
reading from file/writing to file.private static void copyStream(InputStream input, OutputStream output) throws IOException
InputStream to an
OutputStream.
This method uses the provided buffer, so there is no need to use a
BufferedInputStream.
input - the InputStream to read fromoutput - the OutputStream to write toIOException - if an I/O error occurs while reading or writingprivate void closeQuietly(Closeable closeable)
Closeable.
Equivalent to Closeable.close(),
except any exceptions will be ignored. FIXME
This is typically used in finally blocks.
Example code:
Closeable closeable = null;
try {
closeable = new FileReader("foo.txt");
// process closeable
closeable.close();
} catch (Exception e) {
// error handling
} finally {
IOUtils.closeQuietly(closeable);
}
Logging: WFU03: Cannot close
closeable - the object to close, may be null or already closedString getFileNameWithoutSuffix(File file)
getSuffix(File)String getSuffix(File file)
.,
except there is no ..
Then the suffix is empty.getFileNameWithoutSuffix(File)Boolean matchInFile(File file, String regex)
file (which shall exist)
contains the given pattern pattern
or null in case of problems reading file.
This is typically applied to log files,
but also to latex-files to find the latex main files.
Logging:
WFU03 cannot close
Note that in case null is returned,
no error/warning is logged.
This must be done by the invoking method.
file - an existing proper file, not a folder.regex - the pattern (regular expression) to look for in file.file (which shall exist)
contains the given pattern pattern.
If the file does not exist or an IOException occurs
while reading, null is returned.Collection<String> collectMatches(File file, String regex, int idxGroup)
idxGroup
of the pattern regex matching a line
in file file or returns null
in case of problems reading file.
This is used only to collect the identifiers of explicitly given indices in an idx-file.
file - an existing proper file, not a folder.
In practice this is an idx file.regex - the pattern (regular expression) to look for in file.idxGroup - the number of a group of the pattern regex.idxGroup
of the pattern regex matching a line
in file file or returns null
in case of problems reading file.void deleteX(File pFile, FileFilter filter)
pFile directly,
i.e. not in subfolders, which are accepted by filter.
Logging:
pFile - a file in a folder to be deleted from.
This is either a metapost file or a latex main file.filter - a filter which decides which files
from the parent directory of pFile to delete.void deleteOrError(File delFile)
delFile or logs a warning.
Logging: EFU05: failed to delete
delFile - the existing file to be deleted.
This must not be a directory.void moveOrError(File fromFile, File toFile)
fromFile to toFile
or logs a warning.
Logging: EFU06: failed to move.
fromFile - the existing file to be moved.
This must not be a directory.toFile - the file to be moved to
This must not be a directory.void cleanUp(DirNode orgNode, File texDir)
texDir including subdirectories
which are not in orgNode.
The background is, that orgNode represents the files
originally in texDir.
Logging:
orgNode - texDir - private void cleanUpRec(File dir, DirNode orgNode, DirNode currNode)
currNode
which are not in orgNode recursively
including subdirectories.
The background is, that orgNode represents the files
originally in the directory and currNode
the current ones at the end of the creating goal.
Logging: EFU05: Cannot delete...
orgNode - the node representing the original files.
This is the latex source directory or a subdirectory.currNode - the node representing the current files.
This is the latex source directory or a subdirectory.public static void main(String[] args)
Copyright © 2016–2018 Simuline Organization (l2r). All rights reserved.