aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/test/mock/GCBase.java
blob: 328c993a4f2ca6197038b55afe9a95ad9d31f974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cgeo.geocaching.test.mock;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import cgeo.geocaching.ICache;
import cgeo.geocaching.cgBase;

public abstract class GCBase implements ICache {

	/* 
	 * The data for the caches can be generated by entering the url
	 * http://www.geocaching.com/seek/cache_details.aspx?log=y&wp=GCxxxx&numlogs=35&decrypt=y
	 * into a browser and saving the file 
	 */
	@Override
	public String getData() {
		try {
			InputStream is = this.getClass().getResourceAsStream("/cgeo/geocaching/test/mock/"+getGeocode()+".html");
			ByteArrayOutputStream buffer = new ByteArrayOutputStream();

			int nRead;
			byte[] data = new byte[16384];

			while ((nRead = is.read(data, 0, data.length)) != -1) {
				buffer.write(data, 0, nRead);
			}

			buffer.flush();
			StringBuffer sb = new StringBuffer(buffer.toString());
			cgBase.replaceWhitespace(sb);
			return sb.toString();

		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
		
	}


}