1.1 --- a/src/org/sonews/util/io/ArticleInputStream.java Sun Aug 29 17:28:58 2010 +0200
1.2 +++ b/src/org/sonews/util/io/ArticleInputStream.java Mon Aug 30 00:20:06 2010 +0200
1.3 @@ -32,40 +32,36 @@
1.4 public class ArticleInputStream extends InputStream
1.5 {
1.6
1.7 - private byte[] buf;
1.8 - private int pos = 0;
1.9 -
1.10 - public ArticleInputStream(final Article art)
1.11 - throws IOException, UnsupportedEncodingException
1.12 - {
1.13 - final ByteArrayOutputStream out = new ByteArrayOutputStream();
1.14 - out.write(art.getHeaderSource().getBytes("UTF-8"));
1.15 - out.write("\r\n\r\n".getBytes());
1.16 - out.write(art.getBody()); // Without CRLF
1.17 - out.flush();
1.18 - this.buf = out.toByteArray();
1.19 - }
1.20 + private byte[] buf;
1.21 + private int pos = 0;
1.22
1.23 - /**
1.24 - * This method reads one byte from the stream. The <code>pos</code>
1.25 - * counter is advanced to the next byte to be read. The byte read is
1.26 - * returned as an int in the range of 0-255. If the stream position
1.27 - * is already at the end of the buffer, no byte is read and a -1 is
1.28 - * returned in order to indicate the end of the stream.
1.29 - *
1.30 - * @return The byte read, or -1 if end of stream
1.31 - */
1.32 - @Override
1.33 - public synchronized int read()
1.34 - {
1.35 - if(pos < buf.length)
1.36 - {
1.37 - return ((int)buf[pos++]) & 0xFF;
1.38 - }
1.39 - else
1.40 - {
1.41 - return -1;
1.42 - }
1.43 - }
1.44 -
1.45 + public ArticleInputStream(final Article art)
1.46 + throws IOException, UnsupportedEncodingException
1.47 + {
1.48 + final ByteArrayOutputStream out = new ByteArrayOutputStream();
1.49 + out.write(art.getHeaderSource().getBytes("UTF-8"));
1.50 + out.write("\r\n\r\n".getBytes());
1.51 + out.write(art.getBody()); // Without CRLF
1.52 + out.flush();
1.53 + this.buf = out.toByteArray();
1.54 + }
1.55 +
1.56 + /**
1.57 + * This method reads one byte from the stream. The <code>pos</code>
1.58 + * counter is advanced to the next byte to be read. The byte read is
1.59 + * returned as an int in the range of 0-255. If the stream position
1.60 + * is already at the end of the buffer, no byte is read and a -1 is
1.61 + * returned in order to indicate the end of the stream.
1.62 + *
1.63 + * @return The byte read, or -1 if end of stream
1.64 + */
1.65 + @Override
1.66 + public synchronized int read()
1.67 + {
1.68 + if (pos < buf.length) {
1.69 + return ((int) buf[pos++]) & 0xFF;
1.70 + } else {
1.71 + return -1;
1.72 + }
1.73 + }
1.74 }