public final class FileUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
addFileChangeListener(FileChangeListener fcl)
Registers
listener so that it will receive
FileEvent s from FileSystem s providing instances
of FileObject convertible to java.io.File . |
static void |
addFileChangeListener(FileChangeListener listener,
File path)
Adds a listener to changes in a given path.
|
static void |
addRecursiveListener(FileChangeListener listener,
File path)
Works like
addRecursiveListener(listener, path, null, null) . |
static void |
addRecursiveListener(FileChangeListener listener,
File path,
Callable<Boolean> stop)
Works like
addRecursiveListener(listener, path, null, stop) . |
static void |
addRecursiveListener(FileChangeListener listener,
File path,
FileFilter recurseInto,
Callable<Boolean> stop)
Adds a listener to changes under given path.
|
static boolean |
affectsOrder(FileAttributeEvent event)
Checks whether a change in a given file attribute would affect the result of
FileUtil.getOrder(java.util.Collection<org.openide.filesystems.FileObject>, boolean) . |
static File |
archiveOrDirForURL(URL entry)
Convert a classpath-type URL to a corresponding file.
|
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 void |
copyAttributes(FileObject source,
FileObject dest,
java.util.function.BiFunction<String,Object,Object> attrTransformer)
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(File data)
Returns FileObject for a data file.
|
static FileObject |
createData(FileObject folder,
String name)
Returns a data file on given filesystem if such a data file exists.
|
static FileObject |
createFolder(File folder)
Returns FileObject for a folder.
|
static FileObject |
createFolder(FileObject folder,
String name)
Returns a folder on given filesystem if such a folder exists.
|
static FileSystem |
createMemoryFileSystem()
Factory method that creates an empty implementation of a filesystem that
completely resides in a memory.
|
static java.util.function.BiFunction<String,Object,Object> |
defaultAttributesTransformer()
Default attribute transformer for
FileUtil.copyAttributes(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject, java.util.function.BiFunction) that
skips common transient attributes defined or used by the Platform. |
static void |
extractJar(FileObject fo,
InputStream is)
Deprecated.
Use of XML filesystem layers generally obsoletes this method.
For tests, use
org.openide.util.test.TestFileUtils#unpackZipFile . |
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)
Deprecated.
Use
FileUtil.toFileObject(java.io.File) instead. |
static FileObject |
getArchiveFile(FileObject fo)
Returns a FileObject representing an archive file containing the
FileObject given by the parameter.
|
static URL |
getArchiveFile(URL url)
Returns the URL of the archive file containing the file
referred to by an archive (eg.
|
static FileObject |
getArchiveRoot(FileObject fo)
Returns a FileObject representing the root folder of an archive.
|
static URL |
getArchiveRoot(URL url)
Returns a URL representing the root of an archive.
|
static FileObject |
getConfigFile(String path)
Returns
FileObject from the NetBeans default (system, configuration)
filesystem or null if does not exist. |
static <T> T |
getConfigObject(String path,
Class<T> type)
Finds a config object under given path.
|
static FileObject |
getConfigRoot()
Returns the root of the NetBeans default (system, configuration)
filesystem.
|
static String |
getExtension(String fileName)
Gets the extension of a specified file name.
|
static String |
getFileDisplayName(FileObject fo)
Get an appropriate display name for a file object.
|
static String |
getMIMEType(FileObject fo)
Resolves MIME type.
|
static String |
getMIMEType(FileObject fo,
String... withinMIMETypes)
Resolves MIME type.
|
static String |
getMIMEType(String ext)
Deprecated.
use
FileUtil.getMIMEType(FileObject) or FileUtil.getMIMEType(FileObject, String[])
as MIME cannot be generally detected by file object extension. |
static List<String> |
getMIMETypeExtensions(String mimeType)
Returns list of file extensions associated with specified MIME type.
|
static List<FileObject> |
getOrder(Collection<FileObject> children,
boolean logWarnings)
Sorts some sibling file objects.
|
static String |
getRelativePath(FileObject folder,
FileObject fo)
Gets a relative resource path between folder and fo.
|
static FileObject |
getSystemConfigFile(String path)
Returns
FileObject from the default filesystem, or null if the file does not exist. |
static <T> T |
getSystemConfigObject(String path,
Class<T> type)
Finds a config object under the given path, in system-wide configuration.
|
static FileObject |
getSystemConfigRoot()
Returns the root of the NetBeans default (system, configuration)
filesystem.
|
static boolean |
isArchiveArtifact(FileObject fo)
Tests if an file is inside an archive.
|
static boolean |
isArchiveArtifact(URL url)
Tests if an
URL denotes a file inside an archive. |
static boolean |
isArchiveFile(FileObject fo)
Tests if a file represents a java archive.
|
static boolean |
isArchiveFile(URL url)
Tests if a URL represents a java archive.
|
static boolean |
isParentOf(FileObject folder,
FileObject fo)
Recursively checks whether the file is underneath the folder.
|
static boolean |
isRecursiveSymbolicLink(FileObject fo)
Check whether some FileObject is a recursive symbolic link.
|
static boolean |
isValidFileName(String fileName)
Determines whether the string forms a valid filename (without a path component).
|
static FileObject |
moveFile(FileObject source,
FileObject destFolder,
String newName)
Moves file to the selected folder.
|
static URLStreamHandler |
nbfsURLStreamHandler()
Deprecated.
No longer used.
|
static File |
normalizeFile(File file)
Normalize a file path to a clean form.
|
static String |
normalizePath(String path)
See
FileUtil.normalizeFile(java.io.File) for details |
static void |
preventFileChooserSymlinkTraversal(JFileChooser chooser,
File currentDirectory)
Deprecated.
Just use
JFileChooser.setCurrentDirectory(java.io.File) . JDK 6 does not have this bug. |
static void |
refreshAll()
Refreshes all
FileObject that represent files File.listRoots()
and their children recursively. |
static void |
refreshFor(File... files)
Refreshes all necessary filesystems.
|
static void |
removeFileChangeListener(FileChangeListener fcl)
Unregisters
listener so that it will no longer receive
FileEvent s from FileSystem s providing instances
of FileObject convertible to java.io.File |
static void |
removeFileChangeListener(FileChangeListener listener,
File path)
Removes a listener to changes in a given path.
|
static void |
removeRecursiveListener(FileChangeListener listener,
File path)
Removes a listener to changes under given path.
|
static void |
runAtomicAction(FileSystem.AtomicAction atomicCode)
Executes atomic action.
|
static void |
runAtomicAction(Runnable atomicCode)
Executes atomic action.
|
static void |
setMIMEType(String extension,
String mimeType)
Registers specified extension to be recognized as specified MIME type.
|
static void |
setOrder(List<FileObject> children)
Imposes an order on some sibling file objects.
|
static File |
toFile(FileObject fo)
Finds appropriate java.io.File to FileObject if possible.
|
static FileObject |
toFileObject(File file)
Converts a disk file to a matching file object.
|
static FileObject |
toFileObject(Path path)
Converts a Path to a FileObject if that is possible.
|
static Path |
toPath(FileObject fo)
Finds appropriate java.nio.file.Path to FileObject if possible.
|
static URL |
urlForArchiveOrDir(File entry)
Convert a file such as would be shown in a classpath entry into a proper folder URL.
|
static FileChangeListener |
weakFileChangeListener(FileChangeListener l,
Object source)
Creates a weak implementation of FileChangeListener.
|
static FileStatusListener |
weakFileStatusListener(FileStatusListener l,
Object source)
Creates a weak implementation of FileStatusListener.
|
public static void refreshFor(File... files)
FileObject
are refreshed
but just those that represent passed files
and their children recursively.files
- public static void refreshAll()
FileObject
that represent files File.listRoots()
and their children recursively.public static void addFileChangeListener(FileChangeListener fcl)
listener
so that it will receive
FileEvent
s from FileSystem
s providing instances
of FileObject
convertible to java.io.File
.fcl
- FileUtil.toFileObject(java.io.File)
public static void removeFileChangeListener(FileChangeListener fcl)
listener
so that it will no longer receive
FileEvent
s from FileSystem
s providing instances
of FileObject
convertible to java.io.File
fcl
- FileUtil.toFileObject(java.io.File)
public static void addFileChangeListener(FileChangeListener listener, File path)
path.isDirectory() == false
)
path.isDirectory() == true
)
listener
- FileChangeListener to listen to changes in pathpath
- File path to listen to (even not existing)FileObject.addFileChangeListener(org.openide.filesystems.FileChangeListener)
public static void removeFileChangeListener(FileChangeListener listener, File path)
listener
- FileChangeListener to be removedpath
- File path in which listener was listeningIllegalArgumentException
- if listener was not listening to given pathFileObject.removeFileChangeListener(org.openide.filesystems.FileChangeListener)
public static void addRecursiveListener(FileChangeListener listener, File path)
addRecursiveListener(listener, path, null, null)
.listener
- FileChangeListener to listen to changes in pathpath
- File path to listen to (even not existing)public static void addRecursiveListener(FileChangeListener listener, File path, Callable<Boolean> stop)
addRecursiveListener(listener, path, null, stop)
.listener
- FileChangeListener to listen to changes in pathpath
- File path to listen to (even not existing)stop
- an interface to interrupt the process of registering
the listener. If the call
returns true, the process
of registering the listener is immediately interruptedFileObject.addRecursiveListener(org.openide.filesystems.FileChangeListener)
public static void addRecursiveListener(FileChangeListener listener, File path, FileFilter recurseInto, Callable<Boolean> stop)
path.isDirectory() == false
), this
code behaves exactly like FileUtil.addFileChangeListener(org.openide.filesystems.FileChangeListener, java.io.File)
.
Usually the path shall represent a folder (path.isDirectory() == true
)
stop
.
This stop object is guaranteed to be called once per every folder on the
default (when masterfs module is included) implemention. If the call
to stop.call()
returns true, then the registration of
next recursive items is interrupted. The listener may or may not get
some events from already registered folders.
recurseInto
callback can prevent
the system to enter, and register operating system level listeners
to certain subtrees under the provided path
. This does
not prevent delivery of changes, if they are made via the filesystem API.
External changes however will not be detected.listener
- FileChangeListener to listen to changes in pathpath
- File path to listen to (even not existing)stop
- an interface to interrupt the process of registering
the listener. If the call
returns true, the process
of registering the listener is immediately interrupted. null
value disables this kind of callback.recurseInto
- a file filter that may return false
when
a folder should not be traversed into and external changes in it ignored.
null
recurses into all subfolderspublic static void removeRecursiveListener(FileChangeListener listener, File path)
listener
- FileChangeListener to be removedpath
- File path in which listener was listeningIllegalArgumentException
- if listener was not listening to given pathFileObject.removeRecursiveListener(org.openide.filesystems.FileChangeListener)
public static final void runAtomicAction(FileSystem.AtomicAction atomicCode) throws IOException
FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)
.
All events about filesystem changes (related to events on all affected instances of FileSystem
)
are postponed after the whole atomicCode
is executed.
atomicCode
- code that is supposed to be run as atomic action. See FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)
IOException
public static final void runAtomicAction(Runnable atomicCode)
FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)
.
All events about filesystem changes (related to events on all affected instances of FileSystem
)
are postponed after the whole atomicCode
is executed.
atomicCode
- code that is supposed to be run as atomic action. See FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)
public static FileObject createFolder(File folder) throws IOException
folder
- folder to be createdIOException
- if the creation failspublic static FileObject createData(File data) throws IOException
data
- data file to be createdIOException
- if the creation failspublic static void copy(InputStream is, OutputStream os) throws IOException
Please be aware, that this method doesn't close any of passed streams.
is
- input streamos
- output streamIOException
public static FileSystem createMemoryFileSystem()
To specify the MIME type of a data file without using a MIME resolver,
set the mimeType
file attribute.
Since 7.42, a URLMapper
is available for files (and folders)
in memory filesystems. These URLs are valid only so long as the filesystem
has not been garbage-collected, so hold the filesystem (or a file in it)
strongly for as long as you expect the URLs to be in play.
public 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
- where the new folder will be placed inname
- name of the new folderIOException
- 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)
FileUtil.toFileObject(java.io.File)
.fo
- FileObject whose corresponding File will be looked forpublic static Path toPath(FileObject fo)
FileUtil.toFileObject(java.io.File)
.fo
- FileObject whose corresponding Path will be looked forpublic static FileObject toFileObject(File file)
FileUtil.toFile(org.openide.filesystems.FileObject)
.
If you are running with org.netbeans.modules.masterfs
enabled,
this method should never return null for a file which exists on disk.
For example, to make this method work in unit tests in an Ant-based module project,
right-click Unit Test Libraries, Add Unit Test Dependency, check Show Non-API Modules, select Master Filesystem.
(Also right-click the new Master Filesystem node, Edit, uncheck Include in Compile Classpath.)
To ensure masterfs (or some other module that can handle the conversion)
is present put following line into your module manifest:
OpenIDE-Module-Needs: org.openide.filesystems.FileUtil.toFileObject
file
- a disk file (may or may not exist). This file
must be normalized.URLMapper
available to convert itpublic static FileObject toFileObject(Path path)
FileUtil.toFileObject(java.io.File)
method with path.toFile()
.
if the conversion is not possible for some reason null
is returned.path
- the Path
to be convertedFileObject
representing the path
or null
@Deprecated public static FileObject[] fromFile(File file)
FileUtil.toFileObject(java.io.File)
instead.file
- File whose corresponding FileObjects will be looked for.
The file has to be "normalized" otherwise IllegalArgumentException is thrown.
See FileUtil.normalizeFile(java.io.File)
for how to do that.public static void copyAttributes(FileObject source, FileObject dest) throws IOException
source
- source file objectdest
- destination file objectIOException
- if the copying failedpublic static java.util.function.BiFunction<String,Object,Object> defaultAttributesTransformer()
FileUtil.copyAttributes(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject, java.util.function.BiFunction)
that
skips common transient attributes defined or used by the Platform. Custom Attribute Transformers should delegate to this instance.public static void copyAttributes(FileObject source, FileObject dest, java.util.function.BiFunction<String,Object,Object> attrTransformer) throws IOException
attrTransformer
is specified,
it is called for each attribute that is about to be copied. The returned value will be
written to the target. If attrTransformer
returns null
, the attribute will be skipped.
The Transformer should delegate to FileUtil.defaultAttributesTransformer()
to conform to the usual transient attribute
conventions - unless it really intends to copy such otherwise transient attributes.source
- source file objectdest
- destination file objectattrTransformer
- callback to transform or filter attribute values. Can be null
.IOException
- if the copying failed@Deprecated public static void extractJar(FileObject fo, InputStream is) throws IOException
org.openide.util.test.TestFileUtils#unpackZipFile
.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)
isVirtual
.
Otherwise, the first available name of the form 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.
folder
- parent foldername
- preferred base name of fileext
- extension to use (or null)public static String findFreeFolderName(FileObject folder, String name)
See caveat for findFreeFileName
.
folder
- parent foldername
- preferred folder namefindFreeFileName
public static String getRelativePath(FileObject folder, FileObject fo)
folder
- root of filesystem or any other folder in folders hierarchyfo
- arbitrary FileObject in folder's tree (including folder itself)null
if fo is not in
folder's tree.FileUtil.isParentOf(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject)
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
@Deprecated public static String getMIMEType(String ext)
FileUtil.getMIMEType(FileObject)
or FileUtil.getMIMEType(FileObject, String[])
as MIME cannot be generally detected by 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 unrecognized.
It may return content/unknown
instead of null
.public static String getMIMEType(FileObject fo, String... withinMIMETypes)
content/unknown
instead of null
- if
you want to avoid such behavior, include null
in the
list of requested withinMIMETypes
- in such case the
return value is guaranteed to be one of the values in withinMIMETypes
or null
.
Example: Check if some file is Java source file or text file:
FileUtil.getMIMEType(fo, null, "text/x-java", "text/plain") != null
fo
- whose MIME type should be recognizedwithinMIMETypes
- an array of MIME types. Only resolvers whose
MIMEResolver#getMIMETypes()
contain one or more of the requested
MIME types will be asked if they recognize the file. It is possible for
the resulting MIME type to not be a member of this list.null
if
the FileObject is unrecognized.public static void setMIMEType(String extension, String mimeType)
extension
- the file extension to be registeredmimeType
- the MIME type to be registered for the extension or null
to deregisterFileUtil.getMIMEType(FileObject)
,
FileUtil.getMIMETypeExtensions(String)
public static List<String> getMIMETypeExtensions(String mimeType)
null
.mimeType
- the MIME type (e.g. image/gif)null
FileUtil.setMIMEType(String, String)
@Deprecated public static URLStreamHandler nbfsURLStreamHandler()
public static boolean isParentOf(FileObject folder, FileObject fo)
FileObject
of the file recursively until the folder is found
or the root of the filesystem is reached.
Warning: this method will return false in the case that
folder == fo
.
folder
- the root of folders hierarchy to search info
- the file to search fortrue
, if fo
lies somewhere underneath the folder
,
false
otherwisepublic static boolean isRecursiveSymbolicLink(FileObject fo) throws IOException
fo
- FileObject to check.IOException
- If some I/O problem occurs.public static FileChangeListener weakFileChangeListener(FileChangeListener l, Object source)
l
- the listener to delegate tosource
- the source that the listener should detach from when
listener l
is freed, can be null
l
.public static FileStatusListener weakFileStatusListener(FileStatusListener l, Object source)
l
- the listener to delegate tosource
- the source that the listener should detach from when
listener l
is freed, can be null
l
.public static String getFileDisplayName(FileObject fo)
FileObject
isn't root FileObject.isRoot()
.fo
- a file objectpublic static String normalizePath(String path)
FileUtil.normalizeFile(java.io.File)
for detailspath
- file path to normalizepublic static File normalizeFile(File file)
.
and ..
sequences are removed; etc.
Unlike File.getCanonicalFile()
this method will not traverse symbolic links on Unix.
This method involves some overhead and should not be called frivolously.
Generally it should be called on incoming pathnames that are gotten from user input
(including filechoosers), configuration files, Ant properties, etc. Internal
calculations should not need to renormalize paths since File.listFiles()
,
File.getParentFile()
, etc. will not produce abnormal variants.
file
- file to normalizepublic static FileObject getArchiveRoot(FileObject fo)
FileUtil.isArchiveFile(FileObject)
to determine
if the file object refers to an archive file.fo
- a java archive file, by default ZIP and JAR are supportedpublic static URL getArchiveRoot(URL url)
FileUtil.isArchiveFile(URL)
to determine if the URL
refers to an archive file.url
- of a java archive file, by default ZIP and JAR are supportedjar
) protocol URL of the root of the archive.public static FileObject getArchiveFile(FileObject fo)
fo
- a file in an archive filesystemfo
is not an archive entrypublic static URL getArchiveFile(URL url)
jar
) protocol URL.
Remember that any path within the archive is discarded
so you may need to check for non-root entries.url
- a URL!/
public static boolean isArchiveFile(FileObject fo)
fo
- the file to be testedpublic static boolean isArchiveFile(URL url)
url
- a URL to a filepublic static boolean isArchiveArtifact(FileObject fo)
fo
- the file to be testedpublic static boolean isArchiveArtifact(URL url)
URL
denotes a file inside an archive.url
- the url to be testedpublic static URL urlForArchiveOrDir(File entry)
file
URL will be created.
If it looks to represent a ZIP archive, a jar
URL will be created.entry
- a file or directory name/
),
or null for an existing file which does not look like a valid archivepublic static File archiveOrDirForURL(URL entry)
jar
URL representing the root folder of a local disk archive,
that archive file will be returned.
If it is a file
URL representing a local disk folder,
that folder will be returned.entry
- a classpath entry or similar URL@Deprecated public static void preventFileChooserSymlinkTraversal(JFileChooser chooser, File currentDirectory)
JFileChooser.setCurrentDirectory(java.io.File)
. JDK 6 does not have this bug.chooser
- a file choosercurrentDirectory
- if not null, a file to set as the current directory
using JFileChooser.setCurrentDirectory(java.io.File)
without canonicalizingpublic static List<FileObject> getOrder(Collection<FileObject> children, boolean logWarnings) throws IllegalArgumentException
Normally this is done by looking for numeric file attributes named position
on the children; children with a lower position number are placed first.
Now-deprecated relative ordering attributes of the form earlier/later
may
also be used; if the above attribute has a boolean value of true
,
then the file named earlier
will be sorted somewhere (not necessarily directly)
before the file named later
. Numeric and relative attributes may also be mixed.
The sort is stable at least to the extent that if there is no ordering information whatsoever, the returned list will be in the same order as the incoming collection.
children
- zero or more files (or folders); must all have the same FileObject.getParent()
logWarnings
- true to log warnings about relative ordering attributes or other semantic problems, false to keep quietIllegalArgumentException
- in case there are duplicates, or nulls, or the files do not have a common parentFileUtil.setOrder(java.util.List<org.openide.filesystems.FileObject>)
,
Specificationpublic static void setOrder(List<FileObject> children) throws IllegalArgumentException, IOException
FileUtil.getOrder(java.util.Collection<org.openide.filesystems.FileObject>, boolean)
on these files should return a list in the same order.
Beyond the fact that this call may manipulate the position
attributes
of files in the folder, and may delete deprecated relative ordering attributes on the folder,
the exact means of setting the order is unspecified.children
- a list of zero or more files (or folders); must all have the same FileObject.getParent()
IllegalArgumentException
- in case there are duplicates, or nulls, or the files do not have a common parentIOException
- if new file attributes to order the children cannot be written outpublic static boolean affectsOrder(FileAttributeEvent event)
FileUtil.getOrder(java.util.Collection<org.openide.filesystems.FileObject>, boolean)
.event
- an attribute change eventpublic static FileObject getConfigFile(String path)
FileObject
from the NetBeans default (system, configuration)
filesystem or null
if does not exist.
If you wish to create the file/folder when it does not already exist,
start with FileUtil.getConfigRoot()
and use FileUtil.createData(FileObject, String)
or FileUtil.createFolder(FileObject, String)
methods.
In environment with multiple contextual Lookups, the method may return different FileObject depending
on what Lookup serves the executing thread. If the system-wide (user-independent) configuration
is required instead, FileUtil.getSystemConfigFile(java.lang.String)
should be called instead. If an service instance is created based
on the configuration, it is important to decide whether the service instance should live for each context
independently (possibly with some private means of communication between instances/users) or all users
should share the same instance. In the later case, FileUtil.getSystemConfigFile(java.lang.String)
must be used.
path
- the path from the root of the NetBeans default (system, configuration)
filesystem delimited by '/' or empty string to get root folder.FileObject
for given path in the NetBeans default (system, configuration)
filesystem or null
if does not existNullPointerException
- if the path is null
public static FileObject getSystemConfigFile(String path)
FileObject
from the default filesystem, or null
if the file does not exist.
Unlike FileUtil.getConfigFile(java.lang.String)
, this call returns a FileObject from the system-wide configuration.
Because default/config filesystem is used both for configuration and services, Lookup or service providers
should use this method in preference to FileUtil.getConfigFile(java.lang.String)
to produce singleton services even
in multiple context environment.
With the default Lookup implementation, behaviour of getSystemConfigFile
and FileUtil.getConfigFile(java.lang.String)
is identical.
path
- the path from the root of the NetBeans default (system, configuration)
filesystem delimited by '/' or empty string to get root folder.FileObject
for given path in the NetBeans default (system, configuration)
filesystem or null
if does not existNullPointerException
- if the path is null
public static <T> T getConfigObject(String path, Class<T> type)
Actions/Edit/org-openide-actions-CopyAction.instance Services/Browsers/swing-browser.settings
In multi-user setup, this method returns instance specific for the executing user.
Important: it returns user-specific instance even though the object is configured in
a XML layer, or system-wide configuration; still, the instance will be tied to the user-specific
file as served by FileUtil.getConfigFile(java.lang.String)
.
path
- path to .instance or .settings filetype
- the requested type for given objectpublic static <T> T getSystemConfigObject(String path, Class<T> type)
FileUtil.getConfigObject(java.lang.String, java.lang.Class<T>)
. In
multi-user setups, this method should return an instance shared between
potential users; in a sense, it works as FileUtil.getConfigObject(java.lang.String, java.lang.Class<T>)
prior version 9.5path
- path to .instance or .settings filetype
- the requested type for given objectpublic static FileObject getConfigRoot()
FileObject
for the root of the NetBeans default (system, configuration)
filesystempublic static FileObject getSystemConfigRoot()
FileUtil.getConfigRoot()
, this method always provides the
system-wide configuration root.FileObject
for the root of the NetBeans default (system, configuration)
filesystempublic static boolean isValidFileName(String fileName)
fileName
- candidate string