[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nutch-cvs
Subject:    [Nutch-cvs] nutch/src/java/net/nutch/ndfs DF.java,NONE,1.1
From:       Doug Cutting <cutting () users ! sourceforge ! net>
Date:       2005-01-28 19:56:58
Message-ID: E1CucEk-0002Zf-2x () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/nutch/nutch/src/java/net/nutch/ndfs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9886

Added Files:
	DF.java 
Log Message:
Added ability to get filesystem usage statistics.  This will be used
by NDFS data nodes, so that they can be configured to use all
available space on a volume.


--- NEW FILE: DF.java ---
/* Copyright (c) 2005 The Nutch Organization.  All rights reserved.   */
/* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
package net.nutch.ndfs;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

import java.util.StringTokenizer;
import java.util.Iterator;

/** Filesystem disk space usage statistics.  Uses the unix 'df' program.
 * Tested on Linux, FreeBSD and Cygwin. */
class DF {
  private String filesystem;
  private long capacity;
  private long used;
  private long available;
  private int percentUsed;
  private String mount;
  
  public DF(String path) throws IOException {

    Process process = Runtime.getRuntime().exec(new String[] {"df","-k",path});

    try {
      if (process.waitFor() == 0) {
        BufferedReader lines =
          new BufferedReader(new InputStreamReader(process.getInputStream()));

        lines.readLine();                         // skip headings

        StringTokenizer tokens =
          new StringTokenizer(lines.readLine(), " \t\n\r\f%");
        
        this.filesystem = tokens.nextToken();
        this.capacity = Long.parseLong(tokens.nextToken()) * 1024;
        this.used = Long.parseLong(tokens.nextToken()) * 1024;
        this.available = Long.parseLong(tokens.nextToken()) * 1024;
        this.percentUsed = Integer.parseInt(tokens.nextToken());
        this.mount = tokens.nextToken();

      } else {
        throw new IOException
          (new BufferedReader(new InputStreamReader(process.getErrorStream()))
           .readLine());
      }
    } catch (InterruptedException e) {
      throw new IOException(e.toString());
    }
  }

  /// ACCESSORS

  public String getFilesystem() { return filesystem; }
  public long getCapacity() { return capacity; }
  public long getUsed() { return used; }
  public long getAvailable() { return available; }
  public int getPercentUsed() { return percentUsed; }
  public String getMount() { return mount; }
  
  public String toString() {
    return
      "df -k " + mount +"\n" +
      filesystem + "\t" +
      capacity / 1024 + "\t" +
      used / 1024 + "\t" +
      available / 1024 + "\t" +
      percentUsed + "%\t" +
      mount;
  }

  public static void main(String[] args) throws Exception {
    System.out.println(new DF(args[0]));
  }
}



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Nutch-cvs mailing list
Nutch-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nutch-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic