HardLink { public static int getLinkCount(File fileName) throws IOException { if (fileName == null) { throw new IOException( "invalid argument to getLinkCount: file name is null"); } if (!fileName.exists()) { throw new FileNotFoundException(fileName + " not found."); } String[] cmd = getHardLinkCommand.linkCount(fileName); String inpMsg = null; String errMsg = null; int exitValue = -1; BufferedReader in = null; ShellCommandExecutor shexec = new ShellCommandExecutor(cmd); try { shexec.execute(); in = new BufferedReader(new StringReader(shexec.getOutput())); inpMsg = in.readLine(); exitValue = shexec.getExitCode(); if (inpMsg == null || exitValue != 0) { throw createIOException(fileName, inpMsg, errMsg, exitValue, null); } if (Shell.SOLARIS) { String[] result = inpMsg.split("\\s+"); return Integer.parseInt(result[1]); } else { return Integer.parseInt(inpMsg); } } catch (ExitCodeException e) { inpMsg = shexec.getOutput(); errMsg = e.getMessage(); exitValue = e.getExitCode(); throw createIOException(fileName, inpMsg, errMsg, exitValue, e); } catch (NumberFormatException e) { throw createIOException(fileName, inpMsg, errMsg, exitValue, e); } finally { IOUtils.closeStream(in); } } HardLink(); static void createHardLink(File file, File linkName); static void createHardLinkMult(File parentDir, String[] fileBaseNames,
      File linkDir); static int getLinkCount(File fileName); final LinkStats linkStats; }
@Test public void testGetLinkCount() throws IOException { assertEquals(1, getLinkCount(x1)); assertEquals(1, getLinkCount(x2)); assertEquals(1, getLinkCount(x3)); }