Project

General

Profile

1
package eu.dnetlib.wds.collector.plugins;
2

    
3
import java.io.BufferedWriter;
4
import java.io.IOException;
5
import java.nio.charset.Charset;
6
import java.nio.file.FileSystems;
7
import java.nio.file.Files;
8
import java.nio.file.Path;
9

    
10
import org.junit.Test;
11

    
12
/**
13
 * Created by sandro on 5/27/16.
14
 */
15
public class CMRIteratorTest {
16

    
17
	final static String BASE_URL_PAGE = "https://cmr.earthdata.nasa.gov/search/collections.json?pretty=true&page_num=%d";
18

    
19
	@Test
20
	public void test() throws Exception {
21

    
22
		CMRIterator it = new CMRIterator();
23
		int i = 1;
24

    
25
		Charset charset = Charset.forName("UTF-8");
26

    
27
		Path file = FileSystems.getDefault().getPath("/tmp/out.json");
28
		try (BufferedWriter writer = Files.newBufferedWriter(file, charset)) {
29
			while (it.hasNext()) {
30

    
31
				final String s = it.next();
32
				writer.write(s, 0, s.length());
33
				writer.newLine();
34
				System.out.println("Writed  " + i++);
35
			}
36
			writer.close();
37

    
38
		} catch (IOException x) {
39
			System.err.format("IOException: %s%n", x);
40
		}
41

    
42
	}
43

    
44
}
    (1-1/1)