@Test public void shouldParseOneCharacterTags() throws IOException { final String LOG = "c6963a7ea2753672325502d342e653700be550a8:1377876557:tag: z:\n" + "c23e82b612acd5e947c164114377578116f6d298:1163621273::\n"; final byte[] LOG_BYTES = LOG.getBytes(StandardCharsets.UTF_8); ByteArrayInputStream bytesIn = new ByteArrayInputStream(LOG_BYTES); TreeSet<TagEntry> tagList = new TreeSet<>(); GitTagParser parser = new GitTagParser(tagList); parser.processStream(bytesIn); long countLF = LOG.chars().filter(ch -> ch == '\n').count(); assertEquals("size should == LF count - 1", countLF - 1, tagList.size()); }
@Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); @Override void processStream(InputStream input); }
GitTagParser implements Executor.StreamHandler { @Override public void processStream(InputStream input) throws IOException { ArrayList<String> tagNames = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(GitRepository.newLogReader(input))) { String line; while ((line = reader.readLine()) != null) { String originalLine = line; String hash; Date date; int i; if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %H: {0}", originalLine); continue; } hash = line.substring(0, i); line = line.substring(i + 1); if ((i = line.indexOf(":")) == -1) { LOGGER.log(Level.WARNING, "Bad tags log for %at: {0}", originalLine); continue; } String timestamp = line.substring(0, i); line = line.substring(i + 1); date = new Date((long) (Integer.parseInt(timestamp)) * 1000); tagNames.clear(); Matcher m = PRETTY_TAG_MATCHER.matcher(line); while (m.find()) { tagNames.add(m.group(1)); } if (!tagNames.isEmpty()) { String joinedTagNames = String.join(TAGS_SEPARATOR, tagNames); GitTagEntry tagEntry = new GitTagEntry(hash, date, joinedTagNames); entries.add(tagEntry); } } } } GitTagParser(TreeSet<TagEntry> entries); @Override void processStream(InputStream input);  }