List of usage examples for org.apache.http.message HeaderGroup setHeaders
public void setHeaders(Header[] headerArr)
From source file:it.unimi.di.law.warc.io.AbstractWarcReader_NYU.java
protected WarcRecord read(final boolean consecutive) throws IOException { if (consecutive && this.payload != null) { this.payload.consume(); this.payload = null; this.line.clear(); // check WARC version if (!(this.version.getMajor() == 0 && this.version.getMinor() == 18)) { this.buffer.readLine(this.line); this.buffer.readLine(this.line); } else {//w w w .ja v a 2 s . c o m if (!this.skip) { this.buffer.readLine(this.line); this.skip = true; } } if (line.length() != 0) throw new WarcFormatException("Missing CRLFs at WARC record end, got \"" + line + "\""); this.line.clear(); } // first header line this.version = parseHead(); if (this.version == null) return null; if (VERSION && (this.version.getMajor() != 1 || this.version.getMinor() != 0)) throw new IllegalArgumentException("Unsupported WARC version " + this.version); // rest of headers final HeaderGroup warcHeaders = new HeaderGroup(); try { warcHeaders.setHeaders(AbstractMessageParser.parseHeaders(this.buffer, -1, -1, null)); } catch (HttpException e) { throw new WarcFormatException("Can't parse WARC headers", e); } // payload final Header payloadLengthHeader = WarcHeader.getFirstHeader(warcHeaders, WarcHeader.Name.CONTENT_LENGTH); if (payloadLengthHeader == null) throw new WarcFormatException("Missing 'Content-Length' WARC header"); long payloadLength = -1; try { payloadLength = Long.parseLong(payloadLengthHeader.getValue()); } catch (NumberFormatException e) { throw new WarcFormatException( "Can't parse 'Content-Length' WARC header (is \"" + payloadLengthHeader.getValue() + "\")", e); } this.payload = new BoundSessionInputBuffer(this.buffer, payloadLength); return AbstractWarcRecord.fromPayload(warcHeaders, this.payload); }