Skip to content

Commit

Permalink
chore: Remove redundant file footer pattern noop regex (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfarrell authored and chaochenq committed Mar 5, 2018
1 parent 35bacf4 commit 0a3d7ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void getNewCurrentBuffer() {
private R buildRecord(int offset, int length) {
ByteBuffer data = ByteBuffers.getPartialView(currentBuffer, offset, length);

if (fileFooterPattern != null && fileFooterPattern.pattern() != FileFlow.NO_MATCH_REGEX.pattern()) {
if (fileFooterPattern != null) {
final Matcher fileFooterMatcher = fileFooterPattern.matcher(data.asCharBuffer());
if(fileFooterMatcher.matches()) {
stopParsing("End of file reached, file footer pattern matched");
Expand Down
4 changes: 1 addition & 3 deletions src/com/amazon/kinesis/streaming/agent/tailing/FileFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public abstract class FileFlow<R extends IRecord> extends Configuration {
public static final String DEFAULT_TRUNCATED_RECORD_TERMINATOR = String.valueOf(Constants.NEW_LINE);
public static final String CONVERSION_OPTION_KEY = "dataProcessingOptions";
public static final String FILE_FOOTER_PATTERN = "fileFooterPattern"; //If a line matches this pattern it stops processing the file

public static final Pattern NO_MATCH_REGEX = Pattern.compile("^\\b$"); //https://stackoverflow.com/questions/1723182/a-regex-that-will-never-be-matched-by-anything

@Getter protected final AgentContext agentContext;
@Getter protected final SourceFile sourceFile;
Expand Down Expand Up @@ -113,7 +111,7 @@ protected FileFlow(AgentContext context, Configuration config) {

String footerPattern = readString(FILE_FOOTER_PATTERN, null);

fileFooterPattern = Strings.isNullOrEmpty(footerPattern)? NO_MATCH_REGEX : Pattern.compile(footerPattern);
fileFooterPattern = Strings.isNullOrEmpty(footerPattern)? null : Pattern.compile(footerPattern);

String terminatorConfig = readString("truncatedRecordTerminator", DEFAULT_TRUNCATED_RECORD_TERMINATOR);
if (terminatorConfig == null || terminatorConfig.getBytes(StandardCharsets.UTF_8).length >= getMaxRecordSizeBytes()) {
Expand Down

0 comments on commit 0a3d7ee

Please sign in to comment.