Package sc.fiji.snt.util
Class IOUtils
java.lang.Object
sc.fiji.snt.util.IOUtils
Static utilities for file I/O, namely the detection of reconstruction file formats.
- Author:
- Tiago Ferreira
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe reconstruction formats that can be detected byIOUtils -
Method Summary
Modifier and TypeMethodDescriptionstatic IOUtils.ReconstructionFormatdetectFormat(File file) Guesses the format of a reconstruction file from its first bytes.static IOUtils.ReconstructionFormatdetectFormat(InputStream is, boolean closeStreamAfterGuess) Guesses the format of a reconstruction file from its first bytes (not its extension): gzip magic number, XML (Neurolucida if the header holds an<mbf>root element), JSON ('{'), NDF ('/'), or SWC otherwise.static String[]Returns the extensions (lower case, without the leading period) of the supported reconstruction formats that can be identified by name alone, i.e., not including Neurolucida .xml filesstatic booleanisReconstructionFile(File file) Checks if a file is a reconstruction file based on its extension only (SWC, TRACES, JSON or NDF).static booleanisReconstructionFile(File file, boolean sniffXml) Checks if a file is a reconstruction file.static booleanChecks if a file has an SWC extension, i.e., .swc or .eswc (extended SWC, which holds extra columns that are ignored on import).
-
Method Details
-
detectFormat
public static IOUtils.ReconstructionFormat detectFormat(InputStream is, boolean closeStreamAfterGuess) throws IOException Guesses the format of a reconstruction file from its first bytes (not its extension): gzip magic number, XML (Neurolucida if the header holds an<mbf>root element), JSON ('{'), NDF ('/'), or SWC otherwise.- Parameters:
is- the stream to be inspected. If it supports marking, it is reset after inspection (unlesscloseStreamAfterGuessis true)closeStreamAfterGuess- whetherisshould be closed after inspection- Returns:
- the detected format
- Throws:
IOException- if an IO error occurs
-
detectFormat
Guesses the format of a reconstruction file from its first bytes. SeedetectFormat(InputStream, boolean)- Parameters:
file- the file to be inspected- Returns:
- the detected format
- Throws:
IOException- if the file could not be read
-
getReconstructionExtensions
Returns the extensions (lower case, without the leading period) of the supported reconstruction formats that can be identified by name alone, i.e., not including Neurolucida .xml files- Returns:
- a new array of extensions, e.g., "swc", "traces", etc.
-
isSWCFile
Checks if a file has an SWC extension, i.e., .swc or .eswc (extended SWC, which holds extra columns that are ignored on import). Case-insensitive.- Parameters:
file- the file to be tested- Returns:
- true if the file name ends with ".swc" or ".eswc"
-
isReconstructionFile
Checks if a file is a reconstruction file based on its extension only (SWC, TRACES, JSON or NDF). Neurolucida XML files are not recognized by this method, seeisReconstructionFile(File, boolean)- Parameters:
file- the file to be tested- Returns:
- true if the extension is that of a supported reconstruction format
-
isReconstructionFile
Checks if a file is a reconstruction file. Apart from the extension-only check, XML files are recognized as Neurolucida reconstructions ifsniffXmlis true and their header is that of a Neurolucida file. Only the first few KB of XML files are read.- Parameters:
file- the file to be testedsniffXml- whether .xml files should be inspected- Returns:
- true if the file is a supported reconstruction file
-