package com.macmillan.nmeyers; /* FileStatus.java: Implement some POSIX-specific file system access. Copyright (c) 1999 Nathan Meyers $Id: FileStatus.java,v 1.2 1999/11/08 05:03:42 nathanm Exp $ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * Provide access to POSIX-specific information about the file system. * This class extends {@link java.io.File} to obtain POSIX-specific * information that is not supported by Java. */ public class FileStatus extends java.io.File { /** * File owner. Value is the owner's UID in textual form. * @serial */ public String uid = null; // UID in text form /** * File group. Value is the file's GID in textual form. * @serial */ public String gid = null; // GID in text form /** * File mode. Value is the POSIX permissions bits. * @serial */ public int mode = 0; // Mode bits /** * Symbolic link target. If the file is a symbolic link, this * will be non-null and contain the name of the link target. * @serial */ public String target = null; // Target of symlink static { System.loadLibrary("FileStatus"); } /** * This class' extension of the {@link java.io.File} constructor * with the same signature. */ public FileStatus(String path) { super(path); getExtendedInformation(); } /** * This class' extension of the {@link java.io.File} constructor * with the same signature. */ public FileStatus(String path, String name) { super(path, name); getExtendedInformation(); } /** * This class' extension of the {@link java.io.File} constructor * with the same signature. */ public FileStatus(java.io.File dir, String name) { super(dir, name); getExtendedInformation(); } /** * This is the native entry point for obtaining the POSIX file * information and filling in fields of this class. */ private native void getExtendedInformation(); /** * This provides a small test program that queries and reports * information about files specified on the command line. */ public static void main(String[] argv) { for (int i = 0; i < argv.length; i++) { FileStatus file = new FileStatus(argv[i]); System.out.print(file.toString() + ": owner = " + file.uid + ", group = " + file.gid + ", mode = " + file.mode); if (file.target != null) System.out.print(", symlink to " + file.target); System.out.println(""); } } }