Package org.jbake.app
Class FileUtil
- java.lang.Object
-
- org.jbake.app.FileUtil
-
public class FileUtil extends java.lang.ObjectProvides File related functions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringURI_SEPARATOR_CHAR
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringasPath(java.io.File file)platform independent file.getPath()static java.lang.StringasPath(java.lang.String path)platform independent file.getPath()static booleandirectoryOnlyIfNotIgnored(java.io.File file)Deprecated.static booleandirectoryOnlyIfNotIgnored(java.io.File file, JBakeConfiguration config)Ignores directory (and children) if it contains a file named in the configuration as a marker to ignore the directory.static java.lang.StringfileExt(java.io.File src)static java.lang.StringfileExt(java.lang.String name)static java.io.FileFiltergetDataFileFilter()Filters files based on their file extension - only find data files (i.e.static java.io.FileFiltergetFileFilter()Deprecated.usegetFileFilter(JBakeConfiguration)insteadstatic java.io.FileFiltergetFileFilter(JBakeConfiguration config)Filters files based on their file extension.static java.io.FileFiltergetNotContentFileFilter()Deprecated.usegetNotContentFileFilter(JBakeConfiguration)insteadstatic java.io.FileFiltergetNotContentFileFilter(JBakeConfiguration config)Gets the list of files that are not content files based on their extension.static java.lang.StringgetPathToRoot(JBakeConfiguration config, java.io.File rootPath, java.io.File sourceFile)Given a file inside content it return the relative path to get to the root.static java.io.FilegetRunningLocation()Works out the folder where JBake is running from.static java.lang.StringgetUriPathToContentRoot(JBakeConfiguration config, java.io.File sourceFile)static java.lang.StringgetUriPathToDestinationRoot(JBakeConfiguration config, java.io.File sourceFile)static booleanisExistingFolder(java.io.File f)static booleanisFileInDirectory(java.io.File file, java.io.File directory)Utility method to determine if a given file is located somewhere in the directory provided.static java.lang.Stringsha1(java.io.File sourceFile)Computes the hash of a file or directory.
-
-
-
Field Detail
-
URI_SEPARATOR_CHAR
public static final java.lang.String URI_SEPARATOR_CHAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getFileFilter
public static java.io.FileFilter getFileFilter(JBakeConfiguration config)
Filters files based on their file extension.- Parameters:
config- the jbake configuration- Returns:
- Object for filtering files
-
getFileFilter
@Deprecated public static java.io.FileFilter getFileFilter()
Deprecated.usegetFileFilter(JBakeConfiguration)insteadFilters files based on their file extension.- Returns:
- Object for filtering files
-
getDataFileFilter
public static java.io.FileFilter getDataFileFilter()
Filters files based on their file extension - only find data files (i.e. files with .yaml or .yml extension)- Returns:
- Object for filtering files
-
getNotContentFileFilter
public static java.io.FileFilter getNotContentFileFilter(JBakeConfiguration config)
Gets the list of files that are not content files based on their extension.- Parameters:
config- the jbake configuration- Returns:
- FileFilter object
-
getNotContentFileFilter
@Deprecated public static java.io.FileFilter getNotContentFileFilter()
Deprecated.usegetNotContentFileFilter(JBakeConfiguration)insteadGets the list of files that are not content files based on their extension.- Returns:
- FileFilter object
-
directoryOnlyIfNotIgnored
public static boolean directoryOnlyIfNotIgnored(java.io.File file, JBakeConfiguration config)Ignores directory (and children) if it contains a file named in the configuration as a marker to ignore the directory.- Parameters:
file- the file to testconfig- the jbake configuration- Returns:
- true if file is directory and not ignored
-
directoryOnlyIfNotIgnored
@Deprecated public static boolean directoryOnlyIfNotIgnored(java.io.File file)
Deprecated.Ignores directory (and children) if it contains a file named ".jbakeignore".- Parameters:
file- the file to test- Returns:
- true if file is directory and not ignored
-
isExistingFolder
public static boolean isExistingFolder(java.io.File f)
-
getRunningLocation
public static java.io.File getRunningLocation() throws java.lang.ExceptionWorks out the folder where JBake is running from.- Returns:
- File referencing folder JBake is running from
- Throws:
java.lang.Exception- when application is not able to work out where is JBake running from
-
fileExt
public static java.lang.String fileExt(java.io.File src)
-
fileExt
public static java.lang.String fileExt(java.lang.String name)
-
sha1
public static java.lang.String sha1(java.io.File sourceFile) throws java.lang.ExceptionComputes the hash of a file or directory.- Parameters:
sourceFile- the original file or directory- Returns:
- an hex string representing the SHA1 hash of the file or directory.
- Throws:
java.lang.Exception- if any IOException of SecurityException occured
-
asPath
public static java.lang.String asPath(java.io.File file)
platform independent file.getPath()- Parameters:
file- the file to transform, ornull- Returns:
- The result of file.getPath() with all path Separators beeing a "/", or
nullNeeded to transform Windows path separators into slashes.
-
asPath
public static java.lang.String asPath(java.lang.String path)
platform independent file.getPath()- Parameters:
path- the path to transform, ornull- Returns:
- The result will have all platform path separators replaced by "/".
-
getPathToRoot
public static java.lang.String getPathToRoot(JBakeConfiguration config, java.io.File rootPath, java.io.File sourceFile)
Given a file inside content it return the relative path to get to the root.Example: /content and /content/tags/blog will return '../..'
- Parameters:
sourceFile- the file to calculate relative path forrootPath- the root pathconfig- the jbake configuration- Returns:
- the relative path to get to the root
-
getUriPathToDestinationRoot
public static java.lang.String getUriPathToDestinationRoot(JBakeConfiguration config, java.io.File sourceFile)
-
getUriPathToContentRoot
public static java.lang.String getUriPathToContentRoot(JBakeConfiguration config, java.io.File sourceFile)
-
isFileInDirectory
public static boolean isFileInDirectory(java.io.File file, java.io.File directory) throws java.io.IOExceptionUtility method to determine if a given file is located somewhere in the directory provided.- Parameters:
file- used to check if it is located in the provided directory.directory- to validate whether or not the provided file resides.- Returns:
- true if the file is somewhere in the provided directory, false if it is not.
- Throws:
java.io.IOException- if the canonical path for either of the input directories can't be determined.
-
-