| Method from org.apache.nutch.protocol.Content Detail: |
public boolean equals(Object o) {
if (!(o instanceof Content)) {
return false;
}
Content that = (Content) o;
return this.url.equals(that.url) && this.base.equals(that.base)
&& Arrays.equals(this.getContent(), that.getContent())
&& this.contentType.equals(that.contentType)
&& this.metadata.equals(that.metadata);
}
|
public String getBaseUrl() {
return base;
}
The base url for relative links contained in the content.
Maybe be different from url if the request redirected. |
public byte[] getContent() {
return content;
}
The binary content retrieved. |
public String getContentType() {
return contentType;
}
The media type of the retrieved content. |
public Metadata getMetadata() {
return metadata;
}
Other protocol-specific data. |
public String getUrl() {
return url;
}
|
public static void main(String[] argv) throws Exception {
String usage = "Content (-local | -dfs < namenode:port >) recno segment";
if (argv.length < 3) {
System.out.println("usage:" + usage);
return;
}
Configuration conf = NutchConfiguration.create();
FileSystem fs = FileSystem.parseArgs(argv, 0, conf);
try {
int recno = Integer.parseInt(argv[0]);
String segment = argv[1];
Path file = new Path(segment, DIR_NAME);
System.out.println("Reading from file: " + file);
ArrayFile.Reader contents = new ArrayFile.Reader(fs, file.toString(),
conf);
Content content = new Content();
contents.get(recno, content);
System.out.println("Retrieved " + recno + " from file " + file);
System.out.println(content);
contents.close();
} finally {
fs.close();
}
}
|
public static Content read(DataInput in) throws IOException {
Content content = new Content();
content.readFields(in);
return content;
}
|
public final void readFields(DataInput in) throws IOException {
metadata.clear();
int sizeOrVersion = in.readInt();
if (sizeOrVersion < 0) { // version
version = sizeOrVersion;
switch (version) {
case VERSION:
url = Text.readString(in);
base = Text.readString(in);
content = new byte[in.readInt()];
in.readFully(content);
contentType = Text.readString(in);
metadata.readFields(in);
break;
default:
throw new VersionMismatchException((byte)VERSION, (byte)version);
}
} else { // size
byte[] compressed = new byte[sizeOrVersion];
in.readFully(compressed, 0, compressed.length);
ByteArrayInputStream deflated = new ByteArrayInputStream(compressed);
DataInput inflater =
new DataInputStream(new InflaterInputStream(deflated));
readFieldsCompressed(inflater);
}
}
|
public void setContent(byte[] content) {
this.content = content;
}
|
public void setContentType(String contentType) {
this.contentType = contentType;
}
|
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
Other protocol-specific data. |
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Version: " + version + "\n");
buffer.append("url: " + url + "\n");
buffer.append("base: " + base + "\n");
buffer.append("contentType: " + contentType + "\n");
buffer.append("metadata: " + metadata + "\n");
buffer.append("Content:\n");
buffer.append(new String(content)); // try default encoding
return buffer.toString();
}
|
public final void write(DataOutput out) throws IOException {
out.writeInt(VERSION);
Text.writeString(out, url); // write url
Text.writeString(out, base); // write base
out.writeInt(content.length); // write content
out.write(content);
Text.writeString(out, contentType); // write contentType
metadata.write(out); // write metadata
}
|