Revision 1788
Added by Matt Jones over 20 years ago
MetacatClient.java | ||
---|---|---|
35 | 35 |
import java.util.Properties; |
36 | 36 |
|
37 | 37 |
import edu.ucsb.nceas.utilities.HttpMessage; |
38 |
import edu.ucsb.nceas.utilities.IOUtil; |
|
38 | 39 |
|
40 |
|
|
39 | 41 |
/** |
40 | 42 |
* This interface provides methods for initializing and logging in to a |
41 | 43 |
* Metacat server, and then querying, reading, transforming, inserting, |
... | ... | |
154 | 156 |
{ |
155 | 157 |
Reader reader = null; |
156 | 158 |
String query = null; |
157 |
try |
|
158 |
{ |
|
159 |
query = readerToString(xmlQuery); |
|
160 |
} |
|
161 |
catch (IOException ioE) |
|
162 |
{ |
|
159 |
try { |
|
160 |
query = IOUtil.getAsString(xmlQuery, true); |
|
161 |
} catch (IOException ioE) { |
|
163 | 162 |
throw ioE; |
164 | 163 |
} |
165 | 164 |
|
... | ... | |
315 | 314 |
} |
316 | 315 |
return response; |
317 | 316 |
} |
318 |
/** |
|
319 |
* Utility method to convert a reader to a String. |
|
320 |
* |
|
321 |
* @param reader the Reader to be converted |
|
322 |
* @return a String representation fo the data read |
|
323 |
*/ |
|
324 |
private String readerToString(Reader reader) throws IOException |
|
325 |
{ |
|
326 |
String response = null; |
|
327 |
|
|
328 |
try { |
|
329 |
StringWriter sw = new StringWriter(); |
|
330 |
int len; |
|
331 |
char[] characters = new char[512]; |
|
332 |
while ((len = reader.read(characters, 0, 512)) != -1) { |
|
333 |
sw.write(characters, 0, len); |
|
334 |
} |
|
335 |
response = sw.toString(); |
|
336 |
sw.close(); |
|
337 |
reader.close(); |
|
338 |
} catch (IOException e) { |
|
339 |
throw e; |
|
340 |
} |
|
341 |
return response; |
|
342 |
} |
|
343 |
|
|
344 | 317 |
} |
Also available in: Unified diff
Refactored to use IOUtil routines. Reformatted for within-file consistency.