|
23 | 23 | public final class FetchReader { |
24 | 24 | private static final Logger logger = LoggerFactory.getLogger(FetchReader.class); |
25 | 25 | private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle"); |
| 26 | + private static final String FETCH_LINE_REGEX = ".*[ \t]*(\\d*|-)[ \t]*.*"; |
26 | 27 |
|
27 | 28 | private FetchReader(){ |
28 | 29 | //intentionally left empty |
@@ -51,14 +52,19 @@ public static List<FetchItem> readFetch(final Path fetchFile, final Charset enco |
51 | 52 | long length = 0; |
52 | 53 | URL url = null; |
53 | 54 | while(line != null){ |
54 | | - parts = line.split("\\s+", 3); |
55 | | - final Path path = TagFileReader.createFileFromManifest(bagRootDir, parts[2]); |
56 | | - length = parts[1].equals("-") ? -1 : Long.decode(parts[1]); |
57 | | - url = new URL(parts[0]); |
58 | | - |
59 | | - logger.debug(messages.getString("read_fetch_file_line"), url, length, parts[2], fetchFile); |
60 | | - final FetchItem itemToFetch = new FetchItem(url, length, path); |
61 | | - itemsToFetch.add(itemToFetch); |
| 55 | + if(line.matches(FETCH_LINE_REGEX) && !line.matches("\\s*")){ |
| 56 | + parts = line.split("\\s+", 3); |
| 57 | + final Path path = TagFileReader.createFileFromManifest(bagRootDir, parts[2]); |
| 58 | + length = parts[1].equals("-") ? -1 : Long.decode(parts[1]); |
| 59 | + url = new URL(parts[0]); |
| 60 | + |
| 61 | + logger.debug(messages.getString("read_fetch_file_line"), url, length, parts[2], fetchFile); |
| 62 | + final FetchItem itemToFetch = new FetchItem(url, length, path); |
| 63 | + itemsToFetch.add(itemToFetch); |
| 64 | + } |
| 65 | + else{ |
| 66 | + throw new InvalidBagitFileFormatException(messages.getString("invalid_fetch_file_line_error").replace("{}", line)); |
| 67 | + } |
62 | 68 |
|
63 | 69 | line = reader.readLine(); |
64 | 70 | } |
|
0 commit comments