1
|
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
|
import eu.dnetlib.data.transform.OafUtils;
|
10
|
|
11
|
public class OafHbaseUtils extends OafUtils {
|
12
|
|
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
|
public OafDecoder apply(final ImmutableBytesWritable input) {
|
22
|
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
|
public Oaf apply(final ImmutableBytesWritable input) {
|
32
|
return parse(input);
|
33
|
}
|
34
|
};
|
35
|
}
|
36
|
|
37
|
public static Oaf parse(final ImmutableBytesWritable input) {
|
38
|
try {
|
39
|
return Oaf.parseFrom(input.copyBytes());
|
40
|
} catch (final InvalidProtocolBufferException e) {
|
41
|
throw new IllegalArgumentException(e);
|
42
|
}
|
43
|
}
|
44
|
|
45
|
}
|