26import java.time.Instant;
27import java.util.Comparator;
49 public static native String
dirname(
final String path);
59 public static native String
basename(
final String path);
101 public static native
int from_java_fd(
final java.io.FileDescriptor jfd);
110 public static boolean mkdir(
final String path,
final FMode mode) {
111 return mkdirImpl(path, mode.
mask);
113 private static native
boolean mkdirImpl(
final String path,
final int mode);
118 public static boolean mkdir(
final String path) {
131 public static boolean touch(
final String path,
final Instant atime,
final Instant mtime,
133 return touchImpl(path,
134 atime.getEpochSecond(), atime.getNano(),
135 mtime.getEpochSecond(), mtime.getNano(),
138 private static native
boolean touchImpl(
final String path,
139 long atime_s,
long atime_ns,
140 long mtime_s,
long mtime_ns,
152 public static boolean touch(
final String path,
final FMode mode) {
223 return visitImpl(item_stats, topts, visitor,
new long[] { 0 });
225 private static boolean visitImpl(
final FileStats item_stats,
final TraverseOptions topts,
final PathVisitor visitor,
final long[] depth) {
227 if( item_stats.
is_dir() ) {
231 if( !topts.
isSet(TraverseOptions.Bit.recursive) ) {
232 return visitor.visit( TraverseEvent.dir_non_recursive, item_stats, depth[0] );
234 if( topts.
isSet(TraverseOptions.Bit.dir_check_entry) ) {
235 if( !visitor.visit( TraverseEvent.dir_check_entry, item_stats, depth[0] ) ) {
239 if( topts.
isSet(TraverseOptions.Bit.dir_entry) ) {
240 if( !visitor.visit( TraverseEvent.dir_entry, item_stats, depth[0] ) ) {
245 final Comparator<DirItem> dirItemComparator =
new Comparator<DirItem> () {
247 public int compare(
final DirItem o1,
final DirItem o2) {
248 return o1.basename().compareTo(o2.basename());
253 if(
null != content && content.size() > 0 ) {
254 if( topts.
isSet(TraverseOptions.Bit.lexicographical_order) ) {
255 content.sort(dirItemComparator);
257 for (
final DirItem element : content) {
258 final FileStats element_stats =
new FileStats( element );
259 if( element_stats.is_dir() ) {
260 if( element_stats.is_link() && !topts.
isSet(TraverseOptions.Bit.follow_symlinks) ) {
261 if( !visitor.visit( TraverseEvent.dir_symlink, element_stats, depth[0] ) ) {
264 }
else if( !visitImpl(element_stats, topts, visitor, depth) ) {
267 }
else if( !visitor.visit( element_stats.is_file() && element_stats.is_link() ? TraverseEvent.file_symlink :
268 ( element_stats.is_file() ? TraverseEvent.file :
269 ( element_stats.is_link() ? TraverseEvent.symlink : TraverseEvent.none ) ),
270 element_stats, depth[0] ) ) {
276 if( item_stats.
is_dir() && topts.
isSet(TraverseOptions.Bit.dir_exit) ) {
277 return visitor.visit( TraverseEvent.dir_exit, item_stats, depth[0] );
278 }
else if( item_stats.
is_file() || !item_stats.
ok() ) {
279 return visitor.visit( item_stats.
is_file() && item_stats.
is_link() ? TraverseEvent.file_symlink :
280 ( item_stats.
is_file() ? TraverseEvent.file :
281 ( item_stats.
is_link() ? TraverseEvent.symlink : TraverseEvent.none ) ),
282 item_stats, depth[0] );
305 return remove_impl(path, topts.
mask);
307 private static native
boolean remove_impl(
final String path,
final short topts);
317 public static native
boolean compare(
final String source1,
final String source2,
final boolean verbose);
356 public static boolean copy(
final String source_path,
final String dest_path,
final CopyOptions copts) {
357 return copy_impl(source_path, dest_path, copts.
mask);
359 private static native
boolean copy_impl(
final String source_path,
final String dest_path,
final short copts);
377 public static native
boolean rename(
final String oldpath,
final String newpath);
382 public static native
void sync();
404 public static long mount_image(
final String image_path,
final String target,
final String fs_type,
405 final MountFlags flags,
final String fs_options) {
406 return mount_image_impl(image_path, target, fs_type, flags.
value(), fs_options);
408 private static native
long mount_image_impl(
final String image_path,
final String target,
final String fs_type,
409 final long mountflags,
final String fs_options);
428 public static long mount(
final String source,
final String target,
final String fs_type,
429 final MountFlags flags,
final String fs_options) {
430 return mount_impl(source, target, fs_type, flags.
value(), fs_options);
432 private static native
long mount_impl(
final String source,
final String target,
final String fs_type,
433 final long mountflags,
final String fs_options);
449 return umount1_impl(context, flags.
value());
451 private static native
boolean umount1_impl(
final long context,
final int unmountflags);
468 return umount2_impl(target, flags.
value());
470 private static native
boolean umount2_impl(
final String target,
final int unmountflags);
Filesystem copy options used to copy() path elements.
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
static final FMode def_dir
Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_g...
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
String path()
Returns the unix path representation.
boolean is_file()
Returns true if entity is a file, might be in combination with is_link().
boolean ok()
Returns true if no error occurred.
boolean is_link()
Returns true if entity is a symbolic link, might be in combination with is_file(),...
boolean is_dir()
Returns true if entity is a directory, might be in combination with is_link().
Native file types and functionality.
static boolean touch(final String path, final Instant atime, final Instant mtime, final FMode mode)
Touch the file with given atime and mtime and create file if not existing yet.
static boolean copy(final String source_path, final String dest_path, final CopyOptions copts)
Copy the given source_path to dest_path using copy_options.
static native String dirname(final String path)
Return stripped last component from given path separated by /, excluding the trailing separator /.
static long mount_image(final String image_path, final String target, final String fs_type, final MountFlags flags, final String fs_options)
Attach the filesystem image named in image_path to target using an intermediate platform specific fil...
static native String basename(final String path)
Return stripped leading directory components from given path separated by /.
static boolean umount(final long context, final UnmountFlags flags)
Detach the given mount_ctx context
static boolean mkdir(final String path)
See mkdir(String, FMode) using FMode#def_dir.
static boolean mkdir(final String path, final FMode mode)
Create directory.
static boolean visit(final FileStats item_stats, final TraverseOptions topts, final PathVisitor visitor)
Visit element(s) of a given path, see traverse_options for detailed settings.
static boolean touch(final String path, final FMode mode)
Touch the file with current time and create file if not existing yet.
static native void sync()
Synchronizes filesystems, i.e.
static native boolean rename(final String oldpath, final String newpath)
Rename oldpath to newpath using POSIX ::rename(), with the following combinations.
static boolean umount(final String target, final UnmountFlags flags)
Detach the topmost filesystem mounted on target optionally using given umountflags options if support...
static native int from_java_fd(final java.io.FileDescriptor jfd)
Returns the file descriptor from the given FileDescriptor instance.
static native String to_named_fd(final int fd)
Returns platform dependent named file descriptor of given file descriptor, if supported.
static native String get_cwd()
Return the current working directory or empty on failure.
static native boolean compare(final String source1, final String source2, final boolean verbose)
Compare the bytes of both files, denoted by source1 and source2.
static final long UTIME_NOW
static native List< DirItem > get_dir_content(final String path)
Returns a list of directory elements excluding .
static long mount(final String source, final String target, final String fs_type, final MountFlags flags, final String fs_options)
Attach the filesystem named in source to target using the given filesystem source directly.
static boolean visit(final String path, final TraverseOptions topts, final PathVisitor visitor)
Visit element(s) of a given path, see traverse_options for detailed settings.
static native int from_named_fd(final String named_fd)
Returns the file descriptor from the given named file descriptor.
Generic flag bit values for mount() flags.
Filesystem traverse options used to visit() path elements.
boolean isSet(final Bit bit)
Generic flag bit class for umount() flags
Filesystem traverse event used to call path_visitor for path elements from visit().
dir_symlink
Visiting a symbolic-link to a directory which is not followed, i.e.
follow_symlinks
Traverse through symbolic linked directories if traverse_options::recursive is set,...
Path visitor for FileUtil#visit(FileStats, TraverseOptions, PathVisitor).
boolean visit(TraverseEvent tevt, final FileStats item_stats, final long depth)