Fix wrong handling of byte values > 127 in ArticleInputStream.
1.1 --- a/org/sonews/util/io/ArticleInputStream.java Wed Aug 12 17:25:46 2009 +0200
1.2 +++ b/org/sonews/util/io/ArticleInputStream.java Mon Aug 17 11:00:51 2009 +0200
1.3 @@ -32,8 +32,8 @@
1.4 public class ArticleInputStream extends InputStream
1.5 {
1.6
1.7 - private byte[] buffer;
1.8 - private int offset = 0;
1.9 + private byte[] buf;
1.10 + private int pos = 0;
1.11
1.12 public ArticleInputStream(final Article art)
1.13 throws IOException, UnsupportedEncodingException
1.14 @@ -43,19 +43,28 @@
1.15 out.write("\r\n\r\n".getBytes());
1.16 out.write(art.getBody()); // Without CRLF
1.17 out.flush();
1.18 - this.buffer = out.toByteArray();
1.19 + this.buf = out.toByteArray();
1.20 }
1.21
1.22 + /**
1.23 + * This method reads one byte from the stream. The <code>pos</code>
1.24 + * counter is advanced to the next byte to be read. The byte read is
1.25 + * returned as an int in the range of 0-255. If the stream position
1.26 + * is already at the end of the buffer, no byte is read and a -1 is
1.27 + * returned in order to indicate the end of the stream.
1.28 + *
1.29 + * @return The byte read, or -1 if end of stream
1.30 + */
1.31 @Override
1.32 - public int read()
1.33 + public synchronized int read()
1.34 {
1.35 - if(offset >= buffer.length)
1.36 + if(pos < buf.length)
1.37 {
1.38 - return -1;
1.39 + return ((int)buf[pos++]) & 0xFF;
1.40 }
1.41 else
1.42 {
1.43 - return buffer[offset++];
1.44 + return -1;
1.45 }
1.46 }
1.47