ACL: uživatel v Article bude jako User ne jen jako String.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package org.sonews.util.io;
20 import java.io.FilterInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
25 * Filter input stream for reading from SMTP (or NNTP or similar) socket
26 * where lines containing single dot have special meaning – end of message.
28 * @author František Kučera (frantovo.cz)
30 public class SMTPInputStream extends FilterInputStream {
32 public static final int CR = 0x0d;
33 public static final int LF = 0x0a;
34 public static final int DOT = 0x2e;
37 public SMTPInputStream(InputStream in) {
42 * @return one byte as expected
43 * or -2 if there was line with single dot (which means end of message)
47 public int read() throws IOException {
48 // read current character
49 int ch = super.read();
53 int next = super.read();
55 if (next == CR || next == LF) { // There should be CRLF, but we may accept also just LF or CR with missing LF. Or should we be more strict?
56 // <CRLF>.<CRLF> → end of current message
59 // <CRLF>.… → eat one dot and return next character
73 * @return See {@link FilterInputStream#read(byte[], int, int)} or -2 (then see {@link #read(byte[])})
77 public int read(byte[] buffer, int offset, int length) throws IOException {
79 throw new NullPointerException("Byte array should not be null.");
80 } else if ((offset < 0) || (offset > buffer.length) || (length < 0) || ((offset + length) > buffer.length) || ((offset + length) < 0)) {
81 throw new IndexOutOfBoundsException("Invalid offset or length.");
82 } else if (length == 0) {
88 if (ch == -1 || ch == -2) {
92 buffer[offset] = (byte) ch;
96 for (; readCounter < length; readCounter++) {
99 if (ch == -1 || ch == -2) {
103 if (buffer != null) {
104 buffer[offset + readCounter] = (byte) ch;