/**
* @param line
* @return SearchResult representation of input line
*/
public static SearchResult doAdapt(String line) {
SearchResult result = new SearchResult();
String[] tokens = line.split(" ");
if (tokens.length != 9) {
return null;
//throw new IllegalArgumentException("Need 9 columns("+line+")");
}
String url = tokens[0];
String captureDate = tokens[1];
String origHost = tokens[2];
String mimeType = tokens[3];
String httpResponseCode = tokens[4];
String md5Fragment = tokens[5];
String redirectUrl = tokens[6];
long compressedOffset = -1;
if(!tokens[7].equals("-")) {
compressedOffset = Long.parseLong(tokens[7]);
}
String arcFileName = tokens[8];
String origUrl = url;
if(!url.startsWith(WaybackConstants.DNS_URL_PREFIX)) {
try {
UURI uri = UURIFactory.getInstance(
WaybackConstants.HTTP_URL_PREFIX + url);
if(uri.getPort() != -1) {
origHost += ":" + uri.getPort();
}
origUrl = origHost + uri.getEscapedPathQuery();
} catch (URIException e) {
// TODO Stifle? throw an error?
e.printStackTrace();
return null;
}
}
result.put(WaybackConstants.RESULT_URL, origUrl);
result.put(WaybackConstants.RESULT_URL_KEY, url);
result.put(WaybackConstants.RESULT_CAPTURE_DATE, captureDate);
result.put(WaybackConstants.RESULT_ORIG_HOST, origHost);
result.put(WaybackConstants.RESULT_MIME_TYPE, mimeType);
result.put(WaybackConstants.RESULT_HTTP_CODE, httpResponseCode);
result.put(WaybackConstants.RESULT_MD5_DIGEST, md5Fragment);
result.put(WaybackConstants.RESULT_REDIRECT_URL, redirectUrl);
// HACKHACK:
result.put(WaybackConstants.RESULT_OFFSET, String.valueOf(compressedOffset));
result.put(WaybackConstants.RESULT_ARC_FILE, arcFileName);
return result;
}