public class ProcessUtils extends Object
Constructor and Description |
---|
ProcessUtils() |
Modifier and Type | Method and Description |
---|---|
static Object |
collectProcessOutput(InputStream inputStream,
int maxCollect,
Set<Thread> collectionThreads)
Collect all output from an inputstream, up to maxCollect bytes, in an output object.
|
static void |
discardProcessOutput(InputStream inputStream)
Read the output from a process.
|
static int |
runProcess(String... programAndArgs)
Runs an external process that takes no input, discarding its output.
|
static int |
runProcess(String[] environment,
String... programAndArgs)
Runs an external process that takes no input, discarding its output.
|
static int |
runUnixSort(File inputFile,
File outputFile)
Runs a system process (Unix sort) to sort a file.
|
static int |
runUnixSort(File inputFile,
File outputFile,
File tempDir,
boolean crawllogSorting)
Runs a system process (Unix sort) to sort a file.
|
static Integer |
waitFor(Process p,
long maxWait)
Wait for the end of a process, but only for a limited time.
|
static void |
writeProcessOutput(InputStream inputStream,
File outputFile,
Set<Thread> collectionThreads)
Collect all output from an inputstream, appending it to a file.
|
public ProcessUtils()
public static int runProcess(String[] environment, String... programAndArgs)
environment
- An environment to run the process in (may be null)programAndArgs
- The program and its arguments.public static int runProcess(String... programAndArgs)
programAndArgs
- The program to run and its argumentspublic static void discardProcessOutput(InputStream inputStream)
inputStream
- A stream to read up to end of file. This stream is closed at some point in the future, but not
necessarily before this method returns.public static Object collectProcessOutput(InputStream inputStream, int maxCollect, Set<Thread> collectionThreads)
inputStream
- The inputstream to read contents frommaxCollect
- The maximum number of bytes to collect, or -1 for no limitcollectionThreads
- Set of threads that concurrently collect outputpublic static void writeProcessOutput(InputStream inputStream, File outputFile, Set<Thread> collectionThreads)
inputStream
- The inputstream to read contents fromoutputFile
- The file that output should be appended to.collectionThreads
- Set of threads that concurrently collect outputpublic static Integer waitFor(Process p, long maxWait)
p
- Process to wait formaxWait
- The maximum number of milliseconds to wait for the process to exit.public static int runUnixSort(File inputFile, File outputFile)
inputFile
- the input file.outputFile
- the output file.public static int runUnixSort(File inputFile, File outputFile, File tempDir, boolean crawllogSorting)
inputFile
- the input file.outputFile
- the output file.tempDir
- the directory where to store temporary files (null for default system temp).crawllogSorting
- Should we sort crawllog style ("-k 4b") or notCopyright © 2005–2018 The Royal Danish Library, the National Library of France and the Austrian National Library.. All rights reserved.