List of usage examples for org.apache.commons.io CopyUtils copy
public static void copy(InputStream input, Writer output, String encoding) throws IOException
InputStream
to chars on a Writer
, using the specified encoding. From source file:org.roosster.input.processors.XmlProcessor.java
/** * *///ww w.jav a2s . c o m public Entry[] process(URL url, InputStream stream, String encoding) throws Exception { if (url == null || stream == null || encoding == null || "".equals(encoding)) throw new IllegalArgumentException("No parameter is allowed to be null"); StringWriter strWriter = new StringWriter(); CopyUtils.copy(stream, strWriter, encoding); try { EntryList entryList = new EntryParser().parse(strWriter.toString(), encoding); return (Entry[]) entryList.toArray(new Entry[0]); } catch (ParseException ex1) { LOG.debug("Parsing Error while trying to parse EntryList: " + ex1.getMessage()); try { // TODO Try to determine, if the stream is a feed, and parses it, // if this is the case. If not, it just indexes it FeedParser parser = new FeedParser(); return parser.parse(url, strWriter.toString()); } catch (Exception ex) { throw new OperationException(ex); } } }