filebot/source/net/filebot/hash/SfvFormat.java

45 lines
893 B
Java
Raw Normal View History

2014-04-19 02:30:29 -04:00
package net.filebot.hash;
import java.io.File;
import java.text.ParseException;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SfvFormat extends VerificationFormat {
2015-07-25 18:47:19 -04:00
@Override
public String format(String path, String hash) {
// e.g folder/file.txt 970E4EF1
return String.format("%s %s", path, hash);
}
2015-07-25 18:47:19 -04:00
/**
* Pattern used to parse the lines of a sfv file.
2015-07-25 18:47:19 -04:00
*
* <pre>
* Sample:
* folder/file.txt 970E4EF1
* | Group 1 | | Gr.2 |
* </pre>
*/
private final Pattern pattern = Pattern.compile("^(.+)\\s+(\\p{XDigit}{8})$");
2015-07-25 18:47:19 -04:00
@Override
public Entry<File, String> parseObject(String line) throws ParseException {
Matcher matcher = pattern.matcher(line);
2015-07-25 18:47:19 -04:00
if (!matcher.matches()) {
throw new ParseException("Illegal input pattern", 0);
}
2015-07-25 18:47:19 -04:00
return entry(matcher.group(1), matcher.group(2));
}
2015-07-25 18:47:19 -04:00
}