+ private void writeArticles(Category cat, HttpServletResponse rp) {
+ String html;
+ List<Article> articles;
+
+ try {
+ articles = provider.getArticles(cat);
+ if (articles != null) {
+ html = HTML.toHTML(articles, cat);
+ rp.setContentType("text/html;charset=utf-8");
+ rp.getWriter().write(html);
+ rp.setCharacterEncoding("utf-8");
+ } else {
+ LOG.severe("writeArticles cannot retrieve any articles");
+ html = HTML.toHTML(new ArrayList<Article>(), cat);
+ rp.setContentType("text/html");
+ rp.getWriter().write(html);
+ }
+ } catch (IOException | IllegalArgumentException | FeedException e) {
+ LOG.log(Level.SEVERE, "writeArticles failure", e);
+ rp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ private void copy(InputStream in, Writer writer) throws IOException {
+ Reader r;
+ char[] buf;
+ int n;
+
+ buf = new char[1024];
+ r = new InputStreamReader(in);
+ while ( (n = r.read(buf, 0, buf.length)) != -1)
+ writer.write(buf, 0, n);
+ }
+