Package org.apache.sling.feature.io

# Class IOUtils

java.lang.Object
org.apache.sling.feature.io.IOUtils

public class IOUtils extends Object

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_DIRECTORY`
The default directory to search for features.
`static final String`
`DEFAULT_FEATURE_FILE`
The default name of the feature file.
`static final String`
`EXTENSION_FEATURE_ARCHIVE`
The extension for a feature file.
`static final String`
`EXTENSION_FEATURE_FILE`
The extension for a feature file.
`static final String`
`EXTENSION_REF_FILE`
The extension for a reference file.

## Constructor Summary

Constructors
Constructor
Description
`IOUtils()`

## Method Summary

Modifier and Type
Method
Description
`static List<String>`
`getFeatureFiles(File homeDirectory, String... files)`
Get the list of feature files.
`static File`
`getFileFromURL(URL url, boolean cache, File tmpDir)`
Get a File from a local URL (if possible)
`static JarFile`
`getJarFileFromURL(URL url, boolean cache, File tmpDir)`
Get a JarFile from a local URL (if possible)
`static List<String>`
`parseFeatureRefFile(File file)`
Parse a feature reference file

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### EXTENSION_REF_FILE

public static final String EXTENSION_REF_FILE
The extension for a reference file.

See Also:
  - Constant Field Values

### EXTENSION_FEATURE_FILE

public static final String EXTENSION_FEATURE_FILE
The extension for a feature file.

See Also:
  - Constant Field Values

### EXTENSION_FEATURE_ARCHIVE

public static final String EXTENSION_FEATURE_ARCHIVE
The extension for a feature file.

See Also:
  - Constant Field Values

### DEFAULT_DIRECTORY

public static final String DEFAULT_DIRECTORY
The default directory to search for features.

See Also:
  - Constant Field Values

### DEFAULT_FEATURE_FILE

public static final String DEFAULT_FEATURE_FILE
The default name of the feature file.

See Also:
  - Constant Field Values

## Constructor Details

### IOUtils

public IOUtils()

## Method Details

### parseFeatureRefFile

public static List<String> parseFeatureRefFile(File file) throws IOException
Parse a feature reference file

Parameters:
  `file` - The file
Returns:
  The referenced features
Throws:
  `IOException` - If reading fails

### getFeatureFiles

public static List<String> getFeatureFiles(File homeDirectory, String... files) throws IOException
Get the list of feature files. If the provided list of files is `null` or an empty array, the default is used. The default checks for the following places, the first one found is used. If none is found an empty list is returned.

1. A directory named `DEFAULT_DIRECTORY` in the current directory
2. A file named `DEFAULT_FEATURE_FILE` in the current directory
3. A directory named `DEFAULT_DIRECTORY` in the home directory
4. A file named `DEFAULT_FEATURE_FILE` in the home directory

The list of files is processed one after the other. If it is relative, it is first tried to be resolved against the current directory and then against the home directory. If an entry denotes a directory, all children ending in `EXTENSION_FEATURE_FILE` or `EXTENSION_REF_FILE` of that directory are read. If a file ends in `EXTENSION_REF_FILE` the contents is read and every line not starting with the hash sign is considered a reference to a feature artifact.

Parameters:
  `homeDirectory` - If relative files should be resolved, this is the directory to use
  `files` - Optional list of files. If none is provided, a default is used.
Returns:
  The list of files.
Throws:
  `IOException` - If an error occurs.

### getFileFromURL

public static File getFileFromURL(URL url, boolean cache, File tmpDir) throws IOException
Get a File from a local URL (if possible)

Parameters:
  `url` - a local url (like a file: url or a jar:file: url
  `cache` - if an attempt should be made to download the content of the url locally if it can not be presented as a file directly
  `tmpDir` - the tmpDir to use (null for default)
Returns:
  the file the url points to (or null if none) - or a tmp file if cache is true and the url could be cached
Throws:
  `IOException` - When an IO Exception occurs.

### getJarFileFromURL

public static JarFile getJarFileFromURL(URL url, boolean cache, File tmpDir) throws IOException
Get a JarFile from a local URL (if possible)

Parameters:
  `url` - a local url (like a file: url or a jar:file: url
  `cache` - if an attempt should be made to download the content of the url locally if it can not be presented as a jarfile directly
  `tmpDir` - the tmpDir to use (null for default)
Returns:
  the jarfile the url points to
Throws:
  `IOException` - if the url can't be represented as a jarfile