Fix all remaining checkstyle violations

This commit is contained in:
Trustin Lee 2012-01-15 02:08:31 +09:00
parent 0007e91923
commit 783a7e5f9a
7 changed files with 106 additions and 71 deletions

View File

@ -27,43 +27,43 @@ import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.handler.codec.http.QueryStringEncoder;
import io.netty.handler.codec.http.CookieEncoder;
import io.netty.handler.codec.http.DefaultHttpDataFactory;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.DiskAttribute;
import io.netty.handler.codec.http.DiskFileUpload;
import io.netty.handler.codec.http.InterfaceHttpData;
import io.netty.handler.codec.http.HttpPostRequestEncoder;
import io.netty.handler.codec.http.HttpDataFactory;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpPostRequestEncoder;
import io.netty.handler.codec.http.HttpPostRequestEncoder.ErrorDataEncoderException;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.HttpPostRequestEncoder.ErrorDataEncoderException;
import io.netty.handler.codec.http.InterfaceHttpData;
import io.netty.handler.codec.http.QueryStringEncoder;
/**
*/
public class HttpUploadClient {
private final String baseUri;
private final String filePath;
public HttpUploadClient(String baseUri, String filePath) {
this.baseUri = baseUri;
this.filePath = filePath;
}
public static void main(String[] args) {
if (args.length != 2) {
System.err.println(
"Usage: " + HttpUploadClient.class.getSimpleName() +
" baseURI Filepath");
return;
}
String baseURI = args[0];
public void run() {
String postSimple, postFile, get;
if (baseURI.endsWith("/")) {
postSimple = baseURI + "formpost";
postFile = baseURI + "formpostmultipart";
get = baseURI + "formget";
if (baseUri.endsWith("/")) {
postSimple = baseUri + "formpost";
postFile = baseUri + "formpostmultipart";
get = baseUri + "formget";
} else {
postSimple = baseURI + "/formpost";
postFile = baseURI + "/formpostmultipart";
get = baseURI + "/formget";
postSimple = baseUri + "/formpost";
postFile = baseUri + "/formpostmultipart";
get = baseUri + "/formget";
}
URI uriSimple;
try {
@ -97,7 +97,7 @@ public class HttpUploadClient {
System.err.println("Error: " + e.getMessage());
return;
}
File file = new File(args[1]);
File file = new File(filePath);
if (! file.canRead()) {
System.err.println("A correct path is needed");
return;
@ -135,7 +135,7 @@ public class HttpUploadClient {
return;
}
// Multipart Post form: factory used
formpostmultipart(bootstrap, host, port, uriFile, file, factory, headers, bodylist);
formpostmultipart(bootstrap, host, port, uriFile, factory, headers, bodylist);
// Shut down executor threads to exit.
bootstrap.releaseExternalResources();
@ -216,13 +216,7 @@ public class HttpUploadClient {
/**
* Standard post without multipart but already support on Factory (memory management)
* @param bootstrap
* @param host
* @param port
* @param uriSimple
* @param file
* @param factory
* @param headers
*
* @return the list of HttpData object (attribute and file) to be reused on next post
*/
private static List<InterfaceHttpData> formpost(ClientBootstrap bootstrap,
@ -311,17 +305,9 @@ public class HttpUploadClient {
/**
* Multipart example
* @param bootstrap
* @param host
* @param port
* @param uriFile
* @param file
* @param factory
* @param headers
* @param bodylist
*/
private static void formpostmultipart(ClientBootstrap bootstrap, String host, int port,
URI uriFile, File file, HttpDataFactory factory,
URI uriFile, HttpDataFactory factory,
List<Entry<String, String>> headers, List<InterfaceHttpData> bodylist) {
// XXX /formpostmultipart
// Start the connection attempt.
@ -390,12 +376,19 @@ public class HttpUploadClient {
channel.getCloseFuture().awaitUninterruptibly();
}
public static void main(String[] args) {
if (args.length != 2) {
System.err.println(
"Usage: " + HttpUploadClient.class.getSimpleName() +
" baseURI filePath");
return;
}
String baseUri = args[0];
String filePath = args[1];
new HttpUploadClient(baseUri, filePath).run();
}
// use to simulate a big TEXTAREA field in a form
private static final String textArea =

View File

@ -21,10 +21,15 @@ import java.util.concurrent.Executors;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
/**
*/
public class HttpUploadServer {
public static void main(String[] args) {
private final int port;
public HttpUploadServer(int port) {
this.port = port;
}
public void run() {
// Configure the server.
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
@ -35,6 +40,16 @@ public class HttpUploadServer {
bootstrap.setPipelineFactory(new HttpUploadServerPipelineFactory());
// Bind and start to accept incoming connections.
bootstrap.bind(new InetSocketAddress(8080));
bootstrap.bind(new InetSocketAddress(port));
}
public static void main(String[] args) {
int port;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
} else {
port = 8080;
}
new HttpUploadServer(port).run();
}
}

View File

@ -32,8 +32,15 @@ import java.util.concurrent.Executors;
*/
public class SctpClient {
public static void main(String[] args) throws Exception {
private final String host;
private final int port;
public SctpClient(String host, int port) {
this.host = host;
this.port = port;
}
public void run() {
// Configure the client.
ClientBootstrap bootstrap = new ClientBootstrap(
new SctpClientSocketChannelFactory(
@ -57,14 +64,31 @@ public class SctpClient {
bootstrap.setOption("sctpNoDelay", true);
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 2955), new InetSocketAddress("localhost", 2956));
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
// Wait until the connection is closed or the connection attempt fails.
future.getChannel().getCloseFuture().awaitUninterruptibly();
// Please check SctpClientHandler to see, how echo message is sent & received
// Please check SctpClientHandler to see, how echo message is sent & received
// Shut down thread pools to exit.
bootstrap.releaseExternalResources();
}
public static void main(String[] args) throws Exception {
// Print usage if no argument is specified.
if (args.length != 2) {
System.err.println(
"Usage: " + SctpClient.class.getSimpleName() +
" <host> <port>");
return;
}
// Parse options.
final String host = args[0];
final int port = Integer.parseInt(args[1]);
final int firstMessageSize;
new SctpClient(host, port).run();
}
}

View File

@ -30,8 +30,14 @@ import java.util.concurrent.Executors;
* Echoes back any received data from a client.
*/
public class SctpServer {
private final int port;
public SctpServer(int port) {
this.port = port;
}
public static void main(String[] args) throws Exception {
public void run() {
// Configure the server.
ServerBootstrap bootstrap = new ServerBootstrap(
new SctpServerSocketChannelFactory(
@ -54,6 +60,16 @@ public class SctpServer {
bootstrap.setOption("child.sctpNoDelay", true);
// Bind and start to accept incoming connections.
bootstrap.bind(new InetSocketAddress("localhost", 2955));
bootstrap.bind(new InetSocketAddress(port));
}
public static void main(String[] args) throws Exception {
int port;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
} else {
port = 2955;
}
new SctpServer(port).run();
}
}

View File

@ -39,10 +39,9 @@ import io.netty.handler.codec.string.StringEncoder;
*/
public class StdioLogger {
private static volatile boolean running = true;
public static void main(String[] args) {
private volatile boolean running = true;
public void run() {
final ExecutorService executorService = Executors.newCachedThreadPool();
final ClientBootstrap bootstrap = new ClientBootstrap(new IoStreamChannelFactory(executorService));
@ -64,7 +63,7 @@ public class StdioLogger {
e.getChannel().write("Message received: " + message);
}
if ("exit".equals(message)) {
StdioLogger.running = false;
running = false;
}
super.messageReceived(ctx, e);
}
@ -93,7 +92,9 @@ public class StdioLogger {
// Shut down all thread pools to exit.
bootstrap.releaseExternalResources();
}
public static void main(String[] args) {
new StdioLogger().run();
}
}

View File

@ -291,7 +291,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-build</artifactId>
<version>2-SNAPSHOT</version>
<version>3</version>
</dependency>
</dependencies>
</plugin>

View File

@ -36,19 +36,5 @@
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>