Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 59986 invoked from network); 4 Apr 2009 19:06:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Apr 2009 19:06:07 -0000 Received: (qmail 75821 invoked by uid 500); 4 Apr 2009 19:06:06 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 75723 invoked by uid 500); 4 Apr 2009 19:06:06 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 75714 invoked by uid 99); 4 Apr 2009 19:06:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2009 19:06:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2009 19:05:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E0A1E2388A04; Sat, 4 Apr 2009 19:05:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r761988 - in /commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp: PostMessage.java post.java Date: Sat, 04 Apr 2009 19:05:38 -0000 To: commits@commons.apache.org From: rwinston@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090404190538.E0A1E2388A04@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rwinston Date: Sat Apr 4 19:05:38 2009 New Revision: 761988 URL: http://svn.apache.org/viewvc?rev=761988&view=rev Log: Rename Added: commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java (with props) Removed: commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/post.java Added: commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java?rev=761988&view=auto ============================================================================== --- commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java (added) +++ commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java Sat Apr 4 19:05:38 2009 @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package examples.nntp; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Writer; + +import org.apache.commons.net.PrintCommandListener; +import org.apache.commons.net.io.Util; +import org.apache.commons.net.nntp.NNTPClient; +import org.apache.commons.net.nntp.NNTPReply; +import org.apache.commons.net.nntp.SimpleNNTPHeader; + + +/*** + * This is an example program using the NNTP package to post an article + * to the specified newsgroup(s). It prompts you for header information and + * a filename to post. + *

+ ***/ + +public final class PostMessage +{ + + public final static void main(String[] args) + { + String from, subject, newsgroup, filename, server, organization; + String references; + BufferedReader stdin; + FileReader fileReader = null; + SimpleNNTPHeader header; + NNTPClient client; + + if (args.length < 1) + { + System.err.println("Usage: post newsserver"); + System.exit(1); + } + + server = args[0]; + + stdin = new BufferedReader(new InputStreamReader(System.in)); + + try + { + System.out.print("From: "); + System.out.flush(); + + from = stdin.readLine(); + + System.out.print("Subject: "); + System.out.flush(); + + subject = stdin.readLine(); + + header = new SimpleNNTPHeader(from, subject); + + System.out.print("Newsgroup: "); + System.out.flush(); + + newsgroup = stdin.readLine(); + header.addNewsgroup(newsgroup); + + while (true) + { + System.out.print("Additional Newsgroup : "); + System.out.flush(); + + // Of course you don't want to do this because readLine() may be null + newsgroup = stdin.readLine().trim(); + + if (newsgroup.length() == 0) + break; + + header.addNewsgroup(newsgroup); + } + + System.out.print("Organization: "); + System.out.flush(); + + organization = stdin.readLine(); + + System.out.print("References: "); + System.out.flush(); + + references = stdin.readLine(); + + if (organization != null && organization.length() > 0) + header.addHeaderField("Organization", organization); + + if (references != null && organization.length() > 0) + header.addHeaderField("References", references); + + header.addHeaderField("X-Newsreader", "NetComponents"); + + System.out.print("Filename: "); + System.out.flush(); + + filename = stdin.readLine(); + + try + { + fileReader = new FileReader(filename); + } + catch (FileNotFoundException e) + { + System.err.println("File not found. " + e.getMessage()); + System.exit(1); + } + + client = new NNTPClient(); + client.addProtocolCommandListener(new PrintCommandListener( + new PrintWriter(System.out))); + + client.connect(server); + + if (!NNTPReply.isPositiveCompletion(client.getReplyCode())) + { + client.disconnect(); + System.err.println("NNTP server refused connection."); + System.exit(1); + } + + if (client.isAllowedToPost()) + { + Writer writer = client.postArticle(); + + if (writer != null) + { + writer.write(header.toString()); + Util.copyReader(fileReader, writer); + writer.close(); + client.completePendingCommand(); + } + } + + fileReader.close(); + + client.logout(); + + client.disconnect(); + } + catch (IOException e) + { + e.printStackTrace(); + System.exit(1); + } + } +} + + Propchange: commons/proper/net/branches/NET_2_0/src/main/java/examples/nntp/PostMessage.java ------------------------------------------------------------------------------ svn:eol-style = native