|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.openide.filesystems.FileUtil
Common utilities for handling files. This is a dummy class; all methods are static.
Method Summary | |
static void |
copy(InputStream is,
OutputStream os)
Copies stream of files. |
static void |
copyAttributes(FileObject source,
FileObject dest)
Copies attributes from one file to another. |
static FileObject |
copyFile(FileObject source,
FileObject destFolder,
String newName)
Copies file to the selected folder. |
static FileObject |
copyFile(FileObject source,
FileObject destFolder,
String newName,
String newExt)
Copies file to the selected folder. |
static FileObject |
createData(FileObject folder,
String name)
Creates a data file on given file system. |
static FileObject |
createFolder(FileObject folder,
String name)
Creates a folder on given file system. |
static void |
extractJar(FileObject fo,
InputStream is)
Deprecated. Use of XML filesystem layers generally obsoletes this method. |
static FileObject |
findBrother(FileObject fo,
String ext)
Finds brother file with same base name but different extension. |
static String |
findFreeFileName(FileObject folder,
String name,
String ext)
Finds an unused file name similar to that requested in the same folder. |
static String |
findFreeFolderName(FileObject folder,
String name)
Finds an unused folder name similar to that requested in the same parent folder. |
static FileObject[] |
fromFile(File file)
Finds appropriate FileObjects to java.io.File if possible. |
static String |
getExtension(String fileName)
Gets the extension of a specified file name. |
static String |
getMIMEType(FileObject fo)
Resolves MIME type. |
static String |
getMIMEType(String ext)
Deprecated. in favour of getMIMEType(FileObject) as MIME cannot
be generaly detected by a file object extension. |
static FileObject |
moveFile(FileObject source,
FileObject destFolder,
String newName)
Moves file to the selected folder. |
static void |
setMIMEType(String ext,
String mimeType)
Register MIME type for a new extension. |
static File |
toFile(FileObject fo)
Finds appropriate java.io.File to FileObject if possible. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void copy(InputStream is, OutputStream os) throws IOException
is
- input streamos
- output streampublic static FileObject copyFile(FileObject source, FileObject destFolder, String newName, String newExt) throws IOException
source
- source file objectdestFolder
- destination foldernewName
- file name (without extension) of destination filenewExt
- extension of destination fileIOException
- if destFolder
is not a folder or does not exist; the destination file already exists; or
another critical error occurs during copyingpublic static FileObject copyFile(FileObject source, FileObject destFolder, String newName) throws IOException
source
- source file objectdestFolder
- destination foldernewName
- file name (without extension) of destination fileIOException
- if destFolder
is not a folder or does not exist; the destination file already exists; or
another critical error occurs during copyingpublic static FileObject moveFile(FileObject source, FileObject destFolder, String newName) throws IOException
source
- source file objectdestFolder
- destination foldernewName
- file name (without extension) of destination fileIOException
- if either the copy
or delete
failedpublic static FileObject createFolder(FileObject folder, String name) throws IOException
folder
- to begin with creation atname
- name of folder as a resourceIOException
- if the creation failspublic static FileObject createData(FileObject folder, String name) throws IOException
folder
- to begin with creation atname
- name of data file as a resourceIOException
- if the creation failspublic static File toFile(FileObject fo)
fo
- FileObject whose coresponding File will be looked forpublic static FileObject[] fromFile(File file)
fo
- File whose coresponding FileObjects will be looked forpublic static void copyAttributes(FileObject source, FileObject dest) throws IOException
source
- source file objectdest
- destination file objectIOException
- if the copying failedpublic static void extractJar(FileObject fo, InputStream is) throws IOException
META-INF/
directories are skipped over.
fo
- file object of destination folderis
- input stream of jar fileIOException
- if the extraction failspublic static String getExtension(String fileName)
fileName
- name of the file""
if it had none)public static String findFreeFileName(FileObject folder, String name, String ext)
basename_nnn.ext
(counting from one) is used.
Caution: this method does not lock the parent folder
to prevent race conditions: i.e. it is possible (though unlikely)
that the resulting name will have been created by another thread
just as you were about to create the file yourself (if you are,
in fact, intending to create it just after this call). Since you
cannot currently lock a folder against child creation actions,
the safe approach is to use a loop in which a free name is
retrieved; an attempt is made to create
that file; and upon an IOException
during
creation, retry the loop up to a few times before giving up.
df
- parent foldername
- preferred base name of fileext
- extension to usepublic static String findFreeFolderName(FileObject folder, String name)
See caveat for findFreeFileName
.
df
- parent foldername
- preferred folder namefindFreeFileName
public static FileObject findBrother(FileObject fo, String ext)
fo
- the file to find the brother for or null
ext
- extension for the brother filenull
if the brother file does not exist or the original file was null
public static String getMIMEType(String ext)
getMIMEType(FileObject)
as MIME cannot
be generaly detected by a file object extension.
ext
- the extension: "jar"
, "zip"
, etc.null
if the extension is unrecognizedpublic static String getMIMEType(FileObject fo)
fo
- whose MIME type should be recognizednull
if the FileObject is unrecognizedpublic static void setMIMEType(String ext, String mimeType)
ext
- the file extension (should be lowercase unless you specifically care about case)mimeType
- the new MIME typeIllegalArgumentException
- if this extension was already registered with a different MIME typegetMIMEType(java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |