01: package org.openedit.sitesearch;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.InputStream;
05: import java.net.URL;
06: import java.net.URLConnection;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.openedit.links.Link;
11:
12: import com.openedit.util.OutputFiller;
13:
14: public class Content {
15: private static final Log log = LogFactory.getLog(Content.class);
16: protected Link fieldUrl;
17:
18: public Link getUrl() {
19: return fieldUrl;
20: }
21:
22: public void setUrl(Link inUrl) {
23: fieldUrl = inUrl;
24: }
25:
26: public byte[] getContent() throws Exception {
27: URL url = new URL(getUrl().getPath());
28: URLConnection connect = url.openConnection();
29: connect.connect();
30: if (connect.getContentLength() > 10000 * 1024) {
31: log.error(getUrl() + " is over 10 megs");
32: return null;
33: }
34: ByteArrayOutputStream out = new ByteArrayOutputStream();
35: InputStream in = connect.getInputStream();
36: try {
37: new OutputFiller().fill(in, out);
38: } finally {
39: in.close();
40: }
41: return out.toByteArray();
42: }
43:
44: }
|