package posix; import java.io.IOException; /** File status record for posix systems. The cross-platform features of java.io.File do not cover everything available on posix systems. @author Stuart D. Gathman Copyright 2002 Business Management Systems, Inc */ public class Stat { private static native void init(); static { System.loadLibrary("posix"); init(); } /** Create a blank Stat record. */ public Stat() { } /** Create a Stat record for the named file. @param path a posix compliant path name for the file */ public Stat(String path) throws IOException { this(path,true); } /** Create a Stat record for the named file. @param path a posix compliant path name for the file @param follow follow symlinks if true */ public Stat(String path,boolean follow) throws IOException { int rc = follow ? stat(path) : lstat(path); if (rc != 0) throw new IOException(path+": "+Errno.getErrdesc(rc)); } /** ID of device containing a directory entry for this file. */ public int dev; /** File serial number. */ public int ino; /** File mode. */ public int mode; /** Number of links. */ public int nlink; /** User ID of the file's owner */ public int uid; /** Group ID of the file's group */ public int gid; /** ID of device if special file. */ public int rdev; /** File size in bytes. */ public long size; /** Time of last access */ public long atime; /** Time of last data modification */ public long mtime; /** Time of last file status change */ public long ctime; /** Optimal blocksize for filesystem. */ public int blksize; /** Actual number of blocks allocated. */ public long blocks; /** Fill in fields from a file path. The fields are filled with information about the file. @return 0 on success or errno on failure */ public native int stat(String path); /** Fill in fields from a file path. Like {@link posix.Stat#stat}, except that if the path refers to a symbolic link, the information for the link is retrieved instead of the file it points to. @return 0 on success or errno on failure */ public native int lstat(String path); /** Test posix file modes. @param mode the posix file mode @param what one of LNK,REG,DIR,CHR,BLK,FIFO,SOCK */ public static native boolean S_IS(int what,int mode); public static final int LNK = 0, REG = 1, DIR = 2, CHR = 3, BLK = 4, FIFO = 5, SOCK = 6; /** True if Stat is for a symbolic link. */ public final boolean isLNK() { return S_IS(LNK,mode); } /** True if Stat is for a regular file. */ public final boolean isREG() { return S_IS(REG,mode); } /** True if Stat is for a directory. */ public final boolean isDIR() { return S_IS(DIR,mode); } /** True if Stat is for a character device. */ public final boolean isCHR() { return S_IS(CHR,mode); } /** True if Stat is for a block device. */ public final boolean isBLK() { return S_IS(BLK,mode); } /** True if Stat is for a unix pipe. */ public final boolean isFIFO() { return S_IS(FIFO,mode); } /** True if Stat is for a unix socket. */ public final boolean isSOCK() { return S_IS(SOCK,mode); } /** 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);
    }
@return the previous value */ public static native int umask(int mask); /** Return the current process file creation mask. */ public synchronized static native int umask(); }