Automated code clean-up

This commit is contained in:
Trustin Lee 2012-05-31 12:03:01 -07:00
parent 734d452be2
commit 77274ae743
59 changed files with 300 additions and 230 deletions

View File

@ -42,7 +42,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
@Override
public void readerIndex(int readerIndex) {
if (readerIndex < 0 || readerIndex > writerIndex) {
throw new IndexOutOfBoundsException("Invalid readerIndex: "
throw new IndexOutOfBoundsException("Invalid readerIndex: "
+ readerIndex + " - Maximum is " + writerIndex);
}
this.readerIndex = readerIndex;
@ -56,7 +56,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
@Override
public void writerIndex(int writerIndex) {
if (writerIndex < readerIndex || writerIndex > capacity()) {
throw new IndexOutOfBoundsException("Invalid writerIndex: "
throw new IndexOutOfBoundsException("Invalid writerIndex: "
+ writerIndex + " - Maximum is " + readerIndex + " or " + capacity());
}
this.writerIndex = writerIndex;
@ -139,7 +139,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
@Override
public void ensureWritableBytes(int writableBytes) {
if (writableBytes > writableBytes()) {
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
+ writableBytes + ", maximum is " + writableBytes());
}
}

View File

@ -442,12 +442,12 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* not a dynamic buffer
*/
void ensureWritableBytes(int writableBytes);
/**
* Gets a boolean at the specified absolute (@code index) in this buffer.
* This method does not modify the {@code readerIndex} or {@code writerIndex}
* of this buffer.
*
*
* @throws IndexOutOfBoundsException
* if the specified {@code index} is less than {@code 0} or
* {@code index + 1} is greater than {@code this.capacity}
@ -736,7 +736,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* {@code index + 1} is greater than {@code this.capacity}
*/
void setBoolean(int index, boolean value);
/**
* Sets the specified byte at the specified absolute {@code index} in this
* buffer. The 24 high-order bits of the specified value are ignored.
@ -986,7 +986,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* if {@code index + length} is greater than {@code this.capacity}
*/
void setZero(int index, int length);
/**
* Gets a boolean at the current {@code readerIndex} and increases
* the {@code readerIndex} by {@code 1} in this buffer.
@ -1263,7 +1263,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* if {@code this.writableBytes} is less than {@code 1}
*/
void writeBoolean(boolean value);
/**
* Sets the specified byte at the current {@code writerIndex}
* and increases the {@code writerIndex} by {@code 1} in this buffer.

View File

@ -243,7 +243,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
}
if (fieldSize > available()) {
throw new EOFException("fieldSize is too long! Length is " + fieldSize
throw new EOFException("fieldSize is too long! Length is " + fieldSize
+ ", but maximum is " + available());
}
}

View File

@ -228,7 +228,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
int componentId = componentId(index);
if (index > capacity() - length || dstIndex > dst.length - length) {
throw new IndexOutOfBoundsException("Too many bytes to read - Needs "
+ (index + length) + ", maximum is " + capacity() + " or "
+ (index + length) + ", maximum is " + capacity() + " or "
+ dst.length);
}
@ -308,7 +308,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
throws IOException {
int componentId = componentId(index);
if (index > capacity() - length) {
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
+ (index + length) + ", maximum of " + capacity());
}
@ -675,13 +675,13 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
// If the list is empty we need to assign a new one because
// we get a List that is immutable.
// we get a List that is immutable.
//
// See https://github.com/netty/netty/issues/325
if (list.isEmpty()) {
list = new ArrayList<ChannelBuffer>(1);
}
// Add a new buffer so that the capacity of this composite buffer does
// not decrease due to the discarded components.
// XXX Might create too many components if discarded by small amount.

View File

@ -17,6 +17,7 @@ package io.netty.buffer;
import static io.netty.buffer.ChannelBuffers.*;
import static org.junit.Assert.*;
import io.netty.util.CharsetUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -26,7 +27,6 @@ import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import io.netty.util.CharsetUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -140,7 +140,7 @@ public abstract class AbstractChannelBufferTest {
buffer.readerIndex(0);
buffer.writerIndex(CAPACITY);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getBooleanBoundaryCheck1() {
buffer.getBoolean(-1);
@ -1641,7 +1641,7 @@ public abstract class AbstractChannelBufferTest {
assertFalse(set.contains(elemB));
assertEquals(0, set.size());
}
// Test case for https://github.com/netty/netty/issues/325
@Test
public void testDiscardAllReadBytes() {

View File

@ -16,8 +16,8 @@
package io.netty.buffer;
import static org.junit.Assert.*;
import io.netty.util.CharsetUtil;
import org.junit.Test;

View File

@ -15,8 +15,8 @@
*/
package io.netty.buffer;
import static org.easymock.EasyMock.*;
import static io.netty.buffer.ChannelBuffers.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import java.io.IOException;

View File

@ -15,13 +15,13 @@
*/
package io.netty.handler.codec.http;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
/**
* The default {@link HttpChunkTrailer} implementation.
*/

View File

@ -15,14 +15,14 @@
*/
package io.netty.handler.codec.http;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.util.internal.StringUtil;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* The default {@link HttpMessage} implementation.
*/

View File

@ -15,15 +15,15 @@
*/
package io.netty.handler.codec.http;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.ChannelPipeline;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.ChannelPipeline;
/**
* An HTTP chunk which is used for HTTP chunked transfer-encoding.
* {@link HttpMessageDecoder} generates {@link HttpChunk} after

View File

@ -99,7 +99,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
!HttpHeaders.Values.IDENTITY.equalsIgnoreCase(contentEncoding)) {
return null;
}
ZlibWrapper wrapper = determineWrapper(acceptEncoding);
if (wrapper == null) {
return null;

View File

@ -15,15 +15,15 @@
*/
package io.netty.handler.codec.http;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
/**
* An HTTP message which provides common properties for {@link HttpRequest} and
* {@link HttpResponse}.

View File

@ -37,9 +37,9 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
*/
public static long MINSIZE = 0x4000;
private boolean useDisk;
private final boolean useDisk;
private boolean checkSize;
private final boolean checkSize;
private long minSize;
@ -55,7 +55,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
public DefaultHttpDataFactory() {
useDisk = false;
checkSize = true;
this.minSize = MINSIZE;
minSize = MINSIZE;
}
/**
@ -79,7 +79,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
}
/**
*
*
* @param request
* @return the associated list of Files for the request
*/
@ -91,7 +91,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
}
return list;
}
@Override
public Attribute createAttribute(HttpRequest request, String name) {
if (useDisk) {

View File

@ -15,13 +15,13 @@
*/
package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ChannelBuffer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import io.netty.buffer.ChannelBuffer;
/**
* Extended interface for InterfaceHttpData
*/

View File

@ -32,7 +32,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
/**
* Creates a new binary frame with the specified binary data. The final fragment flag is set to true.
*
*
* @param binaryData
* the content of the frame.
*/
@ -42,7 +42,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
/**
* Creates a new binary frame with the specified binary data and the final fragment flag.
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv

View File

@ -33,7 +33,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
/**
* Creates a new empty close frame with closing status code and reason text
*
*
* @param statusCode
* Integer status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. For
* example, <tt>1000</tt> indicates normal closure.
@ -46,7 +46,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
/**
* Creates a new close frame with no losing status code and no reason text
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -58,7 +58,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
/**
* Creates a new close frame with closing status code and reason text
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -90,7 +90,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
/**
* Creates a new close frame
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -113,7 +113,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* a status code is set, -1 is returned.
*/
public int getStatusCode() {
ChannelBuffer binaryData = this.getBinaryData();
ChannelBuffer binaryData = getBinaryData();
if (binaryData == null || binaryData.capacity() == 0) {
return -1;
}
@ -130,7 +130,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* text is not supplied, an empty string is returned.
*/
public String getReasonText() {
ChannelBuffer binaryData = this.getBinaryData();
ChannelBuffer binaryData = getBinaryData();
if (binaryData == null || binaryData.capacity() <= 2) {
return "";
}

View File

@ -36,7 +36,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
/**
* Creates a new continuation frame with the specified binary data. The final fragment flag is set to true.
*
*
* @param binaryData
* the content of the frame.
*/
@ -46,7 +46,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
/**
* Creates a new continuation frame with the specified binary data
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -62,7 +62,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
/**
* Creates a new continuation frame with the specified binary data
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -81,7 +81,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
/**
* Creates a new continuation frame with the specified text data
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -107,7 +107,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
/**
* Sets the string for this frame
*
*
* @param text
* text to store
*/

View File

@ -33,7 +33,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
/**
* Creates a new ping frame with the specified binary data.
*
*
* @param binaryData
* the content of the frame.
*/
@ -43,7 +43,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
/**
* Creates a new ping frame with the specified binary data
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv

View File

@ -32,7 +32,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
/**
* Creates a new pong frame with the specified binary data.
*
*
* @param binaryData
* the content of the frame.
*/
@ -42,7 +42,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
/**
* Creates a new pong frame with the specified binary data
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv

View File

@ -33,7 +33,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
/**
* Creates a new text frame with the specified text string. The final fragment flag is set to true.
*
*
* @param text
* String to put in the frame
*/
@ -47,7 +47,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
/**
* Creates a new text frame with the specified binary data. The final fragment flag is set to true.
*
*
* @param binaryData
* the content of the frame. Must be UTF-8 encoded
*/
@ -57,7 +57,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
/**
* Creates a new text frame with the specified text string. The final fragment flag is set to true.
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -77,7 +77,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
/**
* Creates a new text frame with the specified binary data. The final fragment flag is set to true.
*
*
* @param finalFragment
* flag indicating if this frame is the final fragment
* @param rsv
@ -103,7 +103,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
/**
* Sets the string for this frame
*
*
* @param text
* text to store
*/

View File

@ -18,18 +18,18 @@
*
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package io.netty.handler.codec.http.websocketx;

View File

@ -18,18 +18,18 @@
*
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package io.netty.handler.codec.http.websocketx;

View File

@ -62,7 +62,7 @@ public class WebSocket13FrameEncoder extends WebSocket08FrameEncoder {
/**
* Constructor
*
*
* @param maskPayload
* Web socket clients must set this to true to mask payload. Server implementations must set this to
* false.

View File

@ -144,7 +144,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
} else {
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
this.setSelectedSubprotocol(selectedSubprotocol);
setSelectedSubprotocol(selectedSubprotocol);
}
}

View File

@ -138,7 +138,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
} else {
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
this.setSelectedSubprotocol(selectedSubprotocol);
setSelectedSubprotocol(selectedSubprotocol);
}
}

View File

@ -139,7 +139,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
} else {
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
this.setSelectedSubprotocol(selectedSubprotocol);
setSelectedSubprotocol(selectedSubprotocol);
}
}

View File

@ -15,14 +15,14 @@
*/
package io.netty.handler.codec.http.websocketx;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBuffers;
import io.netty.handler.codec.base64.Base64;
import io.netty.util.CharsetUtil;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* TODO Document me.
*/

View File

@ -30,8 +30,8 @@
* For the detailed instruction on adding add Web Socket support to your HTTP
* server, take a look into the <tt>WebSocketServerX</tt> example located in the
* {@code io.netty.example.http.websocket} package.
* </p>
*
* </p>
*
* @apiviz.exclude OneToOne(Encoder|Decoder)$
* @apiviz.exclude \.codec\.replay\.
* @apiviz.exclude \.Default

View File

@ -15,11 +15,11 @@
*/
package io.netty.handler.codec.rtsp;
import io.netty.handler.codec.http.HttpMethod;
import java.util.HashMap;
import java.util.Map;
import io.netty.handler.codec.http.HttpMethod;
/**
* The request method of RTSP.
* @apiviz.exclude

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.spdy;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import io.netty.buffer.ChannelBuffer;
import io.netty.handler.codec.compression.CompressionException;
import io.netty.util.internal.jzlib.JZlib;

View File

@ -15,11 +15,10 @@
*/
package io.netty.handler.codec.spdy;
import java.util.zip.Deflater;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import io.netty.buffer.ChannelBuffer;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import java.util.zip.Deflater;
class SpdyHeaderBlockZlibCompressor extends SpdyHeaderBlockCompressor {

View File

@ -15,12 +15,11 @@
*/
package io.netty.handler.codec.spdy;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import io.netty.buffer.ChannelBuffer;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {

View File

@ -15,12 +15,7 @@
*/
package io.netty.handler.codec.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.util.Date;
import java.util.Iterator;

View File

@ -15,9 +15,7 @@
*/
package io.netty.handler.codec.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import java.text.DateFormat;
import java.util.Date;
@ -126,7 +124,7 @@ public class CookieEncoderTest {
String encodedCookie = encoder.encode();
assertEquals(c1 + c2 + c3, encodedCookie);
}
@Test
public void testEncodingWithNoCookies() {
CookieEncoder encoderForServer = new CookieEncoder(true);
@ -134,8 +132,8 @@ public class CookieEncoderTest {
CookieEncoder encoderForClient = new CookieEncoder(false);
String encodedCookie2 = encoderForClient.encode();
assertNotNull(encodedCookie1);
assertNotNull(encodedCookie2);
assertNotNull(encodedCookie2);
}
}

View File

@ -15,13 +15,14 @@
*/
package io.netty.handler.codec.http;
import io.netty.util.CharsetUtil;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import io.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
@ -97,7 +98,7 @@ public class QueryStringDecoderTest {
assertQueryString("/foo?a=b&c=d", "/foo?a=b&c=d");
assertQueryString("/foo?a=1&a=&a=", "/foo?a=1&a&a=");
}
@Test
public void testHashDos() throws Exception {
StringBuilder buf = new StringBuilder();
@ -178,26 +179,26 @@ public class QueryStringDecoderTest {
Map<String, List<String>> params = decoder.getParameters();
Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
}
// See #189
@Test
public void testURISlashPath() {
@ -207,26 +208,26 @@ public class QueryStringDecoderTest {
Map<String, List<String>> params = decoder.getParameters();
Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
}
// See #189
@Test
public void testURINoPath() {
@ -236,23 +237,23 @@ public class QueryStringDecoderTest {
Map<String, List<String>> params = decoder.getParameters();
Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
}
}

View File

@ -15,10 +15,10 @@
*/
package io.netty.handler.codec.embedder;
import java.util.Collection;
import io.netty.channel.ChannelPipeline;
import java.util.Collection;
/**
* A helper that wraps an encoder or a decoder (codec) so that they can be used
* without doing actual I/O in unit tests or higher level codecs. Please refer

View File

@ -15,9 +15,10 @@
*/
package io.netty.handler.codec.marshalling;
import org.jboss.marshalling.Unmarshaller;
import io.netty.channel.ChannelHandlerContext;
import org.jboss.marshalling.Unmarshaller;
/**
* This provider is responsible to get an {@link Unmarshaller} for a {@link ChannelHandlerContext}
*

View File

@ -40,7 +40,7 @@ public final class ClassResolvers {
public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
}
/**
* agressive non-concurrent cache
* good for non-shared cache, when we're not worried about class unloading

View File

@ -23,7 +23,7 @@ import java.io.ObjectStreamClass;
import java.io.StreamCorruptedException;
class CompactObjectInputStream extends ObjectInputStream {
private final ClassResolver classResolver;
CompactObjectInputStream(InputStream in, ClassResolver classResolver) throws IOException {

View File

@ -98,7 +98,7 @@ public class ObjectDecoderInputStream extends InputStream implements
} else {
this.in = new DataInputStream(in);
}
this.classResolver = ClassResolvers.weakCachingResolver(classLoader);
classResolver = ClassResolvers.weakCachingResolver(classLoader);
this.maxObjectSize = maxObjectSize;
}

View File

@ -15,16 +15,16 @@
*/
package io.netty.handler.codec.serialization;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferOutputStream;
import io.netty.buffer.ChannelBuffers;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferOutputStream;
import io.netty.buffer.ChannelBuffers;
/**
* An {@link ObjectOutput} which is interoperable with {@link ObjectDecoder}
* and {@link ObjectDecoderInputStream}.

View File

@ -21,7 +21,7 @@ import java.util.Map;
import java.util.Set;
abstract class ReferenceMap<K, V> implements Map<K, V> {
private final Map<K, Reference<V>> delegate;
protected ReferenceMap(Map<K, Reference<V>> delegate) {

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.marshalling;
public class RiverThreadLocalCompatibleMarshallingEncoderTest extends RiverCompatibleMarshallingEncoderTest {
@Override
protected MarshallerProvider createProvider() {
return new ThreadLocalMarshallerProvider(createMarshallerFactory(), createMarshallingConfig());

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.marshalling;
public class RiverThreadLocalMarshallingEncoderTest extends RiverMarshallingEncoderTest {
@Override
protected MarshallerProvider createProvider() {
return new ThreadLocalMarshallerProvider(createMarshallerFactory(), createMarshallingConfig());

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.marshalling;
public class SerialThreadLocalMarshallingEncoderTest extends SerialMarshallingEncoderTest {
@Override
protected MarshallerProvider createProvider() {
return new ThreadLocalMarshallerProvider(createMarshallerFactory(), createMarshallingConfig());

View File

@ -15,13 +15,13 @@
*/
package io.netty.handler.codec.protobuf;
import static io.netty.buffer.ChannelBuffers.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static io.netty.buffer.ChannelBuffers.*;
import static org.junit.Assert.*;
import io.netty.buffer.ChannelBuffer;
import io.netty.handler.codec.embedder.DecoderEmbedder;
import org.junit.Before;
import org.junit.Test;

View File

@ -15,12 +15,12 @@
*/
package io.netty.handler.codec.protobuf;
import static org.hamcrest.core.Is.*;
import static io.netty.buffer.ChannelBuffers.*;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import io.netty.buffer.ChannelBuffer;
import io.netty.handler.codec.embedder.EncoderEmbedder;
import org.junit.Before;
import org.junit.Test;

View File

@ -29,6 +29,9 @@ public class UniqueName implements Comparable<UniqueName> {
this.name = name;
}
/**
* @param args arguments to validate
*/
protected void validateArgs(Object... args) {
// Subclasses will override.
}

View File

@ -142,7 +142,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
return segments[hash >>> segmentShift & segmentMask];
}
private int hashOf(Object key) {
private static int hashOf(Object key) {
return hash(System.identityHashCode(key));
}
@ -315,7 +315,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
return new Segment[i];
}
private boolean keyEq(Object src, Object dest) {
private static boolean keyEq(Object src, Object dest) {
return src == dest;
}

View File

@ -40,7 +40,7 @@ import java.util.concurrent.locks.LockSupport;
* </strong>
* <br>
* <br>
*
*
* An unbounded {@link BlockingQueue} based on linked nodes.
* This queue orders elements FIFO (first-in-first-out) with respect
* to any given producer. The <em>head</em> of the queue is that
@ -672,7 +672,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
continue retry; // lost race vs opposite mode
}
if (how != ASYNC) {
return awaitMatch(s, pred, e, (how == TIMED), nanos);
return awaitMatch(s, pred, e, how == TIMED, nanos);
}
}
return e; // not waiting
@ -1351,7 +1351,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
for (;;) {
@SuppressWarnings("unchecked") E item = (E) s.readObject();
E item = (E) s.readObject();
if (item == null) {
break;
} else {

View File

@ -36,13 +36,13 @@ import java.util.concurrent.locks.LockSupport;
* <br>
* The only difference is that it replace {@link BlockingQueue} and any reference to the TransferQueue interface was removed
* <br>
*
*
* <strong>
* Please use {@link QueueFactory} to create a Queue as it will use the "optimal" implementation depending on the JVM
* </strong>
* <br>
* <br>
*
*
* An unbounded {@link BlockingQueue} based on linked nodes.
* This queue orders elements FIFO (first-in-first-out) with respect
* to any given producer. The <em>head</em> of the queue is that
@ -496,7 +496,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
final boolean isMatched() {
Object x = item;
return (x == this) || ((x == null) == isData);
return x == this || x == null == isData;
}
/**
@ -514,7 +514,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
final boolean cannotPrecede(boolean haveData) {
boolean d = isData;
Object x;
return d != haveData && (x = item) != this && (x != null) == d;
return d != haveData && (x = item) != this && x != null == d;
}
/**
@ -598,8 +598,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @throws NullPointerException if haveData mode but e is null
*/
private E xfer(E e, boolean haveData, int how, long nanos) {
if (haveData && (e == null))
if (haveData && e == null) {
throw new NullPointerException();
}
Node s = null; // the node to append, if needed
retry:
@ -608,9 +609,10 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
for (Node h = head, p = h; p != null;) { // find & match first node
boolean isData = p.isData;
Object item = p.item;
if (item != p && (item != null) == isData) { // unmatched
if (isData == haveData) // can't match
if (item != p && item != null == isData) { // unmatched
if (isData == haveData) {
break;
}
if (p.casItem(item, e)) { // match
for (Node q = p; q != h;) {
Node n = q.next; // update by 2 unless singleton
@ -620,24 +622,30 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
} // advance and retry
if ((h = head) == null ||
(q = h.next) == null || !q.isMatched())
{
break; // unless slack < 2
}
}
LockSupport.unpark(p.waiter);
return LinkedTransferQueue.<E>cast(item);
}
}
Node n = p.next;
p = (p != n) ? n : (h = head); // Use head if p offlist
p = p != n ? n : (h = head); // Use head if p offlist
}
if (how != NOW) { // No matches available
if (s == null)
if (s == null) {
s = new Node(e, haveData);
}
Node pred = tryAppend(s, haveData);
if (pred == null)
{
continue retry; // lost race vs opposite mode
if (how != ASYNC)
return awaitMatch(s, pred, e, (how == TIMED), nanos);
}
if (how != ASYNC) {
return awaitMatch(s, pred, e, how == TIMED, nanos);
}
}
return e; // not waiting
}
@ -657,21 +665,25 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
Node n, u; // temps for reads of next & tail
if (p == null && (p = head) == null) {
if (casHead(null, s))
{
return s; // initialize
}
}
else if (p.cannotPrecede(haveData))
else if (p.cannotPrecede(haveData)) {
return null; // lost race vs opposite mode
else if ((n = p.next) != null) // not last; keep traversing
} else if ((n = p.next) != null) {
p = p != t && t != (u = tail) ? (t = u) : // stale tail
(p != n) ? n : null; // restart if off list
else if (!p.casNext(null, s))
p != n ? n : null; // restart if off list
} else if (!p.casNext(null, s)) {
p = p.next; // re-read on CAS failure
else {
} else {
if (p != t) { // update if slack now >= 2
while ((tail != t || !casTail(t, s)) &&
(t = tail) != null &&
(s = t.next) != null && // advance and retry
(s = s.next) != null && s != t);
(s = s.next) != null && s != t) {
continue;
}
}
return p;
}
@ -703,28 +715,32 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
s.forgetContents(); // avoid garbage
return LinkedTransferQueue.<E>cast(item);
}
if ((w.isInterrupted() || (timed && nanos <= 0)) &&
if ((w.isInterrupted() || timed && nanos <= 0) &&
s.casItem(e, s)) { // cancel
unsplice(pred, s);
return e;
}
if (spins < 0) { // establish spins at/near front
if ((spins = spinsFor(pred, s.isData)) > 0)
if ((spins = spinsFor(pred, s.isData)) > 0) {
randomYields = ThreadLocalRandom.current();
}
}
else if (spins > 0) { // spin
--spins;
if (randomYields.nextInt(CHAINED_SPINS) == 0)
{
Thread.yield(); // occasionally yield
}
}
else if (s.waiter == null) {
s.waiter = w; // request unpark then recheck
}
else if (timed) {
long now = System.nanoTime();
if ((nanos -= now - lastTime) > 0)
if ((nanos -= now - lastTime) > 0) {
LockSupport.parkNanos(this, nanos);
}
lastTime = now;
}
else {
@ -739,12 +755,15 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
private static int spinsFor(Node pred, boolean haveData) {
if (MP && pred != null) {
if (pred.isData != haveData) // phase change
if (pred.isData != haveData) {
return FRONT_SPINS + CHAINED_SPINS;
if (pred.isMatched()) // probably at front
}
if (pred.isMatched()) {
return FRONT_SPINS;
if (pred.waiter == null) // pred apparently spinning
}
if (pred.waiter == null) {
return CHAINED_SPINS;
}
}
return 0;
}
@ -758,7 +777,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
final Node succ(Node p) {
Node next = p.next;
return (p == next) ? head : next;
return p == next ? head : next;
}
/**
@ -767,8 +786,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
private Node firstOfMode(boolean isData) {
for (Node p = head; p != null; p = succ(p)) {
if (!p.isMatched())
return (p.isData == isData) ? p : null;
if (!p.isMatched()) {
return p.isData == isData ? p : null;
}
}
return null;
}
@ -781,11 +801,13 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
for (Node p = head; p != null; p = succ(p)) {
Object item = p.item;
if (p.isData) {
if (item != null && item != p)
if (item != null && item != p) {
return LinkedTransferQueue.<E>cast(item);
}
}
else if (item == null)
else if (item == null) {
return null;
}
}
return null;
}
@ -798,15 +820,17 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
int count = 0;
for (Node p = head; p != null; ) {
if (!p.isMatched()) {
if (p.isData != data)
if (p.isData != data) {
return 0;
if (++count == Integer.MAX_VALUE) // saturated
}
if (++count == Integer.MAX_VALUE) {
break;
}
}
Node n = p.next;
if (n != p)
if (n != p) {
p = n;
else {
} else {
count = 0;
p = head;
}
@ -835,25 +859,26 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
Node r, b; // reset lastPred upon possible deletion of lastRet
if ((r = lastRet) != null && !r.isMatched())
if ((r = lastRet) != null && !r.isMatched()) {
lastPred = r; // next lastPred is old lastRet
else if ((b = lastPred) == null || b.isMatched())
} else if ((b = lastPred) == null || b.isMatched()) {
lastPred = null; // at start of list
else {
} else {
Node s, n; // help with removal of lastPred.next
while ((s = b.next) != null &&
s != b && s.isMatched() &&
(n = s.next) != null && n != s)
(n = s.next) != null && n != s) {
b.casNext(s, n);
}
}
this.lastRet = prev;
for (Node p = prev, s, n;;) {
s = (p == null) ? head : p.next;
if (s == null)
s = p == null ? head : p.next;
if (s == null) {
break;
else if (s == p) {
} else if (s == p) {
p = null;
continue;
}
@ -865,17 +890,19 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
return;
}
}
else if (item == null)
else if (item == null) {
break;
}
// assert s.isMatched();
if (p == null)
if (p == null) {
p = s;
else if ((n = s.next) == null)
} else if ((n = s.next) == null) {
break;
else if (s == n)
} else if (s == n) {
p = null;
else
} else {
p.casNext(s, n);
}
}
nextNode = null;
nextItem = null;
@ -885,25 +912,32 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
advance(null);
}
@Override
public final boolean hasNext() {
return nextNode != null;
}
@Override
public final E next() {
Node p = nextNode;
if (p == null) throw new NoSuchElementException();
if (p == null) {
throw new NoSuchElementException();
}
E e = nextItem;
advance(p);
return e;
}
@Override
public final void remove() {
final Node lastRet = this.lastRet;
if (lastRet == null)
if (lastRet == null) {
throw new IllegalStateException();
}
this.lastRet = null;
if (lastRet.tryMatchData())
if (lastRet.tryMatchData()) {
unsplice(lastPred, lastRet);
}
}
}
@ -929,25 +963,33 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
if (pred != null && pred != s && pred.next == s) {
Node n = s.next;
if (n == null ||
(n != s && pred.casNext(s, n) && pred.isMatched())) {
n != s && pred.casNext(s, n) && pred.isMatched()) {
for (;;) { // check if at, or could be, head
Node h = head;
if (h == pred || h == s || h == null)
{
return; // at head or list empty
if (!h.isMatched())
}
if (!h.isMatched()) {
break;
}
Node hn = h.next;
if (hn == null)
{
return; // now empty
}
if (hn != h && casHead(h, hn))
{
h.forgetNext(); // advance head
}
}
if (pred.next != pred && s.next != s) { // recheck if offlist
for (;;) { // sweep now if enough votes
int v = sweepVotes;
if (v < SWEEP_THRESHOLD) {
if (casSweepVotes(v, v + 1))
if (casSweepVotes(v, v + 1)) {
break;
}
}
else if (casSweepVotes(v, 0)) {
sweep();
@ -965,16 +1007,17 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
private void sweep() {
for (Node p = head, s, n; p != null && (s = p.next) != null; ) {
if (!s.isMatched())
if (!s.isMatched()) {
// Unmatched nodes are never self-linked
p = s;
else if ((n = s.next) == null) // trailing node is pinned
} else if ((n = s.next) == null) {
break;
else if (s == n) // stale
} else if (s == n) {
// No need to also check for p == s, since that implies s == n
p = head;
else
} else {
p.casNext(s, n);
}
}
}
@ -992,8 +1035,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
return true;
}
}
else if (item == null)
else if (item == null) {
break;
}
pred = p;
if ((p = p.next) == pred) { // stale
pred = null;
@ -1031,6 +1075,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*
* @throws NullPointerException if the specified element is null
*/
@Override
public void put(E e) {
xfer(e, true, ASYNC, 0);
}
@ -1045,6 +1090,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* BlockingQueue.offer})
* @throws NullPointerException if the specified element is null
*/
@Override
public boolean offer(E e, long timeout, TimeUnit unit) {
xfer(e, true, ASYNC, 0);
return true;
@ -1057,6 +1103,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @return {@code true} (as specified by {@link Queue#offer})
* @throws NullPointerException if the specified element is null
*/
@Override
public boolean offer(E e) {
xfer(e, true, ASYNC, 0);
return true;
@ -1070,6 +1117,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @return {@code true} (as specified by {@link Collection#add})
* @throws NullPointerException if the specified element is null
*/
@Override
public boolean add(E e) {
xfer(e, true, ASYNC, 0);
return true;
@ -1123,28 +1171,35 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*/
public boolean tryTransfer(E e, long timeout, TimeUnit unit)
throws InterruptedException {
if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null)
if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null) {
return true;
if (!Thread.interrupted())
}
if (!Thread.interrupted()) {
return false;
}
throw new InterruptedException();
}
@Override
public E take() throws InterruptedException {
E e = xfer(null, false, SYNC, 0);
if (e != null)
if (e != null) {
return e;
}
Thread.interrupted();
throw new InterruptedException();
}
@Override
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
E e = xfer(null, false, TIMED, unit.toNanos(timeout));
if (e != null || !Thread.interrupted())
if (e != null || !Thread.interrupted()) {
return e;
}
throw new InterruptedException();
}
@Override
public E poll() {
return xfer(null, false, NOW, 0);
}
@ -1153,11 +1208,14 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
*/
@Override
public int drainTo(Collection<? super E> c) {
if (c == null)
if (c == null) {
throw new NullPointerException();
if (c == this)
}
if (c == this) {
throw new IllegalArgumentException();
}
int n = 0;
for (E e; (e = poll()) != null;) {
c.add(e);
@ -1170,11 +1228,14 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
*/
@Override
public int drainTo(Collection<? super E> c, int maxElements) {
if (c == null)
if (c == null) {
throw new NullPointerException();
if (c == this)
}
if (c == this) {
throw new IllegalArgumentException();
}
int n = 0;
for (E e; n < maxElements && (e = poll()) != null;) {
c.add(e);
@ -1196,10 +1257,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*
* @return an iterator over the elements in this queue in proper sequence
*/
@Override
public Iterator<E> iterator() {
return new Itr();
}
@Override
public E peek() {
return firstDataItem();
}
@ -1209,10 +1272,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*
* @return {@code true} if this queue contains no elements
*/
@Override
public boolean isEmpty() {
for (Node p = head; p != null; p = succ(p)) {
if (!p.isMatched())
if (!p.isMatched()) {
return !p.isData;
}
}
return true;
}
@ -1233,6 +1298,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
*
* @return the number of elements in this queue
*/
@Override
public int size() {
return countOfMode(true);
}
@ -1252,6 +1318,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @param o element to be removed from this queue, if present
* @return {@code true} if this queue changed as a result of the call
*/
@Override
public boolean remove(Object o) {
return findAndRemove(o);
}
@ -1264,16 +1331,21 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* @param o object to be checked for containment in this queue
* @return {@code true} if this queue contains the specified element
*/
@Override
public boolean contains(Object o) {
if (o == null) return false;
if (o == null) {
return false;
}
for (Node p = head; p != null; p = succ(p)) {
Object item = p.item;
if (p.isData) {
if (item != null && item != p && o.equals(item))
if (item != null && item != p && o.equals(item)) {
return true;
}
}
else if (item == null)
else if (item == null) {
break;
}
}
return false;
}
@ -1286,6 +1358,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
* {@link java.util.concurrent.BlockingQueue#remainingCapacity()
* BlockingQueue.remainingCapacity})
*/
@Override
public int remainingCapacity() {
return Integer.MAX_VALUE;
}
@ -1300,8 +1373,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
s.defaultWriteObject();
for (E e : this)
for (E e : this) {
s.writeObject(e);
}
// Use trailing null as sentinel
s.writeObject(null);
}
@ -1316,12 +1390,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
for (;;) {
@SuppressWarnings("unchecked")
E item = (E) s.readObject();
if (item == null)
if (item == null) {
break;
else
} else {
offer(item);
}
}
}
@ -1361,6 +1435,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
return java.security.AccessController.doPrivileged
(new java.security
.PrivilegedExceptionAction<sun.misc.Unsafe>() {
@Override
public sun.misc.Unsafe run() throws Exception {
java.lang.reflect.Field f = sun.misc
.Unsafe.class.getDeclaredField("theUnsafe");

View File

@ -15,12 +15,12 @@
*/
package io.netty.util.internal;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
/**
* Warn when user creates too many instances to avoid {@link OutOfMemoryError}.
*/

View File

@ -112,7 +112,7 @@ final class Adler32 {
}
return s2 << 16 | s1;
}
private Adler32() {
// Utility Class
}

View File

@ -92,7 +92,7 @@ final class CRC32 {
crc32 ^= 0xffffffff;
return crc32;
}
private CRC32() {
// Utility Class
}

View File

@ -456,7 +456,7 @@ final class InfCodes {
// at least ten. The ten bytes are six bytes for the longest length/
// distance pair plus four bytes for overloading the bit buffer.
int inflate_fast(int bl, int bd, int[] tl, int tl_index, int[] td,
static int inflate_fast(int bl, int bd, int[] tl, int tl_index, int[] td,
int td_index, InfBlocks s, ZStream z) {
int t; // temporary pointer
int[] tp; // temporary pointer

View File

@ -562,7 +562,7 @@ final class Inflate {
}
}
int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength) {
static int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength) {
int index = 0;
int length = dictLength;
if (z == null || z.istate == null || z.istate.mode != DICT0) {

View File

@ -105,7 +105,7 @@ public final class JZlib {
enum WrapperType {
NONE, ZLIB, GZIP, ZLIB_OR_NONE
}
private JZlib() {
// Utility class
}

View File

@ -114,7 +114,7 @@ public final class ZStream {
if (istate == null) {
return JZlib.Z_STREAM_ERROR;
}
return istate.inflateSetDictionary(this, dictionary, dictLength);
return Inflate.inflateSetDictionary(this, dictionary, dictLength);
}
public int deflateInit(int level) {

View File

@ -66,7 +66,7 @@ public class StringUtilTest {
}
}
private void assertStripped(final char controlCode) {
private static void assertStripped(final char controlCode) {
final Object object = "aaa" + controlCode + "bbb";
final String stripped = StringUtil.stripControlCharacters(object);
assertEquals("aaa bbb", stripped);