Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle timestamps that aren't 14 digits on ingest #95

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/outbackcdx/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private static String appendWbPostData(String urlkey, String surt) {
public static Capture fromCdxLine(String line, UrlCanonicalizer canonicalizer) {
String[] fields = line.split(" ");
Capture capture = new Capture();
capture.timestamp = Long.parseLong(fields[1]);
capture.timestamp = parseCdxTimestamp(fields[1]);
capture.original = fields[2];
capture.urlkey = appendWbPostData(fields[0], canonicalizer.surtCanonicalize(capture.original));
capture.mimetype = fields[3];
Expand Down Expand Up @@ -414,6 +414,26 @@ public static Capture fromCdxLine(String line, UrlCanonicalizer canonicalizer) {

return capture;
}

/**
* Convert a 14 digit CDX timestamp into a 64 bit integer (long). If the supplied string is too short, 0 will be
* appended to pad it out. If the supplied string is to long, an exception will be thrown.
* @param cdxTimestamp The CDX timestamp to convert
* @return A 64 bit integer representation of the supplied timestamp
* @throws IllegalArgumentException If the supplied timestamp exceeds 14 characters.
* @throws NumberFormatException If the supplied timestamp contains non-numeric characters.
*/
private static long parseCdxTimestamp(String cdxTimestamp) {
if (cdxTimestamp.length() < 14) {
log.log(Level.WARNING, "Padding timestamp shorter then 14 chars: " + cdxTimestamp);
cdxTimestamp = cdxTimestamp + PAD_TIMESTAMP.substring(cdxTimestamp.length());
}
if (cdxTimestamp.length() > 14) {
throw new IllegalArgumentException("CDX timestamp longer than 14 chars. Not supported");
}

return Long.parseLong(cdxTimestamp);
}

public Date date() {
return parseTimestamp(timestamp);
Expand Down