Methods Summary |
---|
void | addArticle(java.lang.String articleID, java.util.Properties prop)Add the article information to the repository.
if ( articleID == null ) {
articleID = generateArticleID();
}
FileOutputStream fout = null;
try {
fout = new FileOutputStream(getFileFromID(articleID));
prop.store(fout,new Date().toString());
} finally {
if (fout != null) {
fout.close();
}
}
|
java.lang.String | generateArticleID()Generate a new article ID for use in the repository.
int idx = Math.abs(counter++);
StringBuffer idBuffer =
new StringBuffer(256)
.append("<")
.append(Thread.currentThread().hashCode())
.append(".")
.append(System.currentTimeMillis())
.append(".")
.append(idx)
.append("@")
.append(articleIDDomainSuffix)
.append(">");
return idBuffer.toString();
|
NNTPArticle | getArticle(NNTPRepository repo, java.lang.String id)Get the article from the NNTP respository with the specified id.
File f = getFileFromID(id);
if ( f.exists() == false ) {
return null;
}
FileInputStream fin = null;
Properties prop = new Properties();
try {
fin = new FileInputStream(f);
prop.load(fin);
} finally {
if (fin != null) {
fin.close();
}
}
Enumeration enumeration = prop.keys();
NNTPArticle article = null;
while ( article == null && enumeration.hasMoreElements() ) {
String groupName = (String)enumeration.nextElement();
int number = Integer.parseInt(prop.getProperty(groupName));
NNTPGroup group = repo.getGroup(groupName);
if ( group != null ) {
article = group.getArticle(number);
}
}
return article;
|
java.io.File | getFileFromID(java.lang.String articleID)Returns the file in the repository corresponding to the specified
article ID.
String b64Id;
try {
b64Id = removeCRLF(Base64.encodeAsString(articleID));
} catch (Exception e) {
throw new RuntimeException("This shouldn't happen: " + e);
}
return new File(root, b64Id);
|
boolean | isExists(java.lang.String articleID)Returns whether the article ID is in the repository
return ( articleID == null ) ? false : getFileFromID(articleID).exists();
|
private static java.lang.String | removeCRLF(java.lang.String str)the base64 encode from javax.mail.internet.MimeUtility adds line
feeds to the encoded stream. This removes them, since we will
use the String as a filename.
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c != '\r" && c != '\n") {
buffer.append(c);
}
}
return buffer.toString();
|