01: package pygmy.nntp;
02:
03: import pygmy.core.Response;
04:
05: import java.io.*;
06:
07: public class NntpResponse extends Response {
08:
09: NntpOutputStream output;
10:
11: public NntpResponse(OutputStream output) {
12: this .output = new NntpOutputStream(output);
13: }
14:
15: public NntpOutputStream getOutputStream() {
16: return output;
17: }
18:
19: public void sendResponse(int code, String[] params)
20: throws IOException {
21: StringBuffer buffer = new StringBuffer();
22: buffer.append(code);
23: if (params != null) {
24: for (int i = 0; i < params.length; i++) {
25: buffer.append(" ");
26: buffer.append(params[i]);
27: }
28: }
29: output.println(buffer.toString());
30: output.flush();
31: }
32:
33: public void sendResponse(int code, String param) throws IOException {
34: sendResponse(code, new String[] { param });
35: }
36:
37: public void respondHello(String client) throws IOException {
38: sendResponse(200, client + " news server ready - posting ok.");
39: }
40:
41: public void respondHelloNoPosting(String client) throws IOException {
42: sendResponse(201, client
43: + " news server ready - no posting allowed.");
44: }
45:
46: // public static void main(String[] args) throws IOException {
47: // ByteArrayOutputStream baos = new ByteArrayOutputStream();
48: // NntpResponse response = new NntpResponse( new InternetOutputStream( baos ) );
49: //
50: // response.sendText("Foo bar" + Http.CRLF + ".You are the dude" + Http.CRLF + ".");
51: //
52: // System.out.print( baos.toString("ASCII") );
53: // NntpRequest request = new NntpRequest( new Properties(), new InternetInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) );
54: // System.out.print( request.readText() );
55: // baos.reset();
56: // response.sendText("This is retarded. Why do they do this to me.");
57: // System.out.print( baos.toString("ASCII") );
58: // request = new NntpRequest( new Properties(),new InternetInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) );
59: // System.out.print( request.readText() );
60: // }
61: }
|