Methods Summary |
---|
private java.lang.String | cleanHeader(java.lang.String field)Strips out newlines and tabs, converting them to spaces.
rfc2980: 2.8 XOVER requires newline and tab to be converted to spaces
if ( field == null )
field = "";
StringBuffer sb = new StringBuffer(field);
for( int i=0 ; i<sb.length() ; i++ ) {
char c = sb.charAt(i);
if( (c=='\n") || (c=='\t") || (c=='\r")) {
sb.setCharAt(i, ' ");
}
}
return sb.toString();
|
public int | getArticleNumber()
return Integer.parseInt(articleFile.getName());
|
public NNTPGroup | getGroup()
return group;
|
public java.lang.String | getHeader(java.lang.String header)
try {
FileInputStream fin = new FileInputStream(articleFile);
InternetHeaders hdr = new InternetHeaders(fin);
fin.close();
return hdr.getHeader(header,null);
} catch(Exception ex) {
throw new NNTPException(ex);
}
|
public java.lang.String | getUniqueID()
FileInputStream fin = null;
try {
fin = new FileInputStream(articleFile);
InternetHeaders headers = new InternetHeaders(fin);
String[] idheader = headers.getHeader("Message-Id");
fin.close();
return ( idheader.length > 0 ) ? idheader[0] : null;
} catch(Exception ex) {
throw new NNTPException(ex);
} finally {
IOUtil.shutdownStream(fin);
}
|
public void | writeArticle(java.io.OutputStream out)
FileInputStream fileStream = null;
try {
fileStream = new FileInputStream(articleFile);
byte[] readBuffer = new byte[1024];
int read = 0;
while ((read = fileStream.read(readBuffer)) > 0) {
out.write(readBuffer, 0, read);
}
} catch(IOException ex) {
throw new NNTPException(ex);
} finally {
if (fileStream != null) {
try {
fileStream.close();
} catch (IOException ioe) {
// Ignored
}
}
}
|
public void | writeBody(java.io.OutputStream out)
FileInputStream fileStream = null;
try {
fileStream = new FileInputStream(articleFile);
MailHeaders headers = new MailHeaders(fileStream);
byte[] readBuffer = new byte[1024];
int read = 0;
while ((read = fileStream.read(readBuffer)) > 0) {
out.write(readBuffer, 0, read);
}
} catch(Exception ex) {
throw new NNTPException(ex);
} finally {
if (fileStream != null) {
try {
fileStream.close();
} catch (IOException ioe) {
// Ignored
}
}
}
|
public void | writeHead(java.io.OutputStream out)
FileInputStream fileStream = null;
try {
fileStream = new FileInputStream(articleFile);
MailHeaders headers = new MailHeaders(fileStream);
byte[] headerBuffer = headers.toByteArray();
int headerBufferLength = headerBuffer.length;
// Write the headers excluding the final CRLF pair
if (headerBufferLength > 2) {
out.write(headerBuffer, 0, (headerBufferLength - 2));
}
} catch(Exception ex) {
throw new NNTPException(ex);
} finally {
if (fileStream != null) {
try {
fileStream.close();
} catch (IOException ioe) {
// Ignored
}
}
}
|
public void | writeOverview(java.io.OutputStream out)
FileInputStream fileStream = null;
try {
fileStream = new FileInputStream(articleFile);
InternetHeaders hdr = new InternetHeaders(fileStream);
String subject = hdr.getHeader("Subject",null);
String author = hdr.getHeader("From",null);
String date = hdr.getHeader("Date",null);
String msgId = hdr.getHeader("Message-Id",null);
String references = hdr.getHeader("References",null);
long byteCount = articleFile.length();
// get line count, if not set, count the lines
String lineCount = hdr.getHeader("Lines",null);
if (lineCount == null) {
BufferedReader rdr = new BufferedReader(new FileReader(fileStream.getFD()));
int lines = 0;
while (rdr.readLine() != null) {
lines++;
}
lineCount = Integer.toString(lines);
rdr.close();
}
StringBuffer line=new StringBuffer(256)
.append(getArticleNumber()) .append("\t")
.append(cleanHeader(subject)) .append("\t")
.append(cleanHeader(author)) .append("\t")
.append(cleanHeader(date)) .append("\t")
.append(cleanHeader(msgId)) .append("\t")
.append(cleanHeader(references)) .append("\t")
.append(byteCount) .append("\t")
.append(lineCount).append("\r\n");
String lineString = line.toString();
out.write(lineString.getBytes("ASCII"));
} catch(Exception ex) {
throw new NNTPException(ex);
} finally {
if (fileStream != null) {
try {
fileStream.close();
} catch (IOException ioe) {
// Ignored
}
}
}
|