public static void checkOpenFile(final String path, final int mask) {
        final SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            // write
            if (isFlag(mask, Constants.O_CREAT) ||
                isFlag(mask, Constants.O_WRONLY)||
                isFlag(mask, Constants.O_RDWR) ||
                isFlag(mask, Constants.O_TRUNC)) {
                sm.checkWrite(path);
            }

            // read
            if (isFlag(mask, Constants.O_RDONLY) ||
                isFlag(mask, Constants.O_RDWR)) {
                sm.checkRead(path);
            }
        }
    }