public class FileUtil
extends java.lang.Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyFileOrDirectory(java.io.File src,
java.io.File dest)
copies a file or a whole folder to the given destination
|
static void |
copyStreams(java.io.InputStream is,
java.io.OutputStream os)
Copies the content of the passed input stream into the passed output stream
|
static void |
copyTo(java.io.File src,
java.io.File dest)
Copy a file.
|
static java.io.File |
copyToDir(java.io.File src,
java.io.File dir)
Copy file to directory
|
static void |
createJarMetaInf(java.util.jar.JarOutputStream jarOut,
java.util.Map<java.lang.String,java.lang.String> properties) |
static void |
deleteDir(java.io.File dir)
Deletes the passed directory and all its subdirectories (and so on).
|
static void |
deleteDir(java.lang.String dirPath)
Deletes the directory with the given path.
|
static java.lang.String |
getAbsoluteNormalizedPath(java.io.File file)
Gets the absolute normalized path of a file.
|
static java.lang.String |
getAbsoluteNormalizedPath(java.io.File baseDir,
java.io.File file)
Gets the absolute normalized path of a file.
|
static byte[] |
getBytesFromStream(java.io.InputStream is)
Load the content of an InputStream into a byte array.
|
static java.lang.String |
getContent(java.io.File file)
Get the content of a file as string.
|
static java.lang.String |
getContent(java.lang.String filename) |
static java.io.File |
getFileFromPath(java.lang.String path)
Get a file object from a pathname.
|
static java.lang.String |
getMimeType(java.lang.String ext)
Return the mime-type from the extension.
|
static java.lang.String |
getNoComment(java.io.InputStream in)
Get the contents of an input stream without the comments.
|
static java.lang.String |
getNoComment(java.io.Reader in)
Get the contents of a reader without the comments.
|
static java.lang.String |
getNoCommentContent(java.lang.String filename) |
static java.lang.String |
getRelativeNormalizedPath(java.io.File file)
Gets the relative normalized path of a file with respect to the configured base directory (
Settings.getBaseDir() ). |
static java.lang.String |
getRelativeNormalizedPath(java.io.File baseDir,
java.io.File file)
Gets the relative normalized path of a file with respect to a specified base directory.
|
static java.lang.String |
getShinyPathMapping(java.lang.String path)
Returns the shiny path for the passed resource path.
|
static boolean |
isTextFile(java.lang.String pathname)
Returns true if the mime-time of this file starts with text
|
static java.util.List<java.io.File> |
listFiles(java.lang.String namePattern,
java.io.File dir)
List file with name specified with wildcard in directory and all its
subdirectories.
|
static java.util.List<java.io.File> |
listFiles(java.lang.String namePattern,
java.io.File dir,
boolean recursive)
List file with name specified with wildcard in directory.
|
static Document |
loadApplicationResource(java.lang.String resource)
Load a resource, i.e. a file from the classpath.
|
static java.lang.String |
loadResource(java.lang.String resource)
Load a resource as string from the classpath.
|
static java.lang.String |
loadResource(java.net.URL url)
Load a resource as string from an url.
|
static byte[] |
loadResourceBytes(java.lang.String resource) |
static byte[] |
loadResourceBytes(java.net.URL url)
Load a resource as byte array from the classpath.
|
static java.lang.String |
loadResourceFromStream(java.io.InputStream is)
Load a resource from an input stream (file, etc.).
|
static java.lang.String |
loadResourceFromStream(java.io.InputStream is,
java.lang.String charset) |
static void |
packJarFiles(java.util.jar.JarOutputStream jarOut,
java.io.File dir,
java.lang.String[] types) |
static byte[] |
resizeImage(byte[] content,
int maxWidth,
int maxHeight) |
public static java.lang.String getMimeType(java.lang.String ext)
ext
- the extension, for example "doc" or "html"public static java.lang.String getShinyPathMapping(java.lang.String path)
path
- the original path of a resourcepublic static java.lang.String loadResource(java.lang.String resource)
resource
- a path to a resourcepublic static java.lang.String loadResource(java.net.URL url)
url
- the url of the resourcepublic static java.lang.String loadResourceFromStream(java.io.InputStream is) throws java.io.IOException
is
- an input streamjava.io.IOException
public static java.lang.String loadResourceFromStream(java.io.InputStream is, java.lang.String charset) throws java.io.IOException
java.io.IOException
public static Document loadApplicationResource(java.lang.String resource) throws java.io.FileNotFoundException, JDOMException, java.io.IOException
resource
- a path in the classpathjava.io.FileNotFoundException
java.io.IOException
JDOMException
public static byte[] loadResourceBytes(java.net.URL url)
url
- the url of a resourcepublic static byte[] loadResourceBytes(java.lang.String resource)
public static byte[] getBytesFromStream(java.io.InputStream is)
public static void copyTo(java.io.File src, java.io.File dest) throws java.io.FileNotFoundException, java.io.IOException
src
- the source filedest
- the destination filejava.io.FileNotFoundException
java.io.IOException
public static void copyStreams(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOException
is
- the stream holding the contentos
- the stream into which the content should be writtenjava.io.IOException
public static java.io.File copyToDir(java.io.File src, java.io.File dir) throws java.io.FileNotFoundException, java.io.IOException
src
- dir
- java.io.FileNotFoundException
java.io.IOException
public static void copyFileOrDirectory(java.io.File src, java.io.File dest) throws java.io.IOException
src
- source locationdest
- destination locationjava.io.IOException
public static java.lang.String getContent(java.io.File file) throws java.io.IOException
file
- the filejava.io.IOException
public static java.lang.String getNoComment(java.io.InputStream in) throws java.lang.Exception
in
- the input streamjava.lang.Exception
public static java.lang.String getNoComment(java.io.Reader in) throws java.lang.Exception
in
- the readerjava.lang.Exception
public static java.lang.String getNoCommentContent(java.lang.String filename) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getContent(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static void deleteDir(java.lang.String dirPath)
dirPath
- the directory pathpublic static void deleteDir(java.io.File dir)
dir
- the directorypublic static java.io.File getFileFromPath(java.lang.String path)
path
- the path stringpublic static java.lang.String getRelativeNormalizedPath(java.io.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 java.lang.String getRelativeNormalizedPath(java.io.File baseDir, java.io.File file)
baseDir
- the base directory to relativize (Path.relativize(Path)
)the file to.file
- the filepublic static java.lang.String getAbsoluteNormalizedPath(java.io.File file)
Settings.getBaseDir()
).file
- the filepublic static java.lang.String getAbsoluteNormalizedPath(java.io.File baseDir, java.io.File file)
baseDir
- the base directoryfile
- the filepublic static java.util.List<java.io.File> listFiles(java.lang.String namePattern, java.io.File dir)
namePattern
- dir
- public static java.util.List<java.io.File> listFiles(java.lang.String namePattern, java.io.File dir, boolean recursive)
namePattern
- dir
- recursive
- public static boolean isTextFile(java.lang.String pathname)
public static void createJarMetaInf(java.util.jar.JarOutputStream jarOut, java.util.Map<java.lang.String,java.lang.String> properties) throws java.io.IOException
java.io.IOException
public static void packJarFiles(java.util.jar.JarOutputStream jarOut, java.io.File dir, java.lang.String[] types)
public static byte[] resizeImage(byte[] content, int maxWidth, int maxHeight)
@enterprise 9.0.33982 Copyright © 2001-2023 Groiss Informatics GmbH. All Rights Reserved.