com.jezhumble.javasysmon
Class FileUtils

java.lang.Object
  extended by com.jezhumble.javasysmon.FileUtils

public class FileUtils
extends java.lang.Object

Convenience methods for interacting with the filesystem.


Constructor Summary
FileUtils()
           
 
Method Summary
 java.lang.String[] pidsFromProcFilesystem()
          If you're using an operating system that supports the proc filesystem, this returns a list of all processes by reading the directories under /proc
 java.lang.String runRegexOnFile(java.util.regex.Pattern pattern, java.lang.String filename)
          Runs a regular expression on a file, and returns the first match.
 java.lang.String slurp(java.lang.String fileName)
          Given a filename, reads the entire file into a string.
 java.lang.String slurpFromInputStream(java.io.InputStream stream)
          Given an InputStream, reads the entire file into a string.
 byte[] slurpToByteArray(java.lang.String fileName)
          Given a filename, reads the entire file into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

pidsFromProcFilesystem

public java.lang.String[] pidsFromProcFilesystem()
If you're using an operating system that supports the proc filesystem, this returns a list of all processes by reading the directories under /proc

Returns:
An array of the ids of all processes running on the OS.

slurp

public java.lang.String slurp(java.lang.String fileName)
                       throws java.io.IOException
Given a filename, reads the entire file into a string.

Parameters:
fileName - The path of the filename to read. Should be absolute.
Returns:
A string containing the entire contents of the file
Throws:
java.io.IOException - If there's an IO exception while trying to read the file

slurpToByteArray

public byte[] slurpToByteArray(java.lang.String fileName)
                        throws java.io.IOException
Given a filename, reads the entire file into a byte array.

Parameters:
fileName - The path of the filename to read. Should be absolute.
Returns:
A byte array containing the entire contents of the file
Throws:
java.io.IOException - If there's an IO exception while trying to read the file

slurpFromInputStream

public java.lang.String slurpFromInputStream(java.io.InputStream stream)
                                      throws java.io.IOException
Given an InputStream, reads the entire file into a string.

Parameters:
stream - The InputStream representing the file to read
Returns:
A string containing the entire contents of the input stream
Throws:
java.io.IOException - If there's an IO exception while trying to read the input stream

runRegexOnFile

public java.lang.String runRegexOnFile(java.util.regex.Pattern pattern,
                                       java.lang.String filename)
Runs a regular expression on a file, and returns the first match.

Parameters:
pattern - The regular expression to use.
filename - The path of the filename to match against. Should be absolute.
Returns:
The first match found. Null if no matches.


Copyright © 2009 ThoughtWorks. All Rights Reserved.