Skip to content

Commit

Permalink
Code cleanups (courtesy of IntelliJ Idea code inspector)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1487830 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ok2c committed May 30, 2013
1 parent e7a242d commit 828e955
Show file tree
Hide file tree
Showing 78 changed files with 153 additions and 241 deletions.
2 changes: 1 addition & 1 deletion httpcore-ab/pom.xml
Expand Up @@ -77,7 +77,7 @@
<source>${maven.compile.source}</source>
<target>${maven.compile.target}</target>
<optimize>${maven.compile.optimize}</optimize>
<showDeprecations>${maven.compile.deprecation}</showDeprecations>
<showDeprecation>${maven.compile.deprecation}</showDeprecation>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -123,7 +123,7 @@ public void run() {
resetHeader(request);
if (!conn.isOpen()) {

Socket socket;
final Socket socket;
if (socketFactory != null) {
socket = socketFactory.createSocket();
} else {
Expand Down Expand Up @@ -171,7 +171,7 @@ public void run() {
}
long contentlen = 0;
final InputStream instream = entity.getContent();
int l = 0;
int l;
while ((l = instream.read(this.buffer)) != -1) {
contentlen += l;
if (config.getVerbosity() >= 4) {
Expand Down
Expand Up @@ -112,7 +112,7 @@ private HttpRequest createRequest() {
se.setChunked(config.isUseChunking());
entity = se;
}
HttpRequest request;
final HttpRequest request;
if ("POST".equals(config.getMethod())) {
final BasicHttpEntityEnclosingRequest httppost =
new BasicHttpEntityEnclosingRequest("POST", url.getPath());
Expand Down
2 changes: 1 addition & 1 deletion httpcore-nio/pom.xml
Expand Up @@ -91,7 +91,7 @@
<source>${maven.compile.source}</source>
<target>${maven.compile.target}</target>
<optimize>${maven.compile.optimize}</optimize>
<showDeprecations>${maven.compile.deprecation}</showDeprecations>
<showDeprecation>${maven.compile.deprecation}</showDeprecation>
</configuration>
</plugin>
<plugin>
Expand Down
Expand Up @@ -150,7 +150,7 @@ public SSLNHttpClientConnectionFactory(final ConnectionConfig config) {
}

private SSLContext getDefaultSSLContext() {
SSLContext sslcontext;
final SSLContext sslcontext;
try {
sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
Expand Down
Expand Up @@ -150,7 +150,7 @@ public SSLNHttpServerConnectionFactory(final ConnectionConfig config) {
}

private SSLContext getDefaultSSLContext() {
SSLContext sslcontext;
final SSLContext sslcontext;
try {
sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
Expand Down
Expand Up @@ -150,7 +150,7 @@ protected int writeToBuffer(final ByteBuffer src, final int limit) throws IOExce

private int doWriteChunk(
final ByteBuffer src, final int chunk, final boolean direct) throws IOException {
int bytesWritten;
final int bytesWritten;
if (src.remaining() > chunk) {
final int oldLimit = src.limit();
final int newLimit = oldLimit - (src.remaining() - chunk);
Expand Down
Expand Up @@ -227,8 +227,7 @@ public T parse() throws IOException, HttpException {
}
}
if (this.state == COMPLETED) {
for (int i = 0; i < this.headerBufs.size(); i++) {
final CharArrayBuffer buffer = this.headerBufs.get(i);
for (final CharArrayBuffer buffer : this.headerBufs) {
try {
this.message.addHeader(lineParser.parseHeader(buffer));
} catch (final ParseException ex) {
Expand Down
Expand Up @@ -102,7 +102,6 @@ public void reset() {
* Writes out the first line of {@link HttpMessage}.
*
* @param message HTTP message.
* @throws HttpException in case of HTTP protocol violation
*/
protected abstract void writeHeadLine(T message) throws IOException;

Expand Down
Expand Up @@ -78,7 +78,7 @@ public int read(final ByteBuffer dst) throws IOException {
return -1;
}

int bytesRead;
final int bytesRead;
if (this.buffer.hasData()) {
bytesRead = this.buffer.read(dst);
} else {
Expand Down
Expand Up @@ -77,7 +77,7 @@ public int read(final ByteBuffer dst) throws IOException {
}
final int chunk = (int) Math.min((this.contentLength - this.len), Integer.MAX_VALUE);

int bytesRead;
final int bytesRead;
if (this.buffer.hasData()) {
final int maxLen = Math.min(chunk, this.buffer.length());
bytesRead = this.buffer.read(dst, maxLen);
Expand Down Expand Up @@ -117,7 +117,7 @@ public long transfer(

final int chunk = (int) Math.min((this.contentLength - this.len), Integer.MAX_VALUE);

long bytesRead;
final long bytesRead;
if (this.buffer.hasData()) {
final int maxLen = Math.min(chunk, this.buffer.length());
dst.position(position);
Expand Down
Expand Up @@ -128,8 +128,7 @@ public int write(final ByteBuffer src) throws IOException {
if (!this.buffer.hasData()) {
final int chunk = nextChunk(src);
if (chunk > this.fragHint) {
final int limit = chunk;
final int bytesWritten = writeToChannel(src, limit);
final int bytesWritten = writeToChannel(src, chunk);
this.remaining -= bytesWritten;
total += bytesWritten;
if (bytesWritten == 0) {
Expand Down
Expand Up @@ -147,7 +147,7 @@ public BasicNIOConnFactory(final ConnectionConfig config) {
}

public NHttpClientConnection create(final HttpHost route, final IOSession session) throws IOException {
NHttpClientConnection conn;
final NHttpClientConnection conn;
if (route.getSchemeName().equalsIgnoreCase("https")) {
if (this.sslFactory == null) {
throw new IOException("SSL not supported");
Expand Down
Expand Up @@ -60,7 +60,7 @@
@ThreadSafe
public class BasicNIOConnPool extends AbstractNIOConnPool<HttpHost, NHttpClientConnection, BasicNIOPoolEntry> {

private static AtomicLong COUNTER = new AtomicLong();
private static final AtomicLong COUNTER = new AtomicLong();

private final int connectTimeout;

Expand Down
Expand Up @@ -251,7 +251,7 @@ protected void execute() throws InterruptedIOException, IOReactorException {
try {
for (;;) {

int readyCount;
final int readyCount;
try {
readyCount = this.selector.select(this.selectTimeout);
} catch (final InterruptedIOException ex) {
Expand Down Expand Up @@ -301,7 +301,7 @@ protected void execute() throws InterruptedIOException, IOReactorException {

}

} catch (final ClosedSelectorException ex) {
} catch (final ClosedSelectorException ignore) {
} finally {
hardShutdown();
synchronized (this.statusMutex) {
Expand Down Expand Up @@ -362,8 +362,8 @@ private void processNewChannels() throws IOReactorException {
ChannelEntry entry;
while ((entry = this.newChannels.poll()) != null) {

SocketChannel channel;
SelectionKey key;
final SocketChannel channel;
final SelectionKey key;
try {
channel = entry.getChannel();
channel.configureBlocking(false);
Expand Down
Expand Up @@ -171,7 +171,7 @@ public AbstractMultiworkerIOReactor() throws IOReactorException {

static IOReactorConfig convert(final int workerCount, final HttpParams params) {
Args.notNull(params, "HTTP parameters");
final IOReactorConfig config = IOReactorConfig.custom()
return IOReactorConfig.custom()
.setSelectInterval(NIOReactorParams.getSelectInterval(params))
.setShutdownGracePeriod(NIOReactorParams.getGracePeriod(params))
.setInterestOpQueued(NIOReactorParams.getInterestOpsQueueing(params))
Expand All @@ -183,8 +183,6 @@ static IOReactorConfig convert(final int workerCount, final HttpParams params) {
.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params))
.setSoReuseAddress(HttpConnectionParams.getSoReuseaddr(params))
.build();

return config;
}

/**
Expand Down Expand Up @@ -338,7 +336,7 @@ public void execute(
}

for (;;) {
int readyCount;
final int readyCount;
try {
readyCount = this.selector.select(this.selectTimeout);
} catch (final InterruptedIOException ex) {
Expand Down
Expand Up @@ -253,7 +253,7 @@ private void processSessionRequests() throws IOReactorException {
if (request.isCompleted()) {
continue;
}
SocketChannel socketChannel;
final SocketChannel socketChannel;
try {
socketChannel = SocketChannel.open();
} catch (final IOException ex) {
Expand Down
Expand Up @@ -200,7 +200,7 @@ private void processEvent(final SelectionKey key)
}

private ListenerEndpointImpl createEndpoint(final SocketAddress address) {
final ListenerEndpointImpl endpoint = new ListenerEndpointImpl(
return new ListenerEndpointImpl(
address,
new ListenerEndpointClosedCallback() {

Expand All @@ -209,7 +209,6 @@ public void endpointClosed(final ListenerEndpoint endpoint) {
}

});
return endpoint;
}

public ListenerEndpoint listen(final SocketAddress address) {
Expand All @@ -225,7 +224,7 @@ private void processSessionRequests() throws IOReactorException {
ListenerEndpointImpl request;
while ((request = this.requestQueue.poll()) != null) {
final SocketAddress address = request.getAddress();
ServerSocketChannel serverChannel;
final ServerSocketChannel serverChannel;
try {
serverChannel = ServerSocketChannel.open();
} catch (final IOException ex) {
Expand Down Expand Up @@ -283,9 +282,7 @@ public void pause() throws IOException {
}
this.paused = true;
synchronized (this.endpoints) {
final Iterator<ListenerEndpointImpl> it = this.endpoints.iterator();
while (it.hasNext()) {
final ListenerEndpoint endpoint = it.next();
for (final ListenerEndpointImpl endpoint : this.endpoints) {
if (!endpoint.isClosed()) {
endpoint.close();
this.pausedEndpoints.add(endpoint.getAddress());
Expand Down
Expand Up @@ -59,7 +59,15 @@ public int getEventMask() {

@Override
public boolean equals(final Object obj) {
return this.key.equals(obj);
if (this == obj) {
return true;
}
if (obj instanceof InterestOpEntry) {
final InterestOpEntry that = (InterestOpEntry) obj;
return this.key.equals(that.key);
} else {
return false;
}
}

@Override
Expand Down
Expand Up @@ -161,8 +161,7 @@ public int fill(final ReadableByteChannel channel) throws IOException {
if (!this.buffer.hasRemaining()) {
expand();
}
final int readNo = channel.read(this.buffer);
return readNo;
return channel.read(this.buffer);
}

public int read() {
Expand Down Expand Up @@ -202,7 +201,7 @@ public int read(final WritableByteChannel dst, final int maxLen) throws IOExcept
return 0;
}
setOutputMode();
int bytesRead;
final int bytesRead;
if (this.buffer.remaining() > maxLen) {
final int oldLimit = this.buffer.limit();
final int newLimit = oldLimit - (this.buffer.remaining() - maxLen);
Expand Down
Expand Up @@ -164,8 +164,7 @@ public void reset(final HttpParams params) {
public int flush(final WritableByteChannel channel) throws IOException {
Args.notNull(channel, "Channel");
setOutputMode();
final int noWritten = channel.write(this.buffer);
return noWritten;
return channel.write(this.buffer);
}

public void write(final ByteBuffer src) {
Expand Down
Expand Up @@ -84,10 +84,6 @@ public void finish() {
this.finished = true;
}

@Override
public void consumeContent() throws IOException {
}

/**
* Obtains entity's content as {@link InputStream}.
*
Expand Down
Expand Up @@ -78,17 +78,6 @@ public void writeTo(final OutputStream out) throws IOException, UnsupportedOpera
throw new UnsupportedOperationException("Does not support blocking methods");
}

/**
* This method is equivalent to the {@link #finish()} method.
* <br/>
* TODO: The name of this method is misnomer. It will be renamed to
* #finish() in the next major release.
*/
@Override
public void consumeContent() throws IOException {
finish();
}

public void consumeContent(
final ContentDecoder decoder,
final IOControl ioctrl) throws IOException {
Expand Down
Expand Up @@ -165,7 +165,7 @@ public void produceContent(final ContentEncoder encoder, final IOControl ioctrl)
idx = 0;
}

long transferred;
final long transferred;
if (useFileChannels && encoder instanceof FileContentEncoder) {
transferred = ((FileContentEncoder)encoder)
.transfer(fileChannel, idx, Long.MAX_VALUE);
Expand Down
Expand Up @@ -83,17 +83,6 @@ public void writeTo(final OutputStream out) throws IOException, UnsupportedOpera
throw new UnsupportedOperationException("Does not support blocking methods");
}

/**
* This method is equivalent to the {@link #finish()} method.
* <br/>
* TODO: The name of this method is misnomer. It will be renamed to
* #finish() in the next major release.
*/
@Override
public void consumeContent() throws IOException {
finish();
}

public void produceContent(
final ContentEncoder encoder,
final IOControl ioctrl) throws IOException {
Expand Down
Expand Up @@ -319,7 +319,7 @@ private boolean processPendingRequest(final LeaseRequest<T, C, E> request) {
}

final RouteSpecificPool<T, C, E> pool = getPool(route);
E entry = null;
E entry;
for (;;) {
entry = pool.getFree(state);
if (entry == null) {
Expand Down Expand Up @@ -497,7 +497,7 @@ protected void requestTimeout(final SessionRequest request) {
private int getMax(final T route) {
final Integer v = this.maxPerRoute.get(route);
if (v != null) {
return v.intValue();
return v;
} else {
return this.defaultMaxPerRoute;
}
Expand Down
Expand Up @@ -89,8 +89,6 @@ public interface HttpAsyncExchange {
* connection times out or gets terminated prematurely by the client. This
* callback can be used to cancel a long running response generating
* process if a response is no longer needed.
*
* @param cancellable
*/
void setCallback(Cancellable cancellable);

Expand Down
Expand Up @@ -49,8 +49,6 @@ public interface HttpAsyncResponseProducer extends Closeable {
* Invoked to generate a HTTP response message head.
*
* @return HTTP response message.
* @throws HttpException in case of HTTP protocol violation
* @throws IOException in case of an I/O error
*/
HttpResponse generateResponse();

Expand Down
Expand Up @@ -66,11 +66,6 @@ public void writeTo(final OutputStream out) throws IOException, UnsupportedOpera
throw new UnsupportedOperationException("Does not support blocking methods");
}

@Override
public void consumeContent() throws IOException {
finish();
}

public void consumeContent(
final ContentDecoder decoder,
final IOControl ioctrl) throws IOException {
Expand Down

0 comments on commit 828e955

Please sign in to comment.