posix
Class Stat

java.lang.Object
  extended by posix.Stat

public class Stat
extends Object

File status record for posix systems. The cross-platform features of java.io.File do not cover everything available on posix systems.


Field Summary
 long atime
          Time of last access
static int BLK
           
 int blksize
          Optimal blocksize for filesystem.
 long blocks
          Actual number of blocks allocated.
static int CHR
           
 long ctime
          Time of last file status change
 int dev
          ID of device containing a directory entry for this file.
static int DIR
           
static int FIFO
           
 int gid
          Group ID of the file's group
 int ino
          File serial number.
static int LNK
           
 int mode
          File mode.
 long mtime
          Time of last data modification
 int nlink
          Number of links.
 int rdev
          ID of device if special file.
static int REG
           
 long size
          File size in bytes.
static int SOCK
           
 int uid
          User ID of the file's owner
 
Constructor Summary
Stat()
          Create a blank Stat record.
Stat(String path)
          Create a Stat record for the named file.
Stat(String path, boolean follow)
          Create a Stat record for the named file.
 
Method Summary
static int chmod(String path, int mode)
          Set the user and group of a file.
static int chown(String path, int uid, int gid)
          Set the user and group of a file.
 boolean isBLK()
          True if Stat is for a block device.
 boolean isCHR()
          True if Stat is for a character device.
 boolean isDIR()
          True if Stat is for a directory.
 boolean isFIFO()
          True if Stat is for a unix pipe.
 boolean isLNK()
          True if Stat is for a symbolic link.
 boolean isREG()
          True if Stat is for a regular file.
 boolean isSOCK()
          True if Stat is for a unix socket.
 int lstat(String path)
          Fill in fields from a file path.
static boolean S_IS(int what, int mode)
          Test posix file modes.
 int stat(String path)
          Fill in fields from a file path.
static int umask()
          Return the current process file creation mask.
static int umask(int mask)
          Set the process file creation mask.
static int utime(String path, long mtime, long atime)
          Set the access and modification times of a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dev

public int dev
ID of device containing a directory entry for this file.


ino

public int ino
File serial number.


mode

public int mode
File mode.


nlink

public int nlink
Number of links.


uid

public int uid
User ID of the file's owner


gid

public int gid
Group ID of the file's group


rdev

public int rdev
ID of device if special file.


size

public long size
File size in bytes.


atime

public long atime
Time of last access


mtime

public long mtime
Time of last data modification


ctime

public long ctime
Time of last file status change


blksize

public int blksize
Optimal blocksize for filesystem.


blocks

public long blocks
Actual number of blocks allocated.


LNK

public static final int LNK
See Also:
Constant Field Values

REG

public static final int REG
See Also:
Constant Field Values

DIR

public static final int DIR
See Also:
Constant Field Values

CHR

public static final int CHR
See Also:
Constant Field Values

BLK

public static final int BLK
See Also:
Constant Field Values

FIFO

public static final int FIFO
See Also:
Constant Field Values

SOCK

public static final int SOCK
See Also:
Constant Field Values
Constructor Detail

Stat

public Stat()
Create a blank Stat record.


Stat

public Stat(String path)
     throws IOException
Create a Stat record for the named file.

Parameters:
path - a posix compliant path name for the file
Throws:
IOException

Stat

public Stat(String path,
            boolean follow)
     throws IOException
Create a Stat record for the named file.

Parameters:
path - a posix compliant path name for the file
follow - follow symlinks if true
Throws:
IOException
Method Detail

stat

public int stat(String path)
Fill in fields from a file path. The fields are filled with information about the file.

Returns:
0 on success or errno on failure

lstat

public int lstat(String path)
Fill in fields from a file path. Like stat(java.lang.String), except that if the path refers to a symbolic link, the information for the link is retrieved instead of the file it points to.

Returns:
0 on success or errno on failure

utime

public static int utime(String path,
                        long mtime,
                        long atime)
Set the access and modification times of a file. This calls the posix utimes() function to set the times to the millisecond if available, otherwise it calls utime().

Parameters:
path - the pathname of the file
mtime - the modification time in Java milliseconds
atime - the access time in Java milliseconds
Returns:
0 on success or errno on failure
Since:
1.2.1

chown

public static int chown(String path,
                        int uid,
                        int gid)
Set the user and group of a file. This is probably not that useful in Java since it requires a privileged process.

Parameters:
path - the pathname of the file
uid - the new user id
gid - the new group id
Returns:
0 on success or errno on failure
Since:
1.2.1

chmod

public static int chmod(String path,
                        int mode)
Set the user and group of a file.

Parameters:
path - the pathname of the file
mode - the new posix permission mask
Returns:
0 on success or errno on failure
Since:
1.2.1

S_IS

public static boolean S_IS(int what,
                           int mode)
Test posix file modes.

Parameters:
mode - the posix file mode
what - one of LNK,REG,DIR,CHR,BLK,FIFO,SOCK
Since:
1.1.9

isLNK

public final boolean isLNK()
True if Stat is for a symbolic link. @since 1.1.9


isREG

public final boolean isREG()
True if Stat is for a regular file. @since 1.1.9


isDIR

public final boolean isDIR()
True if Stat is for a directory. @since 1.1.9


isCHR

public final boolean isCHR()
True if Stat is for a character device. @since 1.1.9


isBLK

public final boolean isBLK()
True if Stat is for a block device. @since 1.1.9


isFIFO

public final boolean isFIFO()
True if Stat is for a unix pipe. @since 1.1.9


isSOCK

public final boolean isSOCK()
True if Stat is for a unix socket. @since 1.1.9


umask

public static int umask(int mask)
Set the process file creation mask. Bits in this mask clear corresponding unix permissions when creating a new file. This unix concept is not very Thread friendly, of course, so you'll need to do something like:
    synchronized (Stat.class) {
      int oldmask = Stat.umask(newmask);
      createFile();
      Stat.umask(oldmask);
    }

Returns:
the previous value

umask

public static int umask()
Return the current process file creation mask.