public class FileUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
copyFileOrDirectory(File src,
File dest)
copies a file or a whole folder to the given destination
|
static void |
copyStreams(InputStream is,
OutputStream os)
Copies the content of the passed input stream into the passed output stream
|
static void |
copyTo(File src,
File dest)
Copy a file.
|
static File |
copyToDir(File src,
File dir)
Copy file to directory
|
static void |
createJarMetaInf(JarOutputStream jarOut,
Map<String,String> properties) |
static void |
deleteDir(File dir)
Deletes the passed directory and all its subdirectories (and so on).
|
static void |
deleteDir(String dirPath)
Deletes the directory with the given path.
|
static void |
extractZip(File zip,
File dir,
String... files)
Exctract the given zip into a directory.
|
static String |
getAbsoluteNormalizedPath(File file)
Gets the absolute normalized path of a file.
|
static String |
getAbsoluteNormalizedPath(File baseDir,
File file)
Gets the absolute normalized path of a file.
|
static byte[] |
getBytesFromStream(InputStream is)
Load the content of an InputStream into a byte array.
|
static String |
getContent(File file)
Get the content of a file as string.
|
static String |
getContent(String filename) |
static File |
getFileFromPath(String path)
Get a file object from a pathname.
|
static String |
getMappedImagePath(String path,
boolean inverted)
Returns the shiny path for the passed resource path.
|
static String |
getMimeType(String ext)
Return the mime-type from the extension.
|
static String |
getNoComment(InputStream in)
Get the contents of an input stream without the comments.
|
static String |
getNoComment(Reader in)
Get the contents of a reader without the comments.
|
static String |
getNoCommentContent(String filename) |
static String |
getRelativeNormalizedPath(File file)
Gets the relative normalized path of a file with respect to the configured base directory (
Settings.getBaseDir() ). |
static String |
getRelativeNormalizedPath(File baseDir,
File file)
Gets the relative normalized path of a file with respect to a specified base directory.
|
static String |
getShinyPathMapping(String path)
Returns the shiny path for the passed resource path.
|
static boolean |
isTextFile(String pathname)
Returns true if the mime-time of this file starts with text
|
static List<File> |
listFiles(String namePattern,
File dir)
List file with name specified with wildcard in directory and all its
subdirectories.
|
static List<File> |
listFiles(String namePattern,
File dir,
boolean recursive)
List file with name specified with wildcard in directory.
|
static Document |
loadApplicationResource(String resource)
Load a resource, i.e. a file from the classpath.
|
static String |
loadResource(String resource)
Load a resource as string from the classpath.
|
static String |
loadResource(URL url)
Load a resource as string from an url.
|
static byte[] |
loadResourceBytes(String resource) |
static byte[] |
loadResourceBytes(URL url)
Load a resource as byte array from the classpath.
|
static String |
loadResourceFromStream(InputStream is)
Load a resource from an input stream (file, etc.).
|
static String |
loadResourceFromStream(InputStream is,
String charset) |
static void |
packJarFiles(JarOutputStream jarOut,
File dir,
String[] types) |
static byte[] |
resizeImage(byte[] content,
int maxWidth,
int maxHeight) |
public static String getMimeType(String ext)
ext
- the extension, for example "doc" or "html"public static String getShinyPathMapping(String path)
path
- the original path of a resourcepublic static String getMappedImagePath(String path, boolean inverted)
path
- the original path of a resourcepublic static String loadResource(String resource)
resource
- a path to a resourcepublic static String loadResource(URL url)
url
- the url of the resourcepublic static String loadResourceFromStream(InputStream is) throws IOException
is
- an input streamIOException
public static String loadResourceFromStream(InputStream is, String charset) throws IOException
IOException
public static Document loadApplicationResource(String resource) throws JDOMException, IOException
resource
- a path in the classpathJDOMException
IOException
public static byte[] loadResourceBytes(URL url)
url
- the url of a resourcepublic static byte[] loadResourceBytes(String resource)
public static byte[] getBytesFromStream(InputStream is)
public static void copyTo(File src, File dest) throws IOException
src
- the source filedest
- the destination fileIOException
public static void copyStreams(InputStream is, OutputStream os) throws IOException
is
- the stream holding the contentos
- the stream into which the content should be writtenIOException
public static File copyToDir(File src, File dir) throws IOException
src
- dir
- FileNotFoundException
IOException
public static void copyFileOrDirectory(File src, File dest) throws IOException
src
- source locationdest
- destination locationIOException
public static String getContent(File file) throws IOException
file
- the fileIOException
public static String getNoComment(InputStream in) throws Exception
in
- the input streamException
public static String getNoComment(Reader in) throws Exception
in
- the readerException
public static String getNoCommentContent(String filename) throws Exception
Exception
public static String getContent(String filename) throws IOException
IOException
public static void deleteDir(String dirPath)
dirPath
- the directory pathpublic static void deleteDir(File dir)
dir
- the directorypublic static File getFileFromPath(String path)
path
- the path stringpublic static String getRelativeNormalizedPath(File file)
Settings.getBaseDir()
).
If the file is not related to the base directory, the files absolute normalized path is returned.file
- the filepublic static String getRelativeNormalizedPath(File baseDir, File file)
baseDir
- the base directory to relativize (Path.relativize(Path)
)the file to.file
- the filepublic static String getAbsoluteNormalizedPath(File file)
Settings.getBaseDir()
).file
- the filepublic static String getAbsoluteNormalizedPath(File baseDir, File file)
baseDir
- the base directoryfile
- the filepublic static List<File> listFiles(String namePattern, File dir)
namePattern
- dir
- public static List<File> listFiles(String namePattern, File dir, boolean recursive)
namePattern
- dir
- recursive
- public static boolean isTextFile(String pathname)
public static void createJarMetaInf(JarOutputStream jarOut, Map<String,String> properties) throws IOException
IOException
public static void packJarFiles(JarOutputStream jarOut, File dir, String[] types)
public static byte[] resizeImage(byte[] content, int maxWidth, int maxHeight)
public static void extractZip(File zip, File dir, String... files) throws IOException
zip
- the zip filedir
- the destination directoryfiles
- a list of filenames, that should be excluded from extractionIOException
@enterprise 10.0.39049 Copyright © 2024 FREQUENTIS AG. All Rights Reserved.