/**
* This abstract class bridges the OS-dependent implementations of the
* needed functionality for querying link counts.
* The particular implementation class is chosen during
* static initialization phase of the HardLink class.
* The "getter" methods construct shell command strings.
*/privatestaticabstractclassHardLinkCommandGetter {/**
* Get the command string to query the hardlink count of a file
*/abstract String[] linkCount(File file) throws IOException;
}
HardLinkCGUnix – Implementation of HardLinkCommandGetter class for Unix
/**
* Implementation of HardLinkCommandGetter class for Unix
*/privatestaticclassHardLinkCGUnixextendsHardLinkCommandGetter {privatestatic String[] getLinkCountCommand = {"stat","-c%h", null};
privatestaticsynchronizedvoidsetLinkCountCmdTemplate(String[] template) {
//May update this for specific unix variants, //after static initialization phase
getLinkCountCommand = template;
}
/*
* @see org.apache.hadoop.fs.HardLink.HardLinkCommandGetter#linkCount(java.io.File)
*/@Override
String[] linkCount(File file)
throws IOException {
String[] buf = new String[getLinkCountCommand.length];
System.arraycopy(getLinkCountCommand, 0, buf, 0,
getLinkCountCommand.length);
buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true);
return buf;
}
}
HardLinkCGUnix use "stat -c%h" to get the hard link count
HardLinkCommandGetter/** * This abstract class bridges the OS-dependent implementations of the * needed functionality for querying link counts. * The particular implementation class is chosen