1
2
3 package org.galagosearch.core.parse;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.IOException;
7 import java.io.ObjectInputStream;
8 import org.galagosearch.core.types.KeyValuePair;
9 import org.galagosearch.tupleflow.InputClass;
10 import org.galagosearch.tupleflow.OutputClass;
11 import org.galagosearch.tupleflow.StandardStep;
12 import org.galagosearch.tupleflow.execution.Verified;
13
14 /***
15 * <p>This is used in conjunction with DocumentToKeyValuePair. Since Document
16 * is not a real Galago type, it needs to be converted to a KeyValuePair in order
17 * to be passed between stages (or to a Sorter).</p>
18 *
19 * @author trevor
20 */
21 @Verified
22 @InputClass(className = "org.galagosearch.core.types.KeyValuePair")
23 @OutputClass(className = "org.galagosearch.core.parse.Document")
24 public class KeyValuePairToDocument extends StandardStep<KeyValuePair, Document> {
25 @Override
26 public void process(KeyValuePair object) throws IOException {
27 ByteArrayInputStream stream = new ByteArrayInputStream(object.value);
28 ObjectInputStream input = new ObjectInputStream(stream);
29 Document document;
30 try {
31 document = (Document) input.readObject();
32 } catch (ClassNotFoundException ex) {
33 IOException e = new IOException("Expected to find a serialized document here, " +
34 "but found something else instead.");
35 e.initCause(ex);
36 throw e;
37 }
38
39 processor.process(document);
40 }
41 }