Revision 4427 trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/OGCProtocolHandler.java
OGCProtocolHandler.java | ||
---|---|---|
50 | 50 |
import java.net.URL; |
51 | 51 |
import java.net.UnknownHostException; |
52 | 52 |
|
53 |
import com.devx.io.TempFileManager; |
|
54 |
|
|
55 | 53 |
public abstract class OGCProtocolHandler { |
56 | 54 |
/** |
57 | 55 |
* procotol handler name |
... | ... | |
119 | 117 |
this.version = version; |
120 | 118 |
} |
121 | 119 |
|
122 |
protected File downloadFile(URL url, String fileName) throws IOException,ConnectException, UnknownHostException{ |
|
123 |
File f = null; |
|
120 |
// /** |
|
121 |
// * @deprectated |
|
122 |
// * (temporarily) |
|
123 |
// */ |
|
124 |
// protected File downloadFile(URL url, String fileName) throws IOException,ConnectException, UnknownHostException{ |
|
125 |
// File f = null; |
|
126 |
// |
|
127 |
// try{ |
|
128 |
// f = TempFileManager.createTempFile(fileName, "tmp"); |
|
129 |
// System.out.println("downloading '"+url.toString()+"' to: "+f.getAbsolutePath()); |
|
130 |
// |
|
131 |
// f.deleteOnExit(); |
|
132 |
// |
|
133 |
// } catch (IOException io) { |
|
134 |
// io.printStackTrace(); |
|
135 |
// } |
|
136 |
// DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f))); |
|
137 |
// byte[] buffer = new byte[1024*256]; |
|
138 |
// InputStream is = url.openStream(); |
|
139 |
// long readed = 0; |
|
140 |
// for (int i = is.read(buffer); i>0; i = is.read(buffer)){ |
|
141 |
// dos.write(buffer, 0, i); |
|
142 |
// readed += i; |
|
143 |
// } |
|
144 |
// dos.close(); |
|
145 |
// /*if (!isNotAnException(f)) |
|
146 |
// // SI que es una excepci?n |
|
147 |
// throw new ServerErrorResponseException();*/ |
|
148 |
// return f; |
|
149 |
// } |
|
124 | 150 |
|
125 |
try{ |
|
126 |
f = TempFileManager.createTempFile(fileName, "tmp"); |
|
127 |
System.out.println("downloading '"+url.toString()+"' to: "+f.getAbsolutePath()); |
|
128 |
|
|
129 |
f.deleteOnExit(); |
|
130 |
|
|
131 |
} catch (IOException io) { |
|
132 |
io.printStackTrace(); |
|
133 |
} |
|
134 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f))); |
|
135 |
byte[] buffer = new byte[1024*256]; |
|
136 |
InputStream is = url.openStream(); |
|
137 |
long readed = 0; |
|
138 |
for (int i = is.read(buffer); i>0; i = is.read(buffer)){ |
|
139 |
dos.write(buffer, 0, i); |
|
140 |
readed += i; |
|
141 |
} |
|
142 |
dos.close(); |
|
143 |
/*if (!isNotAnException(f)) |
|
144 |
// SI que es una excepci?n |
|
145 |
throw new ServerErrorResponseException();*/ |
|
146 |
return f; |
|
147 |
} |
|
148 |
|
|
149 | 151 |
|
150 | 152 |
/** |
151 | 153 |
* parses the data retrieved by the Capabilities XML document |
Also available in: Unified diff