01: package pygmy.nntp;
02:
03: import pygmy.core.InternetOutputStream;
04:
05: import java.io.IOException;
06: import java.io.OutputStream;
07:
08: public class NntpOutputStream extends InternetOutputStream {
09:
10: String seperator;
11:
12: public NntpOutputStream(OutputStream out) {
13: super (out);
14: }
15:
16: public void print(String text, int start, int length)
17: throws IOException {
18: if (text == null) {
19: super .print("null");
20: } else {
21: encodeText(text, start, length);
22: }
23: }
24:
25: private void encodeText(String text, int begin, int length)
26: throws IOException {
27: int tag = 0;
28: int start = begin;
29: while (start < length) {
30: tag = text.indexOf(seperator + ".", start);
31: if (tag < 0) {
32: tag = length;
33: write(text.getBytes(), start, tag - start);
34: } else {
35: tag += 3;
36: write(text.getBytes(), start, tag - start);
37: print(".");
38: }
39: start = tag;
40: }
41: }
42:
43: public void printEnd() throws IOException {
44: // println();
45: println(".");
46: flush();
47: }
48: }
|