Skip to content

Commit 18e7aeb

Browse files
author
Markus Jelsma
committed
NUTCH-3101 src/java/org/apache/nutch/crawl/Inlink.java
1 parent 3b6d2c6 commit 18e7aeb

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/java/org/apache/nutch/crawl/Inlink.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.io.DataInput;
2020
import java.io.DataOutput;
2121
import java.io.IOException;
22+
import java.util.Map.Entry;
2223

24+
import org.apache.hadoop.io.MapWritable;
2325
import org.apache.hadoop.io.Text;
2426
import org.apache.hadoop.io.Writable;
2527

@@ -28,6 +30,7 @@ public class Inlink implements Writable {
2830

2931
private String fromUrl;
3032
private String anchor;
33+
private MapWritable md = null;
3134

3235
public Inlink() {
3336
}
@@ -41,6 +44,13 @@ public Inlink(String fromUrl, String anchor) {
4144
public void readFields(DataInput in) throws IOException {
4245
fromUrl = Text.readString(in);
4346
anchor = Text.readString(in);
47+
boolean hasMD = in.readBoolean();
48+
if (hasMD) {
49+
md = new org.apache.hadoop.io.MapWritable();
50+
md.readFields(in);
51+
} else {
52+
md = null;
53+
}
4454
}
4555

4656
/**
@@ -51,12 +61,23 @@ public void readFields(DataInput in) throws IOException {
5161
public static void skip(DataInput in) throws IOException {
5262
Text.skip(in); // skip fromUrl
5363
Text.skip(in); // skip anchor
64+
boolean hasMD = in.readBoolean();
65+
if (hasMD) {
66+
MapWritable metadata = new org.apache.hadoop.io.MapWritable();
67+
metadata.readFields(in);
68+
}
5469
}
5570

5671
@Override
5772
public void write(DataOutput out) throws IOException {
5873
Text.writeString(out, fromUrl);
5974
Text.writeString(out, anchor);
75+
if (md != null && md.size() > 0) {
76+
out.writeBoolean(true);
77+
md.write(out);
78+
} else {
79+
out.writeBoolean(false);
80+
}
6081
}
6182

6283
public static Inlink read(DataInput in) throws IOException {
@@ -73,6 +94,14 @@ public String getAnchor() {
7394
return anchor;
7495
}
7596

97+
public MapWritable getMetadata() {
98+
return md;
99+
}
100+
101+
public void setMetadata(MapWritable md) {
102+
this.md = md;
103+
}
104+
76105
@Override
77106
public boolean equals(Object o) {
78107
if (!(o instanceof Inlink))
@@ -89,7 +118,16 @@ public int hashCode() {
89118

90119
@Override
91120
public String toString() {
92-
return "fromUrl: " + fromUrl + " anchor: " + anchor;
121+
StringBuilder buffer = new StringBuilder();
122+
if (md != null && !md.isEmpty()) {
123+
for (Entry<Writable, Writable> e : md.entrySet()) {
124+
buffer.append(" ");
125+
buffer.append(e.getKey());
126+
buffer.append(": ");
127+
buffer.append(e.getValue());
128+
}
129+
}
130+
131+
return "fromUrl: " + fromUrl + " anchor: " + anchor + " metadata: " + buffer.toString();
93132
}
94-
95133
}

0 commit comments

Comments
 (0)