1 |
/* |
/* |
2 |
* $Id$ |
* PostStream.java |
3 |
* Copyright (C) 2002, 2003 The free Software Foundation |
* Copyright (C) 2002, 2003 The free Software Foundation |
4 |
* |
* |
5 |
* This file is part of GNU inetlib, a library. |
* This file is part of GNU inetlib, a library. |
46 |
* A stream to which article contents should be written. |
* A stream to which article contents should be written. |
47 |
* |
* |
48 |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
|
* @version $Revision$ $Date$ |
|
49 |
*/ |
*/ |
50 |
public final class PostStream extends FilterOutputStream |
public final class PostStream |
51 |
|
extends FilterOutputStream |
52 |
{ |
{ |
53 |
|
|
54 |
NNTPConnection connection; |
NNTPConnection connection; |
55 |
boolean isTakethis; |
boolean isTakethis; |
56 |
byte last; |
byte last; |
57 |
|
|
58 |
PostStream (NNTPConnection connection, boolean isTakethis) |
PostStream(NNTPConnection connection, boolean isTakethis) |
59 |
{ |
{ |
60 |
super (connection.out); |
super(connection.out); |
61 |
this.connection = connection; |
this.connection = connection; |
62 |
this.isTakethis = isTakethis; |
this.isTakethis = isTakethis; |
63 |
} |
} |
64 |
|
|
65 |
public void write (int c) throws IOException |
public void write(int c) |
66 |
|
throws IOException |
67 |
{ |
{ |
68 |
super.write (c); |
super.write(c); |
69 |
last = (byte) c; |
last = (byte) c; |
70 |
} |
} |
71 |
|
|
72 |
public void write (byte[] bytes, int pos, int len) throws IOException |
public void write(byte[] bytes) |
73 |
|
throws IOException |
74 |
{ |
{ |
75 |
super.write (bytes, pos, len); |
write(bytes, 0, bytes.length); |
76 |
if (len > 0) |
} |
77 |
|
|
78 |
|
public void write(byte[] bytes, int pos, int len) |
79 |
|
throws IOException |
80 |
|
{ |
81 |
|
super.write(bytes, pos, len); |
82 |
|
if(len > 0) |
83 |
{ |
{ |
84 |
last = bytes[pos + len - 1]; |
last = bytes[pos + len - 1]; |
85 |
} |
} |
89 |
* Close the stream. |
* Close the stream. |
90 |
* This calls NNTPConnection.postComplete(). |
* This calls NNTPConnection.postComplete(). |
91 |
*/ |
*/ |
92 |
public void close () throws IOException |
public void close() |
93 |
|
throws IOException |
94 |
{ |
{ |
95 |
if (last != 0x0d) |
if (last != 0x0d) |
96 |
{ |
{ |
97 |
// Need to add LF |
// Need to add LF |
98 |
write (0x0d); |
write(0x0d); |
99 |
} |
} |
100 |
if (isTakethis) |
if (isTakethis) |
101 |
{ |
{ |
102 |
connection.takethisComplete (); |
connection.takethisComplete(); |
103 |
} |
} |
104 |
else |
else |
105 |
{ |
{ |
106 |
connection.postComplete (); |
connection.postComplete(); |
107 |
} |
} |
108 |
} |
} |
109 |
|
|
110 |
} |
} |
111 |
|
|