Package org.hyperic.sigar

Examples of org.hyperic.sigar.FileInfo$Diff


        }
        return events;
    }

    private long getOffset(FileInfo fileInfo) {
        FileInfo previousFileInfo = fileInfo.getPreviousInfo();

        if (previousFileInfo == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(this.logFile + ": first stat");
            }
            return fileInfo.getSize();
        }

        if (fileInfo.getInode() != previousFileInfo.getInode()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(this.logFile + ": file inode changed");
            }
            return -1;
        }

        if (fileInfo.getSize() < previousFileInfo.getSize()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(this.logFile + ": file truncated");
            }
            return -1;
        }

        if (LOG.isDebugEnabled()) {
            long diff = fileInfo.getSize() - previousFileInfo.getSize();
            LOG.debug(this.logFile + ": " + diff + " new bytes");
        }

        return previousFileInfo.getSize();
    }
View Full Code Here


    private static void printHeader(Sigar sigar, FileInfo info)
        throws SigarException {

        String file = info.getName();
        FileInfo link = sigar.getLinkInfo(file);

        if (link.getType() == FileInfo.TYPE_LNK) {
            try {
                System.out.println(file + " -> " +
                                   new File(file).getCanonicalPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println(link.getTypeChar() +
                           info.getPermissionsString() + "\t" +
                           info.getUid() + "\t" + info.getGid() + "\t" +
                           info.getSize() + "\t" +
                           new Date(info.getMtime()) + "\t" +
                           file);
View Full Code Here

                            FileWatcher watcher,
                            String file,
                            boolean recurse)
        throws SigarException {

        FileInfo info = watcher.add(file);
        printHeader(sigar, info);

        if (!recurse) {
            return;
        }

        if (info.getType() == FileInfo.TYPE_DIR) {
            File[] dirs =
                new File(info.getName()).listFiles(new FileFilter() {
                    public boolean accept(File file) {
                        return file.isDirectory() && file.canRead();
                    }
                });
View Full Code Here

        return new SimpleDateFormat(fmt).format(new Date(mtime));
    }

    public void output(String[] args) throws SigarException {
        String file = args[0];
        FileInfo link = this.sigar.getLinkInfo(file);
        FileInfo info = this.sigar.getFileInfo(file);
        if (link.getType() == FileInfo.TYPE_LNK) {
            try {
                file = file + " -> " + new File(file).getCanonicalPath();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        println(link.getTypeChar() +
                info.getPermissionsString() + "\t" +
                info.getUid() + "\t" + info.getGid() + "\t" +
                info.getSize() + "\t" +
                getDate(info.getMtime()) + "\t" +
                file);
    }
View Full Code Here

    private void getFileInfo(Sigar sigar, String file)
        throws SigarException {

        traceln("Entry=" + file);

        FileInfo info = sigar.getFileInfo(file);

        assertGtEqZeroTrace("Permisions",
                            info.getPermissions());

        assertTrueTrace("Permissions",
                        info.getPermissionsString());

        assertGtEqZeroTrace("Mode", info.getMode());

        assertTrueTrace("Type", info.getTypeString());

        assertGtEqZeroTrace("Size", info.getSize());

        assertGtEqZeroTrace("Uid", info.getUid());

        assertGtEqZeroTrace("Gid", info.getUid());

        assertGtEqZeroTrace("Inode", info.getInode());

        traceln("Device=" + info.getDevice());

        assertGtEqZeroTrace("Nlink", info.getNlink());

        assertGtEqZeroTrace("Atime", info.getAtime());
        traceln(new Date(info.getAtime()).toString());

        assertGtZeroTrace("Mtime", info.getMtime());
        traceln(new Date(info.getMtime()).toString());

        assertGtZeroTrace("Ctime", info.getCtime());
        traceln(new Date(info.getCtime()).toString());

        if (info.getType() == FileInfo.TYPE_DIR) {
            try {
                DirStat stats = sigar.getDirStat(file);
                assertEqualsTrace("Total",
                                  new File(file).list().length,
                                  stats.getTotal());
View Full Code Here

            Thread.sleep(1000 * 1);
        } catch (InterruptedException e) {
        }

        try {
            FileInfo info = sigar.getFileInfo(file);

            FileOutputStream os = null;
            try {
                os = new FileOutputStream(file);
                os.write(1);
            } catch (IOException ioe) {
                throw ioe;
            } finally {
                if (os != null) {
                    try { os.close(); } catch (IOException e) { }
                }
            }

            tmp.setReadOnly();
            boolean changed = info.changed();
            traceln(info.diff());
            assertTrue(info.getPreviousInfo().getSize() != info.getSize());
            assertTrue(changed);
        } catch (SigarNotImplementedException e) {
            //XXX win32
        } catch (SigarException e) {
            throw e;
View Full Code Here

    private void getFileInfo(Sigar sigar, String file)
        throws SigarException {

        traceln("Entry=" + file);

        FileInfo info = sigar.getFileInfo(file);

        assertGtEqZeroTrace("Permisions",
                            info.getPermissions());

        assertTrueTrace("Permissions",
                        info.getPermissionsString());

        assertGtEqZeroTrace("Mode", info.getMode());

        assertTrueTrace("Type", info.getTypeString());

        assertGtEqZeroTrace("Size", info.getSize());

        assertGtEqZeroTrace("Uid", info.getUid());

        assertGtEqZeroTrace("Gid", info.getUid());

        assertGtEqZeroTrace("Inode", info.getInode());

        traceln("Device=" + info.getDevice());

        assertGtEqZeroTrace("Nlink", info.getNlink());

        assertGtEqZeroTrace("Atime", info.getAtime());
        traceln(new Date(info.getAtime()).toString());

        assertGtZeroTrace("Mtime", info.getMtime());
        traceln(new Date(info.getMtime()).toString());

        assertGtZeroTrace("Ctime", info.getCtime());
        traceln(new Date(info.getCtime()).toString());

        if (info.getType() == FileInfo.TYPE_DIR) {
            try {
                DirStat stats = sigar.getDirStat(file);
                assertEqualsTrace("Total",
                                  new File(file).list().length,
                                  stats.getTotal());
View Full Code Here

            Thread.sleep(1000 * 1);
        } catch (InterruptedException e) {
        }

        try {
            FileInfo info = sigar.getFileInfo(file);

            FileOutputStream os = null;
            try {
                os = new FileOutputStream(file);
                os.write(1);
            } catch (IOException ioe) {
                throw ioe;
            } finally {
                if (os != null) {
                    try { os.close(); } catch (IOException e) { }
                }
            }

            tmp.setReadOnly();
            boolean changed = info.changed();
            traceln(info.diff());
            assertTrue(info.getPreviousInfo().getSize() != info.getSize());
            assertTrue(changed);
        } catch (SigarNotImplementedException e) {
            //XXX win32
        } catch (SigarException e) {
            throw e;
View Full Code Here

    private void getFileInfo(Sigar sigar, String file)
        throws SigarException {

        traceln("Entry=" + file);

        FileInfo info = sigar.getFileInfo(file);

        assertGtEqZeroTrace("Permisions",
                            info.getPermissions());

        assertTrueTrace("Permissions",
                        info.getPermissionsString());

        assertGtEqZeroTrace("Mode", info.getMode());

        assertTrueTrace("Type", info.getTypeString());

        assertGtEqZeroTrace("Size", info.getSize());

        assertGtEqZeroTrace("Uid", info.getUid());

        assertGtEqZeroTrace("Gid", info.getUid());

        assertGtEqZeroTrace("Inode", info.getInode());

        traceln("Device=" + info.getDevice());

        assertGtEqZeroTrace("Nlink", info.getNlink());

        assertGtEqZeroTrace("Atime", info.getAtime());
        traceln(new Date(info.getAtime()).toString());

        assertGtZeroTrace("Mtime", info.getMtime());
        traceln(new Date(info.getMtime()).toString());

        assertGtZeroTrace("Ctime", info.getCtime());
        traceln(new Date(info.getCtime()).toString());

        if (info.getType() == FileInfo.TYPE_DIR) {
            try {
                DirStat stats = sigar.getDirStat(file);
                assertEqualsTrace("Total",
                                  new File(file).list().length,
                                  stats.getTotal());
View Full Code Here

            //Thread.sleep(1000 * 1);
      //  } catch (InterruptedException e) {
       // }

        try {
            FileInfo info = sigar.getFileInfo(file);

            FileOutputStream os = null;
            try {
                os = new FileOutputStream(file);
                os.write(1);
            } catch (IOException ioe) {
                throw ioe;
            } finally {
                if (os != null) {
                    try { os.close(); } catch (IOException e) { }
                }
            }

            tmp.setReadOnly();
            boolean changed = info.changed();
            traceln(info.diff());
            assertTrue(info.getPreviousInfo().getSize() != info.getSize());
            assertTrue(changed);
        } catch (SigarNotImplementedException e) {
            //XXX win32
        } catch (SigarException e) {
            throw e;
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.FileInfo$Diff

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.