/** {@inheritDoc} */ @Override public long getSparseFileSize(int fd) { FileStat stat = posix.fstat(fd); return stat.blocks() * 512; }
import jnr.posix.*; final POSIX p = POSIXFactory.getPOSIX(); final int S_BLKSIZE = 512; // from sys/stat.h final FileStat stat = p.stat("/some/file.txt"); final long bytes = stat.blocks() * S_BLKSIZE;
@SuppressWarnings("UseOfSystemOutOrSystemErr") protected void reportSpaceUsed(final File dir, final String desc) { final File[] files = dir.listFiles(); if (files == null) { return; } long bytes = 0; for (final File f : files) { if (f.isDirectory()) { throw new UnsupportedOperationException("impl created directory"); } final FileStat stat = POSIX.stat(f.getAbsolutePath()); bytes += stat.blocks() * S_BLKSIZE; } out.println("\nBytes\t" + desc + "\t" + bytes + "\t" + dir.getName()); }
@JRubyMethod(name = "inspect") public IRubyObject inspect() { StringBuilder buf = new StringBuilder("#<"); buf.append(getMetaClass().getRealClass().getName()); buf.append(" "); // FIXME: Obvious issue that not all platforms can display all attributes. Ugly hacks. // Using generic posix library makes pushing inspect behavior into specific system impls // rather painful. try { buf.append("dev=0x").append(Long.toHexString(stat.dev())); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("ino=").append(stat.ino()); } catch (Exception e) {} finally { buf.append(", "); } buf.append("mode=0").append(Integer.toOctalString(stat.mode())).append(", "); try { buf.append("nlink=").append(stat.nlink()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("uid=").append(stat.uid()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("gid=").append(stat.gid()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("rdev=0x").append(Long.toHexString(stat.rdev())); } catch (Exception e) {} finally { buf.append(", "); } buf.append("size=").append(sizeInternal()).append(", "); try { buf.append("blksize=").append(stat.blockSize()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("blocks=").append(stat.blocks()); } catch (Exception e) {} finally { buf.append(", "); } buf.append("atime=").append(atime()).append(", "); buf.append("mtime=").append(mtime()).append(", "); buf.append("ctime=").append(ctime()); buf.append(">"); return getRuntime().newString(buf.toString()); }
@JRubyMethod(name = "inspect") public IRubyObject inspect() { StringBuilder buf = new StringBuilder("#<"); buf.append(getMetaClass().getRealClass().getName()); buf.append(" "); // FIXME: Obvious issue that not all platforms can display all attributes. Ugly hacks. // Using generic posix library makes pushing inspect behavior into specific system impls // rather painful. try { buf.append("dev=0x").append(Long.toHexString(stat.dev())); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("ino=").append(stat.ino()); } catch (Exception e) {} finally { buf.append(", "); } buf.append("mode=0").append(Integer.toOctalString(stat.mode())).append(", "); try { buf.append("nlink=").append(stat.nlink()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("uid=").append(stat.uid()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("gid=").append(stat.gid()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("rdev=0x").append(Long.toHexString(stat.rdev())); } catch (Exception e) {} finally { buf.append(", "); } buf.append("size=").append(sizeInternal()).append(", "); try { buf.append("blksize=").append(stat.blockSize()); } catch (Exception e) {} finally { buf.append(", "); } try { buf.append("blocks=").append(stat.blocks()); } catch (Exception e) {} finally { buf.append(", "); } buf.append("atime=").append(atime()).append(", "); buf.append("mtime=").append(mtime()).append(", "); buf.append("ctime=").append(ctime()); buf.append(">"); return getRuntime().newString(buf.toString()); }
@JRubyMethod(name = "blocks") public IRubyObject blocks() { return getRuntime().newFixnum(stat.blocks()); }
@JRubyMethod(name = "blocks") public IRubyObject blocks() { return getRuntime().newFixnum(stat.blocks()); }
@JRubyMethod(name = "blocks") public IRubyObject blocks() { checkInitialized(); if (Platform.IS_WINDOWS) return getRuntime().getNil(); return getRuntime().newFixnum(stat.blocks()); }
@JRubyMethod(name = "blocks") public IRubyObject blocks() { checkInitialized(); if (Platform.IS_WINDOWS) return getRuntime().getNil(); return getRuntime().newFixnum(stat.blocks()); }