Project

General

Profile

1
package eu.dnetlib.iis.core.examples.java;
2

    
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import java.util.HashMap;
7
import java.util.Map;
8

    
9
import org.apache.hadoop.conf.Configuration;
10
import org.apache.hadoop.fs.FileSystem;
11
import org.apache.hadoop.fs.Path;
12
import org.apache.oozie.util.IOUtils;
13

    
14
import eu.dnetlib.iis.core.java.PortBindings;
15
import eu.dnetlib.iis.core.java.Process;
16
import eu.dnetlib.iis.core.java.io.FileSystemPath;
17
import eu.dnetlib.iis.core.java.porttype.AnyPortType;
18
import eu.dnetlib.iis.core.java.porttype.PortType;
19

    
20

    
21
public class StopwordsProducer implements Process {
22
	
23
	private final static String stopwordsPort = "stopwords";
24

    
25
    @Override
26
	public Map<String, PortType> getInputPorts() {
27
		return new HashMap<String, PortType>();
28
	}
29
	
30
	@Override
31
	public Map<String, PortType> getOutputPorts() {
32
		return createOutputPorts();
33
	}
34

    
35
	private static HashMap<String, PortType> createOutputPorts(){
36
		HashMap<String, PortType> outputPorts = 
37
				new HashMap<String, PortType>();
38
		outputPorts.put(stopwordsPort, 
39
				new AnyPortType());
40
		return outputPorts;	
41
	}
42
	
43
	@Override
44
	public void run(PortBindings portBindings, Configuration conf,
45
			Map<String, String> parameters)	throws IOException{
46
		Map<String, Path> output = portBindings.getOutput();
47

    
48
        FileSystem fs = FileSystem.get(conf);
49
		InputStream inStream = IOUtils.getResourceAsStream("eu/dnetlib/iis/core/examples/data/stopwords.db", -1);
50
		OutputStream outStream = fs.create(new FileSystemPath(fs, output.get(stopwordsPort)).getPath());
51
		IOUtils.copyStream(inStream, outStream);
52
	}
53

    
54
}
(9-9/11)