/** * Constructs an instance for controlling a local process. * * @param pidFile file containing the pid of the process to attach to * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IOException if unable to read from the specified file * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws NumberFormatException if the pid file does not contain a parsable integer */ public LocalProcessController(final File pidFile) throws IOException { this(readPid(pidFile)); }
/** * Constructs an instance for controlling a local process. * * @param pidFile file containing the pid of the process to attach to * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IOException if unable to read from the specified file * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws NumberFormatException if the pid file does not contain a parsable integer */ public LocalProcessController(final File pidFile) throws IOException { this(readPid(pidFile)); }
/** * Constructs an instance for controlling a local process. * * @param directory directory containing a file of name pidFileName * @param pidFilename name of the file containing the pid of the process to attach to * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IOException if an I/O error occurs * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws IllegalStateException if dir is not an existing directory * @throws NumberFormatException if the pid file does not contain a parsable integer */ public LocalProcessController(final File directory, final String pidFilename) throws IOException { this(readPid(directory, pidFilename)); }
/** * Constructs an instance for controlling a local process. * * @param directory directory containing a file of name pidFileName * @param pidFilename name of the file containing the pid of the process to attach to * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IOException if an I/O error occurs * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws IllegalStateException if dir is not an existing directory * @throws NumberFormatException if the pid file does not contain a parsable integer */ public LocalProcessController(final File directory, final String pidFilename) throws IOException { this(readPid(directory, pidFilename)); }
/** * Reads in the pid from the named file contained within the specified * directory. * * @param directory directory containing a file of name pidFileName * @param pidFilename name of the file containing the pid of the process to stop * * @return the process id (pid) contained within the pidFile * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws IllegalStateException if dir is not an existing directory * @throws IOException if an I/O error occurs * @throws NumberFormatException if the pid file does not contain a parsable integer */ private static int readPid(final File directory, final String pidFilename) throws IOException { if (!directory.isDirectory() && directory.exists()) { throw new IllegalArgumentException("Argument '" + directory + "' must be an existing directory!"); } final File[] files = directory.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String filename) { return filename.equals(pidFilename); } }); if (files.length == 0) { throw new FileNotFoundException("Unable to find PID file '" + pidFilename + "' in directory " + directory); } return readPid(files[0]); }
/** * Reads in the pid from the named file contained within the specified * directory. * * @param directory directory containing a file of name pidFileName * @param pidFilename name of the file containing the pid of the process to stop * * @return the process id (pid) contained within the pidFile * * @throws FileNotFoundException if the specified file name is not found within the directory * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer * @throws IllegalStateException if dir is not an existing directory * @throws IOException if an I/O error occurs * @throws NumberFormatException if the pid file does not contain a parsable integer */ private static int readPid(final File directory, final String pidFilename) throws IOException { if (!directory.isDirectory() && directory.exists()) { throw new IllegalArgumentException("Argument '" + directory + "' must be an existing directory!"); } final File[] files = directory.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String filename) { return filename.equals(pidFilename); } }); if (files.length == 0) { throw new FileNotFoundException("Unable to find PID file '" + pidFilename + "' in directory " + directory); } return readPid(files[0]); }