}
else {
in = r.pbin;
}
Payload payload = null;
HttpHeader httpHeader = null;
if (ArcReaderFactory.isArcRecord(in)) {
r.arcReader = ArcReaderFactory.getReaderUncompressed();
r.arcReader.setUriProfile(UriProfile.RFC3986_ABS_16BIT_LAX);
r.arcReader.setBlockDigestEnabled(false);
r.arcReader.setPayloadDigestEnabled(false);
r.arcRecord = r.arcReader.getNextRecordFrom(in, offset);
if (r.arcRecord != null) {
payload = r.arcRecord.getPayload();
if (payload != null) {
httpHeader = r.arcRecord.getHttpHeader();
}
if (httpHeader != null) {
r.payloadStream = httpHeader.getPayloadInputStream();
r.length = httpHeader.payloadLength;
r.status = httpHeader.statusCode;
} else if (payload != null) {
r.payloadStream = payload.getInputStreamComplete();
r.length = payload.getTotalLength();
r.status = 200;
} else {
r.payloadStream = new ByteArrayInputStream(new byte[0]);
r.length = 0;
r.status = 200;
}
}
}
else if ( WarcReaderFactory.isWarcRecord(in) ) {
r.warcReader = WarcReaderFactory.getReaderUncompressed();
r.warcReader.setWarcTargetUriProfile(UriProfile.RFC3986_ABS_16BIT_LAX);
r.warcReader.setBlockDigestEnabled(false);
r.warcReader.setPayloadDigestEnabled(false);
r.warcRecord = r.warcReader.getNextRecordFrom(in, offset);
if (r.warcRecord != null) {
payload = r.warcRecord.getPayload();
if (payload != null) {
httpHeader = r.warcRecord.getHttpHeader();
}
if (httpHeader != null) {
r.payloadStream = httpHeader.getPayloadInputStream();
r.length = httpHeader.payloadLength;
r.status = httpHeader.statusCode;
} else if (payload != null) {
r.payloadStream = payload.getInputStreamComplete();
r.length = payload.getTotalLength();
r.status = 200;
} else {
r.payloadStream = new ByteArrayInputStream(new byte[0]);
r.length = 0;
r.status = 200;
}
}
}
else {
throw new ResourceNotAvailableException("Unknown archive record");
}
if (r.payloadStream == null) {
r.close();
r = null;
} else {
r.setInputStream(r.payloadStream);
r.headers = new Hashtable<String,String>();
if (httpHeader != null) {
Iterator<HeaderLine> headerLines = httpHeader.getHeaderList().iterator();
HeaderLine headerLine;
while (headerLines.hasNext()) {
headerLine = headerLines.next();
r.headers.put(headerLine.name.toLowerCase(), headerLine.value);
}