FileLocator - apache/ctakes GitHub Wiki

final public class FileLocator

Utility class that attempts to locate files.

  • Author: Mayo Clinic

static private final String CTAKES_HOME = "CTAKES_HOME"

$CTAKES_HOME is an environment variable that may be set to indicate the absolute directory path of the ctakes installation

static private Collection<String> getUrlSearchPaths( final String location )

  • Parameters:
    • location some absolute or relative resource location
  • Returns: a collection containing the location and the location with the prefix resources/

static private Collection<String> getFileSearchPaths( final String location )

  • Parameters:

    • location some absolute or relative file location
  • Returns: a collection containing the location with prefixes created using the working directory, CTAKES_HOME, ctakes, and resources.

    The working directory is traversed backwards to help developers that create projects at upper levels from ctakes.

static private Collection<String> getAllSearchPaths( final String location )

  • Parameters:
    • location some absolute or relative resource or file location
  • Returns: a collection made from {@link #getUrlSearchPaths(String)} and {@link #getFileSearchPaths(String)}

static public InputStream getAsStream( final String location ) throws FileNotFoundException

Fetches stream Search order is by: 1. By resource stream in classpath 2. By file on filesystem 3. By resource url in classpath

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an input stream for the resource
  • Exceptions:
    • FileNotFoundException if no resource could be found

static public InputStream getAsStream( final Class<?> clazz, final String location ) throws FileNotFoundException

Fetches stream Search order is by: 1. By resource stream in classpath 2. By file on filesystem 3. By resource url in classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an input stream for the resource
  • Exceptions:
    • FileNotFoundException if no resource could be found

static public InputStream getStreamQuiet( final String location )

Fetches stream without throwing exceptions. Search order is by: 1. By resource stream in classpath 2. By file on filesystem 3. By resource url in classpath

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an input stream for the resource

static public InputStream getStreamQuiet( final Class<?> clazz, final String location )

Fetches stream without throwing exceptions. Search order is by: 1. By resource stream in classpath 2. By file on filesystem 3. By resource url in classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an input stream for the resource

static private InputStream getStreamOnly( final Class<?> clazz, final String location )

Fetches stream without throwing exceptions only by finding a stream in the classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an input stream for the resource

static public URL getResource( final String location ) throws FileNotFoundException

Fetches resource. Search order is by: 1. By file on filesystem 2. By resource url in classpath

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an url for the resource
  • Exceptions:
    • FileNotFoundException if no resource could be found

static public URL getResource( final Class<?> clazz, final String location ) throws FileNotFoundException

Fetches resource. Search order is by: 1. By file on filesystem 2. By resource url in classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an url for the resource
  • Exceptions:
    • FileNotFoundException if no resource could be found

static public URL getResourceQuiet( final String location )

Fetches resource without throwing exceptions. Search order is by: 1. By file on filesystem 2. By resource url in classpath

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an url for the resource

static public URL getResourceQuiet( final Class<?> clazz, final String location )

Fetches resource without throwing exceptions. Search order is by: 1. By file on filesystem 2. By resource url in classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an url for the resource

static private URL getResourceOnly( final Class<?> clazz, final String location )

Fetches resource without throwing exceptions only by finding a resource in the classpath

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an url for the resource

@Deprecated static public File locateFile( final String location ) throws FileNotFoundException

Calls {@link #getFile(String)}

  • Deprecated

@Deprecated static public File locateFile( final Class<?> clazz, final String location ) throws FileNotFoundException

Calls {@link #getFile(Class, String)}

  • Deprecated

static public File getFile( final String location ) throws FileNotFoundException

Fetches file. Search order is by: 1. By file on filesystem 2. By resource url in classpath 3. By resource stream in classpath If a stream is found then it is copied to a temporary file and that file is returned.

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an file for the resource
  • Exceptions:
    • FileNotFoundException if a file cannot be found or temporary file created

static public File getFile( final Class<?> clazz, final String location ) throws FileNotFoundException

Fetches file. Search order is by: 1. By file on filesystem 2. By resource url in classpath 3. By resource stream in classpath If a stream is found then it is copied to a temporary file and that file is returned.

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an file for the resource
  • Exceptions:
    • FileNotFoundException if a file cannot be found or temporary file created

static public File getFileQuiet( final String location )

Fetches file without throwing exceptions. Search order is by: 1. By file on filesystem 2. By resource url in classpath 3. By resource stream in classpath If a stream is found then it is copied to a temporary file and that file is returned.

  • Parameters:
    • location some string representing the full or partial location of a resource
  • Returns: an file for the resource or null if none is found

static public File getFileQuiet( final Class<?> clazz, final String location )

Fetches file without throwing exceptions. Search order is by: 1. By file on filesystem 2. By resource url in classpath 3. By resource stream in classpath If a stream is found then it is copied to a temporary file and that file is returned.

  • Parameters:
    • clazz some class whose classloader should be used
    • location some string representing the full or partial location of a resource
  • Returns: an file for the resource or null if none is found

static private File getFileOnly( final String location )

Fetches file without throwing exceptions only by finding an existing file in the filesystem.

  • Parameters:
    • location some string representing the full or partial location of a file
  • Returns: a discovered file or null

static private File createTempFile( final InputStream stream, final String location )

  • Parameters:
    • stream an input stream that exists within the classpath
    • location some originally requested file location
  • Returns: a temporary file containing the contents of the stream

@Deprecated static public String getFullPath( final String relativePath ) throws FileNotFoundException

Calls a {@link #getFile(Class, String)} and returns the path of the file or "" if none.

  • Exceptions:
    • FileNotFoundException if the file cannot be found
  • Deprecated

@Deprecated static public String getFullPath( final Class<?> clazz, final String relativePath ) throws FileNotFoundException

Calls a {@link #getFile(Class, String)} and returns the path of the file or "" if none.

  • Exceptions:
    • FileNotFoundException if the file cannot be found
  • Deprecated

@Deprecated static public String getFullPathQuiet( final String relativePath )

Calls a {@link #getFile(Class, String)} and returns the path of the file or "" if none.

  • Deprecated

@Deprecated static public String getFullPathQuiet( final Class<?> clazz, final String relativePath )

Calls a {@link #getFile(Class, String)} and returns the path of the file or "" if none.

  • Deprecated
⚠️ **GitHub.com Fallback** ⚠️