{
if (file.getLength() > prefixFileMaxSize) {
throw new InvalidInputException("Prefix file size exceeds maximum allowed size (" + prefixFileMaxSize
+ "), refusing to load it.");
}
Closer closer = Closer.create();
try {
final BufferedReader reader =
closer.register(new BufferedReader(new InputStreamReader(file.getInputStream(), CHARSET)));
final ArrayList<String> entries = new ArrayList<String>();
String line = reader.readLine();
if (!MAGIC.equals(line) && !LEGACY_MAGIC.equals(line) && !UNSUPPORTED.equals(line)) {
throw new InvalidInputException("Prefix file does not start with expected \"" + MAGIC
+ "\" header, refusing to load the file.");
}
while (line != null) {
// check for unsupported. Before 2.7.0 it needed to be on 1st line, now it is obeyed if found on any
// line, as Nexus 2.7.0+ will have it AFTER headers, whereas older Nexuses had it BEFORE headers (on 1st
// line)
if (UNSUPPORTED.equals(line)) {
return RESULT_UNSUPPORTED;
}
// trim
line = line.trim();
if (!line.startsWith("#") && line.length() > 0) {
// line length
if (line.length() > prefixFileMaxLineLength) {
throw new InvalidInputException("Prefix file contains line longer than allowed ("
+ prefixFileMaxLineLength + " characters), refusing to load the file.");
}
// line should be ASCII
if (!CharMatcher.ASCII.matchesAllOf(line)) {
throw new InvalidInputException(
"Prefix file contains non-ASCII characters, refusing to load the file.");
}
// line should be actually a bit less than ASCII, filtering most certain characters
if (line.contains(":") || line.contains("<") || line.contains(">")) {
throw new InvalidInputException(
"Prefix file contains forbidden characters (colon, less or greater signs), refusing to load the file.");
}
// Igor's find command makes path like "./org/apache/"
while (line.startsWith(".")) {
line = line.substring(1);
}
// win file separators? Highly unlikely but still...
line = line.replace('\\', '/');
// normalization
entries.add(pathFrom(elementsOf(line)));
}
line = reader.readLine();
// dump big files
if (entries.size() > prefixFileMaxEntryCount) {
throw new InvalidInputException("Prefix file entry count exceeds maximum allowed count ("
+ prefixFileMaxEntryCount + "), refusing to load it.");
}
}
return new Result()
{
@Override
public boolean supported() {
return true;
}
@Override
public List<String> entries() {
return entries;
}
};
}
finally {
closer.close();
}
}