Class IOUtils

java.lang.Object
sc.fiji.snt.util.IOUtils

public final class IOUtils extends Object
Static utilities for file I/O, namely the detection of reconstruction file formats.
Author:
Tiago Ferreira
  • 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 (unless closeStreamAfterGuess is true)
      closeStreamAfterGuess - whether is should be closed after inspection
      Returns:
      the detected format
      Throws:
      IOException - if an IO error occurs
    • detectFormat

      public static IOUtils.ReconstructionFormat detectFormat(File file) throws IOException
      Guesses the format of a reconstruction file from its first bytes. See detectFormat(InputStream, boolean)
      Parameters:
      file - the file to be inspected
      Returns:
      the detected format
      Throws:
      IOException - if the file could not be read
    • getReconstructionExtensions

      public static String[] 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

      public static boolean isSWCFile(File file)
      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

      public static boolean isReconstructionFile(File file)
      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, see isReconstructionFile(File, boolean)
      Parameters:
      file - the file to be tested
      Returns:
      true if the extension is that of a supported reconstruction format
    • isReconstructionFile

      public static boolean isReconstructionFile(File file, boolean sniffXml)
      Checks if a file is a reconstruction file. Apart from the extension-only check, XML files are recognized as Neurolucida reconstructions if sniffXml is 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 tested
      sniffXml - whether .xml files should be inspected
      Returns:
      true if the file is a supported reconstruction file