src/org/sonews/daemon/command/PostCommand.java
changeset 48 b78e77619152
parent 37 74139325d305
child 50 0bf10add82d9
     1.1 --- a/src/org/sonews/daemon/command/PostCommand.java	Sun Aug 29 18:17:37 2010 +0200
     1.2 +++ b/src/org/sonews/daemon/command/PostCommand.java	Sun Sep 11 15:05:04 2011 +0200
     1.3 @@ -15,7 +15,6 @@
     1.4   *   You should have received a copy of the GNU General Public License
     1.5   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     1.6   */
     1.7 -
     1.8  package org.sonews.daemon.command;
     1.9  
    1.10  import java.io.IOException;
    1.11 @@ -45,40 +44,35 @@
    1.12   * @author Christian Lins
    1.13   * @since sonews/0.5.0
    1.14   */
    1.15 -public class PostCommand implements Command
    1.16 -{
    1.17 +public class PostCommand implements Command {
    1.18  
    1.19  	private final Article article = new Article();
    1.20  	private int lineCount = 0;
    1.21  	private long bodySize = 0;
    1.22  	private InternetHeaders headers = null;
    1.23  	private long maxBodySize =
    1.24 -		Config.inst().get(Config.ARTICLE_MAXSIZE, 128) * 1024L; // Size in bytes
    1.25 +			Config.inst().get(Config.ARTICLE_MAXSIZE, 128) * 1024L; // Size in bytes
    1.26  	private PostState state = PostState.WaitForLineOne;
    1.27  	private final ByteArrayOutputStream bufBody = new ByteArrayOutputStream();
    1.28  	private final StringBuilder strHead = new StringBuilder();
    1.29  
    1.30  	@Override
    1.31 -	public String[] getSupportedCommandStrings()
    1.32 -	{
    1.33 -		return new String[] {"POST"};
    1.34 +	public String[] getSupportedCommandStrings() {
    1.35 +		return new String[]{"POST"};
    1.36  	}
    1.37  
    1.38  	@Override
    1.39 -	public boolean hasFinished()
    1.40 -	{
    1.41 +	public boolean hasFinished() {
    1.42  		return this.state == PostState.Finished;
    1.43  	}
    1.44  
    1.45  	@Override
    1.46 -	public String impliedCapability()
    1.47 -	{
    1.48 +	public String impliedCapability() {
    1.49  		return null;
    1.50  	}
    1.51  
    1.52  	@Override
    1.53 -	public boolean isStateful()
    1.54 -	{
    1.55 +	public boolean isStateful() {
    1.56  		return true;
    1.57  	}
    1.58  
    1.59 @@ -90,8 +84,7 @@
    1.60  	 */
    1.61  	@Override // TODO: Refactor this method to reduce complexity!
    1.62  	public void processLine(NNTPConnection conn, String line, byte[] raw)
    1.63 -		throws IOException, StorageBackendException
    1.64 -	{
    1.65 +			throws IOException, StorageBackendException {
    1.66  		switch (state) {
    1.67  			case WaitForLineOne: {
    1.68  				if (line.equalsIgnoreCase("POST")) {
    1.69 @@ -113,7 +106,7 @@
    1.70  					try {
    1.71  						// Parse the header using the InternetHeader class from JavaMail API
    1.72  						headers = new InternetHeaders(
    1.73 -							new ByteArrayInputStream(strHead.toString().trim().getBytes(conn.getCurrentCharset())));
    1.74 +								new ByteArrayInputStream(strHead.toString().trim().getBytes(conn.getCurrentCharset())));
    1.75  
    1.76  						// add the header entries for the article
    1.77  						article.setHeaders(headers);
    1.78 @@ -181,8 +174,7 @@
    1.79  	 * @param article
    1.80  	 */
    1.81  	private void controlMessage(NNTPConnection conn, Article article)
    1.82 -		throws IOException
    1.83 -	{
    1.84 +			throws IOException {
    1.85  		String[] ctrl = article.getHeader(Headers.CONTROL)[0].split(" ");
    1.86  		if (ctrl.length == 2) // "cancel <mid>"
    1.87  		{
    1.88 @@ -203,8 +195,7 @@
    1.89  	}
    1.90  
    1.91  	private void supersedeMessage(NNTPConnection conn, Article article)
    1.92 -		throws IOException
    1.93 -	{
    1.94 +			throws IOException {
    1.95  		try {
    1.96  			String oldMsg = article.getHeader(Headers.SUPERSEDES)[0];
    1.97  			StorageManager.current().delete(oldMsg);
    1.98 @@ -217,8 +208,7 @@
    1.99  	}
   1.100  
   1.101  	private void postArticle(NNTPConnection conn, Article article)
   1.102 -		throws IOException
   1.103 -	{
   1.104 +			throws IOException {
   1.105  		if (article.getHeader(Headers.CONTROL)[0].length() > 0) {
   1.106  			controlMessage(conn, article);
   1.107  		} else if (article.getHeader(Headers.SUPERSEDES)[0].length() > 0) {
   1.108 @@ -253,7 +243,7 @@
   1.109  
   1.110  								// Log this posting to statistics
   1.111  								Stats.getInstance().mailPosted(
   1.112 -									article.getHeader(Headers.NEWSGROUPS)[0]);
   1.113 +										article.getHeader(Headers.NEWSGROUPS)[0]);
   1.114  							}
   1.115  							success = true;
   1.116  						}