1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.mapreduce.util;
|
2 |
|
|
|
3 |
|
|
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
4 |
|
|
|
5 |
|
|
import com.google.common.base.Function;
|
6 |
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
7 |
|
|
|
8 |
|
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
9 |
35127
|
claudio.at
|
import eu.dnetlib.data.transform.OafUtils;
|
10 |
26600
|
sandro.lab
|
|
11 |
35127
|
claudio.at
|
public class OafHbaseUtils extends OafUtils {
|
12 |
26600
|
sandro.lab
|
|
13 |
|
|
public static OafDecoder decode(final ImmutableBytesWritable oaf) {
|
14 |
|
|
return new OafDecoder(oaf.copyBytes());
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
public static Function<ImmutableBytesWritable, OafDecoder> decoder() {
|
18 |
|
|
return new Function<ImmutableBytesWritable, OafDecoder>() {
|
19 |
|
|
|
20 |
|
|
@Override
|
21 |
35127
|
claudio.at
|
public OafDecoder apply(final ImmutableBytesWritable input) {
|
22 |
26600
|
sandro.lab
|
return OafDecoder.decode(input.copyBytes());
|
23 |
|
|
}
|
24 |
|
|
};
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
public static Function<ImmutableBytesWritable, Oaf> oafDecoder() {
|
28 |
|
|
return new Function<ImmutableBytesWritable, Oaf>() {
|
29 |
|
|
|
30 |
|
|
@Override
|
31 |
35127
|
claudio.at
|
public Oaf apply(final ImmutableBytesWritable input) {
|
32 |
26600
|
sandro.lab
|
return parse(input);
|
33 |
|
|
}
|
34 |
|
|
};
|
35 |
|
|
}
|
36 |
|
|
|
37 |
35127
|
claudio.at
|
public static Oaf parse(final ImmutableBytesWritable input) {
|
38 |
26600
|
sandro.lab
|
try {
|
39 |
|
|
return Oaf.parseFrom(input.copyBytes());
|
40 |
35127
|
claudio.at
|
} catch (final InvalidProtocolBufferException e) {
|
41 |
26600
|
sandro.lab
|
throw new IllegalArgumentException(e);
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
}
|