Apply checkstyle to the build
Please note that the build will fail at the moment due to various checkstyle violations which should be fixed soon
This commit is contained in:
parent
c38e6c77c2
commit
ebfc4513e0
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,7 +5,7 @@
|
||||
*.ipr
|
||||
*.iws
|
||||
.geany
|
||||
*/target
|
||||
/target
|
||||
*/target
|
||||
/reports
|
||||
*/reports
|
||||
|
@ -135,7 +135,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(int index) {
|
||||
return (getByte(index) == 1);
|
||||
return getByte(index) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -278,7 +278,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public boolean readBoolean() {
|
||||
return (readByte() == 1);
|
||||
return readByte() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,67 +59,67 @@ public class BigEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
|
||||
@Override
|
||||
public short getShort(int index) {
|
||||
return (short) (array[index] << 8 | array[index+1] & 0xFF);
|
||||
return (short) (array[index] << 8 | array[index + 1] & 0xFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedMedium(int index) {
|
||||
return (array[index] & 0xff) << 16 |
|
||||
(array[index+1] & 0xff) << 8 |
|
||||
(array[index+2] & 0xff) << 0;
|
||||
(array[index + 1] & 0xff) << 8 |
|
||||
(array[index + 2] & 0xff) << 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int index) {
|
||||
return (array[index] & 0xff) << 24 |
|
||||
(array[index+1] & 0xff) << 16 |
|
||||
(array[index+2] & 0xff) << 8 |
|
||||
(array[index+3] & 0xff) << 0;
|
||||
(array[index + 1] & 0xff) << 16 |
|
||||
(array[index + 2] & 0xff) << 8 |
|
||||
(array[index + 3] & 0xff) << 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int index) {
|
||||
return ((long) array[index] & 0xff) << 56 |
|
||||
((long) array[index+1] & 0xff) << 48 |
|
||||
((long) array[index+2] & 0xff) << 40 |
|
||||
((long) array[index+3] & 0xff) << 32 |
|
||||
((long) array[index+4] & 0xff) << 24 |
|
||||
((long) array[index+5] & 0xff) << 16 |
|
||||
((long) array[index+6] & 0xff) << 8 |
|
||||
((long) array[index+7] & 0xff) << 0;
|
||||
((long) array[index + 1] & 0xff) << 48 |
|
||||
((long) array[index + 2] & 0xff) << 40 |
|
||||
((long) array[index + 3] & 0xff) << 32 |
|
||||
((long) array[index + 4] & 0xff) << 24 |
|
||||
((long) array[index + 5] & 0xff) << 16 |
|
||||
((long) array[index + 6] & 0xff) << 8 |
|
||||
((long) array[index + 7] & 0xff) << 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShort(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 8);
|
||||
array[index+1] = (byte) (value >>> 0);
|
||||
array[index] = (byte) (value >>> 8);
|
||||
array[index + 1] = (byte) (value >>> 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMedium(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 16);
|
||||
array[index+1] = (byte) (value >>> 8);
|
||||
array[index+2] = (byte) (value >>> 0);
|
||||
array[index] = (byte) (value >>> 16);
|
||||
array[index + 1] = (byte) (value >>> 8);
|
||||
array[index + 2] = (byte) (value >>> 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInt(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 24);
|
||||
array[index+1] = (byte) (value >>> 16);
|
||||
array[index+2] = (byte) (value >>> 8);
|
||||
array[index+3] = (byte) (value >>> 0);
|
||||
array[index] = (byte) (value >>> 24);
|
||||
array[index + 1] = (byte) (value >>> 16);
|
||||
array[index + 2] = (byte) (value >>> 8);
|
||||
array[index + 3] = (byte) (value >>> 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLong(int index, long value) {
|
||||
array[index ] = (byte) (value >>> 56);
|
||||
array[index+1] = (byte) (value >>> 48);
|
||||
array[index+2] = (byte) (value >>> 40);
|
||||
array[index+3] = (byte) (value >>> 32);
|
||||
array[index+4] = (byte) (value >>> 24);
|
||||
array[index+5] = (byte) (value >>> 16);
|
||||
array[index+6] = (byte) (value >>> 8);
|
||||
array[index+7] = (byte) (value >>> 0);
|
||||
array[index] = (byte) (value >>> 56);
|
||||
array[index + 1] = (byte) (value >>> 48);
|
||||
array[index + 2] = (byte) (value >>> 40);
|
||||
array[index + 3] = (byte) (value >>> 32);
|
||||
array[index + 4] = (byte) (value >>> 24);
|
||||
array[index + 5] = (byte) (value >>> 16);
|
||||
array[index + 6] = (byte) (value >>> 8);
|
||||
array[index + 7] = (byte) (value >>> 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,8 +108,8 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
@Override
|
||||
public int getUnsignedMedium(int index) {
|
||||
return (getByte(index) & 0xff) << 16 |
|
||||
(getByte(index+1) & 0xff) << 8 |
|
||||
(getByte(index+2) & 0xff) << 0;
|
||||
(getByte(index + 1) & 0xff) << 8 |
|
||||
(getByte(index + 2) & 0xff) << 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -173,8 +173,8 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
@Override
|
||||
public void setMedium(int index, int value) {
|
||||
setByte(index, (byte) (value >>> 16));
|
||||
setByte(index+1, (byte) (value >>> 8));
|
||||
setByte(index+2, (byte) (value >>> 0));
|
||||
setByte(index + 1, (byte) (value >>> 8));
|
||||
setByte(index + 2, (byte) (value >>> 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +47,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <pre>
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
* for (int i = 0; i < buffer.capacity(); i ++</strong>) {
|
||||
* for (int i = 0; i < buffer.capacity(); i ++) {
|
||||
* byte b = buffer.getByte(i);
|
||||
* System.out.println((char) b);
|
||||
* }
|
||||
|
@ -84,7 +84,7 @@ import io.netty.util.CharsetUtil;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates
|
||||
*/
|
||||
public class ChannelBuffers {
|
||||
public final class ChannelBuffers {
|
||||
|
||||
/**
|
||||
* Big endian byte order.
|
||||
@ -307,7 +307,11 @@ public class ChannelBuffers {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
if (buffer.hasArray()) {
|
||||
return wrappedBuffer(buffer.order(), buffer.array(), buffer.arrayOffset() + buffer.position(),buffer.remaining());
|
||||
return wrappedBuffer(
|
||||
buffer.order(),
|
||||
buffer.array(),
|
||||
buffer.arrayOffset() + buffer.position(),
|
||||
buffer.remaining());
|
||||
} else {
|
||||
return new ByteBufferBackedChannelBuffer(buffer);
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
setByte(index + 2, (byte) value);
|
||||
} else {
|
||||
setShort(index , (short) value);
|
||||
setByte (index + 2, (byte) (value >>> 16));
|
||||
setByte(index + 2, (byte) (value >>> 16));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,9 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private final Object bigEndianLock = new Object();
|
||||
private final Object littleEndianLock = new Object();
|
||||
private final int preallocatedBufferCapacity;
|
||||
private ChannelBuffer preallocatedBigEndianBuffer = null;
|
||||
private ChannelBuffer preallocatedBigEndianBuffer;
|
||||
private int preallocatedBigEndianBufferPosition;
|
||||
private ChannelBuffer preallocatedLittleEndianBuffer = null;
|
||||
private ChannelBuffer preallocatedLittleEndianBuffer;
|
||||
private int preallocatedLittleEndianBufferPosition;
|
||||
|
||||
/**
|
||||
|
@ -59,67 +59,67 @@ public class LittleEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
|
||||
@Override
|
||||
public short getShort(int index) {
|
||||
return (short) (array[index] & 0xFF | array[index+1] << 8);
|
||||
return (short) (array[index] & 0xFF | array[index + 1] << 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedMedium(int index) {
|
||||
return (array[index ] & 0xff) << 0 |
|
||||
(array[index+1] & 0xff) << 8 |
|
||||
(array[index+2] & 0xff) << 16;
|
||||
return (array[index] & 0xff) << 0 |
|
||||
(array[index + 1] & 0xff) << 8 |
|
||||
(array[index + 2] & 0xff) << 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int index) {
|
||||
return (array[index ] & 0xff) << 0 |
|
||||
(array[index+1] & 0xff) << 8 |
|
||||
(array[index+2] & 0xff) << 16 |
|
||||
(array[index+3] & 0xff) << 24;
|
||||
return (array[index] & 0xff) << 0 |
|
||||
(array[index + 1] & 0xff) << 8 |
|
||||
(array[index + 2] & 0xff) << 16 |
|
||||
(array[index + 3] & 0xff) << 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int index) {
|
||||
return ((long) array[index] & 0xff) << 0 |
|
||||
((long) array[index+1] & 0xff) << 8 |
|
||||
((long) array[index+2] & 0xff) << 16 |
|
||||
((long) array[index+3] & 0xff) << 24 |
|
||||
((long) array[index+4] & 0xff) << 32 |
|
||||
((long) array[index+5] & 0xff) << 40 |
|
||||
((long) array[index+6] & 0xff) << 48 |
|
||||
((long) array[index+7] & 0xff) << 56;
|
||||
((long) array[index + 1] & 0xff) << 8 |
|
||||
((long) array[index + 2] & 0xff) << 16 |
|
||||
((long) array[index + 3] & 0xff) << 24 |
|
||||
((long) array[index + 4] & 0xff) << 32 |
|
||||
((long) array[index + 5] & 0xff) << 40 |
|
||||
((long) array[index + 6] & 0xff) << 48 |
|
||||
((long) array[index + 7] & 0xff) << 56;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShort(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 0);
|
||||
array[index+1] = (byte) (value >>> 8);
|
||||
array[index] = (byte) (value >>> 0);
|
||||
array[index + 1] = (byte) (value >>> 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMedium(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 0);
|
||||
array[index+1] = (byte) (value >>> 8);
|
||||
array[index+2] = (byte) (value >>> 16);
|
||||
array[index] = (byte) (value >>> 0);
|
||||
array[index + 1] = (byte) (value >>> 8);
|
||||
array[index + 2] = (byte) (value >>> 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInt(int index, int value) {
|
||||
array[index ] = (byte) (value >>> 0);
|
||||
array[index+1] = (byte) (value >>> 8);
|
||||
array[index+2] = (byte) (value >>> 16);
|
||||
array[index+3] = (byte) (value >>> 24);
|
||||
array[index] = (byte) (value >>> 0);
|
||||
array[index + 1] = (byte) (value >>> 8);
|
||||
array[index + 2] = (byte) (value >>> 16);
|
||||
array[index + 3] = (byte) (value >>> 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLong(int index, long value) {
|
||||
array[index ] = (byte) (value >>> 0);
|
||||
array[index+1] = (byte) (value >>> 8);
|
||||
array[index+2] = (byte) (value >>> 16);
|
||||
array[index+3] = (byte) (value >>> 24);
|
||||
array[index+4] = (byte) (value >>> 32);
|
||||
array[index+5] = (byte) (value >>> 40);
|
||||
array[index+6] = (byte) (value >>> 48);
|
||||
array[index+7] = (byte) (value >>> 56);
|
||||
array[index] = (byte) (value >>> 0);
|
||||
array[index + 1] = (byte) (value >>> 8);
|
||||
array[index + 2] = (byte) (value >>> 16);
|
||||
array[index + 3] = (byte) (value >>> 24);
|
||||
array[index + 4] = (byte) (value >>> 32);
|
||||
array[index + 5] = (byte) (value >>> 40);
|
||||
array[index + 6] = (byte) (value >>> 48);
|
||||
array[index + 7] = (byte) (value >>> 56);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +69,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
assertEquals(0, buffer.readerIndex());
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void readerIndexBoundaryCheck1() {
|
||||
try {
|
||||
buffer.writerIndex(0);
|
||||
@ -79,7 +79,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.readerIndex(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void readerIndexBoundaryCheck2() {
|
||||
try {
|
||||
buffer.writerIndex(buffer.capacity());
|
||||
@ -89,7 +89,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.readerIndex(buffer.capacity() + 1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void readerIndexBoundaryCheck3() {
|
||||
try {
|
||||
buffer.writerIndex(CAPACITY / 2);
|
||||
@ -107,12 +107,12 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.readerIndex(buffer.capacity());
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void writerIndexBoundaryCheck1() {
|
||||
buffer.writerIndex(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void writerIndexBoundaryCheck2() {
|
||||
try {
|
||||
buffer.writerIndex(CAPACITY);
|
||||
@ -123,7 +123,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.writerIndex(buffer.capacity() + 1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void writerIndexBoundaryCheck3() {
|
||||
try {
|
||||
buffer.writerIndex(CAPACITY);
|
||||
@ -141,72 +141,72 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.writerIndex(CAPACITY);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getBooleanBoundaryCheck1() {
|
||||
buffer.getBoolean(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getBooleanBoundaryCheck2() {
|
||||
buffer.getBoolean(buffer.capacity());
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getByteBoundaryCheck1() {
|
||||
buffer.getByte(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getByteBoundaryCheck2() {
|
||||
buffer.getByte(buffer.capacity());
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getShortBoundaryCheck1() {
|
||||
buffer.getShort(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getShortBoundaryCheck2() {
|
||||
buffer.getShort(buffer.capacity() - 1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getMediumBoundaryCheck1() {
|
||||
buffer.getMedium(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getMediumBoundaryCheck2() {
|
||||
buffer.getMedium(buffer.capacity() - 2);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getIntBoundaryCheck1() {
|
||||
buffer.getInt(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getIntBoundaryCheck2() {
|
||||
buffer.getInt(buffer.capacity() - 3);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getLongBoundaryCheck1() {
|
||||
buffer.getLong(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getLongBoundaryCheck2() {
|
||||
buffer.getLong(buffer.capacity() - 7);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getByteArrayBoundaryCheck1() {
|
||||
buffer.getBytes(-1, new byte[0]);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getByteArrayBoundaryCheck2() {
|
||||
buffer.getBytes(-1, new byte[0], 0, 0);
|
||||
}
|
||||
@ -247,42 +247,42 @@ public abstract class AbstractChannelBufferTest {
|
||||
assertEquals(0, dst[3]);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getByteBufferBoundaryCheck() {
|
||||
buffer.getBytes(-1, ByteBuffer.allocate(0));
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void copyBoundaryCheck1() {
|
||||
buffer.copy(-1, 0);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void copyBoundaryCheck2() {
|
||||
buffer.copy(0, buffer.capacity() + 1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void copyBoundaryCheck3() {
|
||||
buffer.copy(buffer.capacity() + 1, 0);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void copyBoundaryCheck4() {
|
||||
buffer.copy(buffer.capacity(), 1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void setIndexBoundaryCheck1() {
|
||||
buffer.setIndex(-1, CAPACITY);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void setIndexBoundaryCheck2() {
|
||||
buffer.setIndex(CAPACITY / 2, CAPACITY / 4);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void setIndexBoundaryCheck3() {
|
||||
buffer.setIndex(0, CAPACITY + 1);
|
||||
}
|
||||
@ -309,7 +309,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
assertEquals(0, dst.get(3));
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void getDirectByteBufferBoundaryCheck() {
|
||||
buffer.getBytes(-1, ByteBuffer.allocateDirect(0));
|
||||
}
|
||||
@ -754,7 +754,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
@Test
|
||||
public void testRandomByteArrayTransfer1() {
|
||||
byte[] value= new byte[BLOCK_SIZE];
|
||||
byte[] value = new byte[BLOCK_SIZE];
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(value);
|
||||
buffer.setBytes(i, value);
|
||||
@ -774,7 +774,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
@Test
|
||||
public void testRandomByteArrayTransfer2() {
|
||||
byte[] value= new byte[BLOCK_SIZE * 2];
|
||||
byte[] value = new byte[BLOCK_SIZE * 2];
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(value);
|
||||
buffer.setBytes(i, value, random.nextInt(BLOCK_SIZE), BLOCK_SIZE);
|
||||
@ -891,7 +891,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
@Test
|
||||
public void testSequentialByteArrayTransfer1() {
|
||||
byte[] value= new byte[BLOCK_SIZE];
|
||||
byte[] value = new byte[BLOCK_SIZE];
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(value);
|
||||
@ -926,7 +926,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
}
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValue= new byte[BLOCK_SIZE * 2];
|
||||
byte[] expectedValue = new byte[BLOCK_SIZE * 2];
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValue);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
|
@ -102,16 +102,16 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
b.skipBytes(6);
|
||||
b.markReaderIndex();
|
||||
assertEquals(a.readerIndex(), b.readerIndex());
|
||||
a.readerIndex(a.readerIndex()-1);
|
||||
b.readerIndex(b.readerIndex()-1);
|
||||
a.readerIndex(a.readerIndex() - 1);
|
||||
b.readerIndex(b.readerIndex() - 1);
|
||||
assertEquals(a.readerIndex(), b.readerIndex());
|
||||
a.writerIndex(a.writerIndex()-1);
|
||||
a.writerIndex(a.writerIndex() - 1);
|
||||
a.markWriterIndex();
|
||||
b.writerIndex(b.writerIndex()-1);
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.markWriterIndex();
|
||||
assertEquals(a.writerIndex(), b.writerIndex());
|
||||
a.writerIndex(a.writerIndex()+1);
|
||||
b.writerIndex(b.writerIndex()+1);
|
||||
a.writerIndex(a.writerIndex() + 1);
|
||||
b.writerIndex(b.writerIndex() + 1);
|
||||
assertEquals(a.writerIndex(), b.writerIndex());
|
||||
assertTrue(ChannelBuffers.equals(a, b));
|
||||
// now discard
|
||||
@ -256,7 +256,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }, new byte[1]));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-1);
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 2 }));
|
||||
assertFalse(ChannelBuffers.equals(a, b));
|
||||
@ -265,7 +265,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }, new byte[2]));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-2);
|
||||
b.writerIndex(b.writerIndex() - 2);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 2 }));
|
||||
b.writeBytes(wrappedBuffer(order, new byte[] { 3 }));
|
||||
@ -275,7 +275,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 1, 3));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-1);
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
|
||||
assertTrue(ChannelBuffers.equals(a, b));
|
||||
@ -284,7 +284,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2 }, new byte[1]));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-1);
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 4 }));
|
||||
assertFalse(ChannelBuffers.equals(a, b));
|
||||
@ -293,7 +293,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 1, 3));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-1);
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
|
||||
assertFalse(ChannelBuffers.equals(a, b));
|
||||
@ -302,7 +302,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 }, new byte[7]));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-7);
|
||||
b.writerIndex(b.writerIndex() - 7);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 4, 5, 6 }));
|
||||
b.writeBytes(
|
||||
@ -313,7 +313,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-5);
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
|
||||
assertTrue(ChannelBuffers.equals(a, b));
|
||||
@ -322,7 +322,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 6 }, new byte[5]));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-5);
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
|
||||
assertFalse(ChannelBuffers.equals(a, b));
|
||||
@ -331,7 +331,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex()-5);
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
|
||||
assertFalse(ChannelBuffers.equals(a, b));
|
||||
|
55
build/pom.xml
Normal file
55
build/pom.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2011 The Netty Project
|
||||
~
|
||||
~ The Netty Project 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-parent</artifactId>
|
||||
<version>4.0.0.Alpha1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-build</artifactId>
|
||||
<version>1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Netty/Build</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>5.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>check-style</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.netty.build.checkstyle;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
|
||||
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
|
||||
import com.puppycrawl.tools.checkstyle.api.Filter;
|
||||
import com.puppycrawl.tools.checkstyle.api.FilterSet;
|
||||
|
||||
public class SuppressionFilter extends AutomaticBean implements Filter {
|
||||
|
||||
private FilterSet filters = new FilterSet();
|
||||
private Pattern pattern;
|
||||
|
||||
public void setPattern(String pattern) {
|
||||
this.pattern = Pattern.compile(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(AuditEvent evt) {
|
||||
return !pattern.matcher(evt.getFileName()).find();
|
||||
}
|
||||
}
|
202
build/src/main/resources/io/netty/LICENSE.txt
Normal file
202
build/src/main/resources/io/netty/LICENSE.txt
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed 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.
|
83
build/src/main/resources/io/netty/checkstyle.xml
Normal file
83
build/src/main/resources/io/netty/checkstyle.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
<module name="Checker">
|
||||
<module name="io.netty.build.checkstyle.SuppressionFilter">
|
||||
<property name="pattern" value="(test[^/]*/.*|LocalTimeProtocol|LinkedTransferQueue|jzlib/.*|com/sun/nio/sctp/.*)\.java" />
|
||||
</module>
|
||||
<module name="FileTabCharacter"/>
|
||||
<module name="JavadocPackage"/>
|
||||
<module name="NewlineAtEndOfFile"/>
|
||||
<module name="RegexpSingleline">
|
||||
<property name="format" value="@(author|version)"/>
|
||||
<property name="ignoreCase" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND, DEC, INC"/>
|
||||
</module>
|
||||
<!-- Commented out due to false positives.
|
||||
<module name="MissingDeprecated"/>
|
||||
-->
|
||||
<module name="MissingOverride"/>
|
||||
<module name="PackageAnnotation"/>
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="text"/>
|
||||
</module>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="RightCurly"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="AvoidNestedBlocks">
|
||||
<property name="allowInSwitchCase" value="true"/>
|
||||
</module>
|
||||
<module name="FinalClass"/>
|
||||
<module name="InterfaceIsType"/>
|
||||
<module name="HideUtilityClassConstructor"/>
|
||||
<module name="CovariantEquals"/>
|
||||
<module name="DoubleCheckedLocking"/>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<!--
|
||||
<module name="FinalLocalVariable"/>
|
||||
-->
|
||||
<module name="RedundantThrows">
|
||||
<property name="logLoadErrors" value="false"/>
|
||||
<property name="suppressLoadErrors" value="true"/>
|
||||
</module>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
<module name="NoFinalizer"/>
|
||||
<module name="SuperClone"/>
|
||||
<module name="SuperFinalize"/>
|
||||
<module name="PackageDeclaration"/>
|
||||
<module name="ExplicitInitialization"/>
|
||||
<module name="DefaultComesLast"/>
|
||||
<module name="UnnecessaryParentheses"/>
|
||||
<module name="AvoidStarImport">
|
||||
<property name="allowStaticMemberImports" value="true"/>
|
||||
</module>
|
||||
<module name="RedundantImport"/>
|
||||
<!-- Commented out due to false positives.
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
</module>
|
||||
-->
|
||||
<module name="JavadocStyle">
|
||||
<property name="checkFirstSentence" value="false"/>
|
||||
</module>
|
||||
<module name="UpperEll"/>
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="OuterTypeFilename"/>
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="RedundantModifier"/>
|
||||
<module name="GenericWhitespace"/>
|
||||
<module name="EmptyForInitializerPad"/>
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
</module>
|
||||
</module>
|
@ -32,14 +32,11 @@ import io.netty.buffer.ChannelBuffers;
|
||||
*/
|
||||
public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
||||
|
||||
protected File file = null;
|
||||
protected File file;
|
||||
private boolean isRenamed;
|
||||
private FileChannel fileChannel;
|
||||
|
||||
private boolean isRenamed = false;
|
||||
|
||||
private FileChannel fileChannel = null;
|
||||
|
||||
public AbstractDiskHttpData(String name, Charset charset, long size)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
public AbstractDiskHttpData(String name, Charset charset, long size) {
|
||||
super(name, charset, size);
|
||||
}
|
||||
|
||||
@ -191,7 +188,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
||||
file = tempFile();
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
FileChannel localfileChannel = outputStream.getChannel();
|
||||
byte[] bytes = new byte[4096*4];
|
||||
byte[] bytes = new byte[4096 * 4];
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
||||
int read = inputStream.read(bytes);
|
||||
int written = 0;
|
||||
|
@ -23,17 +23,12 @@ import java.nio.charset.Charset;
|
||||
public abstract class AbstractHttpData implements HttpData {
|
||||
|
||||
protected final String name;
|
||||
|
||||
protected long definedSize = 0;
|
||||
|
||||
protected long size = 0;
|
||||
|
||||
protected long definedSize;
|
||||
protected long size;
|
||||
protected Charset charset = HttpCodecUtil.DEFAULT_CHARSET;
|
||||
protected boolean completed;
|
||||
|
||||
protected boolean completed = false;
|
||||
|
||||
public AbstractHttpData(String name, Charset charset, long size)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
public AbstractHttpData(String name, Charset charset, long size) {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name");
|
||||
}
|
||||
|
@ -32,14 +32,11 @@ import io.netty.buffer.ChannelBuffers;
|
||||
*/
|
||||
public abstract class AbstractMemoryHttpData extends AbstractHttpData {
|
||||
|
||||
private ChannelBuffer channelBuffer = null;
|
||||
private ChannelBuffer channelBuffer;
|
||||
private int chunkPosition;
|
||||
protected boolean isRenamed;
|
||||
|
||||
private int chunkPosition = 0;
|
||||
|
||||
protected boolean isRenamed = false;
|
||||
|
||||
public AbstractMemoryHttpData(String name, Charset charset, long size)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
public AbstractMemoryHttpData(String name, Charset charset, long size) {
|
||||
super(name, charset, size);
|
||||
}
|
||||
|
||||
@ -64,7 +61,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
|
||||
throw new NullPointerException("inputStream");
|
||||
}
|
||||
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
|
||||
byte[] bytes = new byte[4096*4];
|
||||
byte[] bytes = new byte[4096 * 4];
|
||||
int read = inputStream.read(bytes);
|
||||
int written = 0;
|
||||
while (read > 0) {
|
||||
|
@ -41,10 +41,10 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class CookieDecoder {
|
||||
|
||||
private final static Pattern PATTERN =
|
||||
private static final Pattern PATTERN =
|
||||
Pattern.compile("(?:\\s|[;,])*\\$*([^;=]+)(?:=(?:[\"']((?:\\\\.|[^\"])*)[\"']|([^;,]*)))?(\\s*(?:[;,]+\\s*|$))");
|
||||
|
||||
private final static String COMMA = ",";
|
||||
private static final String COMMA = ",";
|
||||
|
||||
private final boolean lenient;
|
||||
|
||||
|
@ -145,7 +145,7 @@ public class CookieEncoder {
|
||||
addQuoted(sb, CookieHeaderNames.COMMENTURL, cookie.getCommentUrl());
|
||||
}
|
||||
|
||||
if(!cookie.getPorts().isEmpty()) {
|
||||
if (!cookie.getPorts().isEmpty()) {
|
||||
sb.append(CookieHeaderNames.PORT);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
@ -189,7 +189,7 @@ public class CookieEncoder {
|
||||
}
|
||||
|
||||
if (cookie.getVersion() >= 1) {
|
||||
if(!cookie.getPorts().isEmpty()) {
|
||||
if (!cookie.getPorts().isEmpty()) {
|
||||
sb.append('$');
|
||||
sb.append(CookieHeaderNames.PORT);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
@ -204,8 +204,10 @@ public class CookieEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
if(sb.length() > 0)
|
||||
if (sb.length() > 0) {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,11 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
*/
|
||||
public static long MINSIZE = 0x4000;
|
||||
|
||||
private boolean useDisk = false;
|
||||
private boolean useDisk;
|
||||
|
||||
private boolean checkSize = false;
|
||||
private boolean checkSize;
|
||||
|
||||
private long minSize = 0L;
|
||||
private long minSize;
|
||||
|
||||
/**
|
||||
* Keep all HttpDatas until cleanAllHttpDatas() is called.
|
||||
@ -91,8 +91,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute createAttribute(HttpRequest request, String name) throws NullPointerException,
|
||||
IllegalArgumentException {
|
||||
public Attribute createAttribute(HttpRequest request, String name) {
|
||||
if (useDisk) {
|
||||
Attribute attribute = new DiskAttribute(name);
|
||||
List<HttpData> fileToDelete = getList(request);
|
||||
@ -111,8 +110,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
* @see io.netty.handler.codec.http2.HttpDataFactory#createAttribute(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Attribute createAttribute(HttpRequest request, String name, String value)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
public Attribute createAttribute(HttpRequest request, String name, String value) {
|
||||
if (useDisk) {
|
||||
Attribute attribute;
|
||||
try {
|
||||
@ -143,7 +141,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
@Override
|
||||
public FileUpload createFileUpload(HttpRequest request, String name, String filename,
|
||||
String contentType, String contentTransferEncoding, Charset charset,
|
||||
long size) throws NullPointerException, IllegalArgumentException {
|
||||
long size) {
|
||||
if (useDisk) {
|
||||
FileUpload fileUpload = new DiskFileUpload(name, filename, contentType,
|
||||
contentTransferEncoding, charset, size);
|
||||
|
@ -24,7 +24,7 @@ import io.netty.buffer.ChannelBuffers;
|
||||
* Disk implementation of Attributes
|
||||
*/
|
||||
public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
public static String baseDirectory = null;
|
||||
public static String baseDirectory;
|
||||
|
||||
public static boolean deleteOnExitTemporaryFile = true;
|
||||
|
||||
@ -47,8 +47,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IOException
|
||||
*/
|
||||
public DiskAttribute(String name, String value)
|
||||
throws NullPointerException, IllegalArgumentException, IOException {
|
||||
public DiskAttribute(String name, String value) throws IOException {
|
||||
super(name, HttpCodecUtil.DEFAULT_CHARSET, 0); // Attribute have no default size
|
||||
setValue(value);
|
||||
}
|
||||
@ -133,7 +132,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
|
||||
@Override
|
||||
protected String getDiskFilename() {
|
||||
return getName()+postfix;
|
||||
return getName() + postfix;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ import java.nio.charset.Charset;
|
||||
* Disk FileUpload implementation that stores file into real files
|
||||
*/
|
||||
public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
||||
public static String baseDirectory = null;
|
||||
public static String baseDirectory;
|
||||
|
||||
public static boolean deleteOnExitTemporaryFile = true;
|
||||
|
||||
@ -30,15 +30,14 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
||||
|
||||
public static String postfix = ".tmp";
|
||||
|
||||
private String filename = null;
|
||||
private String filename;
|
||||
|
||||
private String contentType = null;
|
||||
private String contentType;
|
||||
|
||||
private String contentTransferEncoding = null;
|
||||
private String contentTransferEncoding;
|
||||
|
||||
public DiskFileUpload(String name, String filename, String contentType,
|
||||
String contentTransferEncoding, Charset charset, long size)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
String contentTransferEncoding, Charset charset, long size) {
|
||||
super(name, charset, size);
|
||||
setFilename(filename);
|
||||
setContentType(contentType);
|
||||
@ -127,12 +126,12 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\"" + getName() +
|
||||
"\"; "+HttpPostBodyUtil.FILENAME+"=\"" + filename + "\"\r\n" +
|
||||
HttpHeaders.Names.CONTENT_TYPE+": " + contentType +
|
||||
(charset != null? "; "+HttpHeaders.Values.CHARSET+"=" + charset + "\r\n" : "\r\n") +
|
||||
HttpHeaders.Names.CONTENT_LENGTH+": " + length() + "\r\n" +
|
||||
return HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" + getName() +
|
||||
"\"; " + HttpPostBodyUtil.FILENAME + "=\"" + filename + "\"\r\n" +
|
||||
HttpHeaders.Names.CONTENT_TYPE + ": " + contentType +
|
||||
(charset != null? "; " + HttpHeaders.Values.CHARSET + "=" + charset + "\r\n" : "\r\n") +
|
||||
HttpHeaders.Names.CONTENT_LENGTH + ": " + length() + "\r\n" +
|
||||
"Completed: " + isCompleted() +
|
||||
"\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " +
|
||||
file.getAbsolutePath() + " DefaultDeleteAfter: " +
|
||||
|
@ -22,7 +22,7 @@ import io.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
*/
|
||||
class HttpCodecUtil {
|
||||
final class HttpCodecUtil {
|
||||
//space ' '
|
||||
static final byte SP = 32;
|
||||
|
||||
|
@ -29,8 +29,7 @@ public interface HttpDataFactory {
|
||||
* @throws NullPointerException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
Attribute createAttribute(HttpRequest request, String name)
|
||||
throws NullPointerException, IllegalArgumentException;
|
||||
Attribute createAttribute(HttpRequest request, String name);
|
||||
|
||||
/**
|
||||
*
|
||||
@ -41,8 +40,7 @@ public interface HttpDataFactory {
|
||||
* @throws NullPointerException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
Attribute createAttribute(HttpRequest request, String name, String value)
|
||||
throws NullPointerException, IllegalArgumentException;
|
||||
Attribute createAttribute(HttpRequest request, String name, String value);
|
||||
|
||||
/**
|
||||
*
|
||||
@ -56,7 +54,7 @@ public interface HttpDataFactory {
|
||||
*/
|
||||
FileUpload createFileUpload(HttpRequest request, String name, String filename,
|
||||
String contentType, String contentTransferEncoding, Charset charset,
|
||||
long size) throws NullPointerException, IllegalArgumentException;
|
||||
long size);
|
||||
|
||||
/**
|
||||
* Remove the given InterfaceHttpData from clean list (will not delete the file, except if the file
|
||||
|
@ -49,7 +49,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "Accept-Encoding"}
|
||||
*/
|
||||
public static final String ACCEPT_ENCODING= "Accept-Encoding";
|
||||
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
||||
/**
|
||||
* {@code "Accept-Language"}
|
||||
*/
|
||||
@ -57,11 +57,11 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "Accept-Ranges"}
|
||||
*/
|
||||
public static final String ACCEPT_RANGES= "Accept-Ranges";
|
||||
public static final String ACCEPT_RANGES = "Accept-Ranges";
|
||||
/**
|
||||
* {@code "Accept-Patch"}
|
||||
*/
|
||||
public static final String ACCEPT_PATCH= "Accept-Patch";
|
||||
public static final String ACCEPT_PATCH = "Accept-Patch";
|
||||
/**
|
||||
* {@code "Age"}
|
||||
*/
|
||||
@ -93,7 +93,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "Content-Language"}
|
||||
*/
|
||||
public static final String CONTENT_LANGUAGE= "Content-Language";
|
||||
public static final String CONTENT_LANGUAGE = "Content-Language";
|
||||
/**
|
||||
* {@code "Content-Length"}
|
||||
*/
|
||||
@ -117,7 +117,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "Content-Type"}
|
||||
*/
|
||||
public static final String CONTENT_TYPE= "Content-Type";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
/**
|
||||
* {@code "Cookie"}
|
||||
*/
|
||||
@ -161,7 +161,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "If-Range"}
|
||||
*/
|
||||
public static final String IF_RANGE= "If-Range";
|
||||
public static final String IF_RANGE = "If-Range";
|
||||
/**
|
||||
* {@code "If-Unmodified-Since"}
|
||||
*/
|
||||
|
@ -568,11 +568,9 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
if (nextByte == HttpCodecUtil.LF) {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
else if (nextByte == HttpCodecUtil.LF) {
|
||||
} else if (nextByte == HttpCodecUtil.LF) {
|
||||
return sb.toString();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (lineLength >= maxLineLength) {
|
||||
// TODO: Respond with Bad Request and discard the traffic
|
||||
// or close the connection.
|
||||
|
@ -23,7 +23,8 @@ import io.netty.util.CharsetUtil;
|
||||
/**
|
||||
* Shared Static object between HttpMessageDecoder, HttpPostRequestDecoder and HttpPostRequestEncoder
|
||||
*/
|
||||
public class HttpPostBodyUtil {
|
||||
final class HttpPostBodyUtil {
|
||||
|
||||
public static int chunkSize = 8096;
|
||||
/**
|
||||
* HTTP content disposition header name.
|
||||
|
@ -50,12 +50,12 @@ public class HttpPostRequestDecoder {
|
||||
/**
|
||||
* Does request have a body to decode
|
||||
*/
|
||||
private boolean bodyToDecode = false;
|
||||
private boolean bodyToDecode;
|
||||
|
||||
/**
|
||||
* Does the last chunk already received
|
||||
*/
|
||||
private boolean isLastChunk = false;
|
||||
private boolean isLastChunk;
|
||||
|
||||
/**
|
||||
* HttpDatas from Body
|
||||
@ -71,28 +71,28 @@ public class HttpPostRequestDecoder {
|
||||
/**
|
||||
* The current channelBuffer
|
||||
*/
|
||||
private ChannelBuffer undecodedChunk = null;
|
||||
private ChannelBuffer undecodedChunk;
|
||||
|
||||
/**
|
||||
* Does this request is a Multipart request
|
||||
*/
|
||||
private boolean isMultipart = false;
|
||||
private boolean isMultipart;
|
||||
|
||||
/**
|
||||
* Body HttpDatas current position
|
||||
*/
|
||||
private int bodyListHttpDataRank = 0;
|
||||
private int bodyListHttpDataRank;
|
||||
|
||||
/**
|
||||
* If multipart, this is the boundary for the flobal multipart
|
||||
*/
|
||||
private String multipartDataBoundary = null;
|
||||
private String multipartDataBoundary;
|
||||
|
||||
/**
|
||||
* If multipart, there could be internal multiparts (mixed) to the global multipart.
|
||||
* Only one level is allowed.
|
||||
*/
|
||||
private String multipartMixedBoundary = null;
|
||||
private String multipartMixedBoundary;
|
||||
|
||||
/**
|
||||
* Current status
|
||||
@ -102,17 +102,17 @@ public class HttpPostRequestDecoder {
|
||||
/**
|
||||
* Used in Multipart
|
||||
*/
|
||||
private Map<String, Attribute> currentFieldAttributes = null;
|
||||
private Map<String, Attribute> currentFieldAttributes;
|
||||
|
||||
/**
|
||||
* The current FileUpload that is currently in decode process
|
||||
*/
|
||||
private FileUpload currentFileUpload = null;
|
||||
private FileUpload currentFileUpload;
|
||||
|
||||
/**
|
||||
* The current Attribute that is currently in decode process
|
||||
*/
|
||||
private Attribute currentAttribute = null;
|
||||
private Attribute currentAttribute;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -122,8 +122,7 @@ public class HttpPostRequestDecoder {
|
||||
* @throws ErrorDataDecoderException if the default charset was wrong when decoding or other errors
|
||||
*/
|
||||
public HttpPostRequestDecoder(HttpRequest request)
|
||||
throws ErrorDataDecoderException, IncompatibleDataDecoderException,
|
||||
NullPointerException {
|
||||
throws ErrorDataDecoderException, IncompatibleDataDecoderException {
|
||||
this(new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE),
|
||||
request, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
}
|
||||
@ -137,8 +136,7 @@ public class HttpPostRequestDecoder {
|
||||
* @throws ErrorDataDecoderException if the default charset was wrong when decoding or other errors
|
||||
*/
|
||||
public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request)
|
||||
throws ErrorDataDecoderException, IncompatibleDataDecoderException,
|
||||
NullPointerException {
|
||||
throws ErrorDataDecoderException, IncompatibleDataDecoderException {
|
||||
this(factory, request, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@ -153,7 +151,7 @@ public class HttpPostRequestDecoder {
|
||||
*/
|
||||
public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request,
|
||||
Charset charset) throws ErrorDataDecoderException,
|
||||
IncompatibleDataDecoderException, NullPointerException {
|
||||
IncompatibleDataDecoderException {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException("factory");
|
||||
}
|
||||
@ -446,9 +444,9 @@ public class HttpPostRequestDecoder {
|
||||
case DISPOSITION:// search '='
|
||||
if (read == '=') {
|
||||
currentStatus = MultiPartStatus.FIELD;
|
||||
equalpos = currentpos-1;
|
||||
equalpos = currentpos - 1;
|
||||
String key = decodeAttribute(
|
||||
undecodedChunk.toString(firstpos, equalpos-firstpos, charset),
|
||||
undecodedChunk.toString(firstpos, equalpos - firstpos, charset),
|
||||
charset);
|
||||
currentAttribute = factory.createAttribute(request, key);
|
||||
firstpos = currentpos;
|
||||
@ -467,8 +465,8 @@ public class HttpPostRequestDecoder {
|
||||
case FIELD:// search '&' or end of line
|
||||
if (read == '&') {
|
||||
currentStatus = MultiPartStatus.DISPOSITION;
|
||||
ampersandpos = currentpos-1;
|
||||
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos-firstpos));
|
||||
ampersandpos = currentpos - 1;
|
||||
setFinalBuffer(undecodedChunk.slice(firstpos, ampersandpos - firstpos));
|
||||
firstpos = currentpos;
|
||||
contRead = true;
|
||||
} else if (read == HttpCodecUtil.CR) {
|
||||
@ -477,9 +475,9 @@ public class HttpPostRequestDecoder {
|
||||
currentpos++;
|
||||
if (read == HttpCodecUtil.LF) {
|
||||
currentStatus = MultiPartStatus.PREEPILOGUE;
|
||||
ampersandpos = currentpos-2;
|
||||
ampersandpos = currentpos - 2;
|
||||
setFinalBuffer(
|
||||
undecodedChunk.slice(firstpos, ampersandpos-firstpos));
|
||||
undecodedChunk.slice(firstpos, ampersandpos - firstpos));
|
||||
firstpos = currentpos;
|
||||
contRead = false;
|
||||
} else {
|
||||
@ -492,9 +490,9 @@ public class HttpPostRequestDecoder {
|
||||
}
|
||||
} else if (read == HttpCodecUtil.LF) {
|
||||
currentStatus = MultiPartStatus.PREEPILOGUE;
|
||||
ampersandpos = currentpos-1;
|
||||
ampersandpos = currentpos - 1;
|
||||
setFinalBuffer(
|
||||
undecodedChunk.slice(firstpos, ampersandpos-firstpos));
|
||||
undecodedChunk.slice(firstpos, ampersandpos - firstpos));
|
||||
firstpos = currentpos;
|
||||
contRead = false;
|
||||
}
|
||||
@ -509,7 +507,7 @@ public class HttpPostRequestDecoder {
|
||||
ampersandpos = currentpos;
|
||||
if (ampersandpos > firstpos) {
|
||||
setFinalBuffer(
|
||||
undecodedChunk.slice(firstpos, ampersandpos-firstpos));
|
||||
undecodedChunk.slice(firstpos, ampersandpos - firstpos));
|
||||
} else if (! currentAttribute.isCompleted()) {
|
||||
setFinalBuffer(ChannelBuffers.EMPTY_BUFFER);
|
||||
}
|
||||
@ -521,7 +519,7 @@ public class HttpPostRequestDecoder {
|
||||
// reset index except if to continue in case of FIELD status
|
||||
if (currentStatus == MultiPartStatus.FIELD) {
|
||||
currentAttribute.addContent(
|
||||
undecodedChunk.slice(firstpos, currentpos-firstpos),
|
||||
undecodedChunk.slice(firstpos, currentpos - firstpos),
|
||||
false);
|
||||
firstpos = currentpos;
|
||||
}
|
||||
@ -1231,7 +1229,7 @@ public class HttpPostRequestDecoder {
|
||||
// so go back of delimiter size
|
||||
try {
|
||||
currentAttribute.addContent(
|
||||
undecodedChunk.slice(readerIndex, lastPosition-readerIndex),
|
||||
undecodedChunk.slice(readerIndex, lastPosition - readerIndex),
|
||||
true);
|
||||
} catch (IOException e) {
|
||||
throw new ErrorDataDecoderException(e);
|
||||
@ -1240,7 +1238,7 @@ public class HttpPostRequestDecoder {
|
||||
} else {
|
||||
try {
|
||||
currentAttribute.addContent(
|
||||
undecodedChunk.slice(readerIndex, lastPosition-readerIndex),
|
||||
undecodedChunk.slice(readerIndex, lastPosition - readerIndex),
|
||||
false);
|
||||
} catch (IOException e) {
|
||||
throw new ErrorDataDecoderException(e);
|
||||
|
@ -51,16 +51,16 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
/**
|
||||
* Chunked false by default
|
||||
*/
|
||||
private boolean isChunked = false;
|
||||
private boolean isChunked;
|
||||
|
||||
/**
|
||||
* InterfaceHttpData for Body (without encoding)
|
||||
*/
|
||||
private List<InterfaceHttpData> bodyListDatas = null;
|
||||
private List<InterfaceHttpData> bodyListDatas;
|
||||
/**
|
||||
* The final Multipart List of InterfaceHttpData including encoding
|
||||
*/
|
||||
private List<InterfaceHttpData> multipartHttpDatas = null;
|
||||
private List<InterfaceHttpData> multipartHttpDatas;
|
||||
|
||||
/**
|
||||
* Does this request is a Multipart request
|
||||
@ -70,17 +70,17 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
/**
|
||||
* If multipart, this is the boundary for the flobal multipart
|
||||
*/
|
||||
private String multipartDataBoundary = null;
|
||||
private String multipartDataBoundary;
|
||||
|
||||
/**
|
||||
* If multipart, there could be internal multiparts (mixed) to the global multipart.
|
||||
* Only one level is allowed.
|
||||
*/
|
||||
private String multipartMixedBoundary = null;
|
||||
private String multipartMixedBoundary;
|
||||
/**
|
||||
* To check if the header has been finalized
|
||||
*/
|
||||
private boolean headerFinalized = false;
|
||||
private boolean headerFinalized;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -90,7 +90,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the request is not a POST
|
||||
*/
|
||||
public HttpPostRequestEncoder(HttpRequest request, boolean multipart)
|
||||
throws ErrorDataEncoderException, NullPointerException {
|
||||
throws ErrorDataEncoderException {
|
||||
this(new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE),
|
||||
request, multipart, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
}
|
||||
@ -104,7 +104,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the request is not a POST
|
||||
*/
|
||||
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart)
|
||||
throws ErrorDataEncoderException, NullPointerException {
|
||||
throws ErrorDataEncoderException {
|
||||
this(factory, request, multipart, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@ -118,8 +118,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the request is not a POST
|
||||
*/
|
||||
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request,
|
||||
boolean multipart, Charset charset) throws ErrorDataEncoderException,
|
||||
NullPointerException {
|
||||
boolean multipart, Charset charset) throws ErrorDataEncoderException {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException("factory");
|
||||
}
|
||||
@ -157,24 +156,24 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
/**
|
||||
* Does the last non empty chunk already encoded so that next chunk will be empty (last chunk)
|
||||
*/
|
||||
private boolean isLastChunk = false;
|
||||
private boolean isLastChunk;
|
||||
/**
|
||||
* Last chunk already sent
|
||||
*/
|
||||
private boolean isLastChunkSent = false;
|
||||
private boolean isLastChunkSent;
|
||||
/**
|
||||
* The current FileUpload that is currently in encode process
|
||||
*/
|
||||
private FileUpload currentFileUpload = null;
|
||||
private FileUpload currentFileUpload;
|
||||
/**
|
||||
* While adding a FileUpload, is the multipart currently in Mixed Mode
|
||||
*/
|
||||
private boolean duringMixedMode = false;
|
||||
private boolean duringMixedMode;
|
||||
|
||||
/**
|
||||
* Global Body size
|
||||
*/
|
||||
private long globalBodySize = 0;
|
||||
private long globalBodySize;
|
||||
|
||||
/**
|
||||
* True if this request is a Multipart request
|
||||
@ -224,7 +223,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already done
|
||||
*/
|
||||
public void setBodyHttpDatas(List<InterfaceHttpData> datas)
|
||||
throws NullPointerException, ErrorDataEncoderException {
|
||||
throws ErrorDataEncoderException {
|
||||
if (datas == null) {
|
||||
throw new NullPointerException("datas");
|
||||
}
|
||||
@ -246,7 +245,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already done
|
||||
*/
|
||||
public void addBodyAttribute(String name, String value)
|
||||
throws NullPointerException, ErrorDataEncoderException {
|
||||
throws ErrorDataEncoderException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name");
|
||||
}
|
||||
@ -268,7 +267,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already done
|
||||
*/
|
||||
public void addBodyFileUpload(String name, File file, String contentType, boolean isText)
|
||||
throws NullPointerException, ErrorDataEncoderException {
|
||||
throws ErrorDataEncoderException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name");
|
||||
}
|
||||
@ -307,7 +306,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already done
|
||||
*/
|
||||
public void addBodyFileUploads(String name, File[] file, String[] contentType, boolean[] isText)
|
||||
throws NullPointerException, ErrorDataEncoderException {
|
||||
throws ErrorDataEncoderException {
|
||||
if (file.length != contentType.length && file.length != isText.length) {
|
||||
throw new NullPointerException("Different array length");
|
||||
}
|
||||
@ -323,7 +322,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
* @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already done
|
||||
*/
|
||||
public void addBodyHttpData(InterfaceHttpData data)
|
||||
throws NullPointerException, ErrorDataEncoderException {
|
||||
throws ErrorDataEncoderException {
|
||||
if (headerFinalized) {
|
||||
throw new ErrorDataEncoderException("Cannot add value once finalized");
|
||||
}
|
||||
@ -340,12 +339,12 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
String value = encodeAttribute(attribute.getValue(), charset);
|
||||
Attribute newattribute = factory.createAttribute(request, key, value);
|
||||
multipartHttpDatas.add(newattribute);
|
||||
globalBodySize += newattribute.getName().length()+1+
|
||||
newattribute.length()+1;
|
||||
globalBodySize += newattribute.getName().length() + 1 +
|
||||
newattribute.length() + 1;
|
||||
} catch (IOException e) {
|
||||
throw new ErrorDataEncoderException(e);
|
||||
}
|
||||
} else if (data instanceof FileUpload){
|
||||
} else if (data instanceof FileUpload) {
|
||||
// since not Multipart, only name=filename => Attribute
|
||||
FileUpload fileUpload = (FileUpload) data;
|
||||
// name=filename& with encoded name and filename
|
||||
@ -353,8 +352,8 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
String value = encodeAttribute(fileUpload.getFilename(), charset);
|
||||
Attribute newattribute = factory.createAttribute(request, key, value);
|
||||
multipartHttpDatas.add(newattribute);
|
||||
globalBodySize += newattribute.getName().length()+1+
|
||||
newattribute.length()+1;
|
||||
globalBodySize += newattribute.getName().length() + 1 +
|
||||
newattribute.length() + 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -393,7 +392,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
if (data instanceof Attribute) {
|
||||
if (duringMixedMode) {
|
||||
InternalAttribute internal = new InternalAttribute();
|
||||
internal.addValue("\r\n--"+multipartMixedBoundary+"--");
|
||||
internal.addValue("\r\n--" + multipartMixedBoundary + "--");
|
||||
multipartHttpDatas.add(internal);
|
||||
multipartMixedBoundary = null;
|
||||
currentFileUpload = null;
|
||||
@ -404,24 +403,24 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
// previously a data field so CRLF
|
||||
internal.addValue("\r\n");
|
||||
}
|
||||
internal.addValue("--"+multipartDataBoundary+"\r\n");
|
||||
internal.addValue("--" + multipartDataBoundary + "\r\n");
|
||||
// content-disposition: form-data; name="field1"
|
||||
Attribute attribute = (Attribute) data;
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FORM_DATA+"; "+
|
||||
HttpPostBodyUtil.NAME+"=\""+
|
||||
encodeAttribute(attribute.getName(), charset)+"\"\r\n");
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FORM_DATA + "; " +
|
||||
HttpPostBodyUtil.NAME + "=\"" +
|
||||
encodeAttribute(attribute.getName(), charset) + "\"\r\n");
|
||||
Charset localcharset = attribute.getCharset();
|
||||
if (localcharset != null) {
|
||||
// Content-Type: charset=charset
|
||||
internal.addValue(HttpHeaders.Names.CONTENT_TYPE+": "+
|
||||
HttpHeaders.Values.CHARSET+"="+localcharset+"\r\n");
|
||||
internal.addValue(HttpHeaders.Names.CONTENT_TYPE + ": " +
|
||||
HttpHeaders.Values.CHARSET + "=" + localcharset + "\r\n");
|
||||
}
|
||||
// CRLF between body header and data
|
||||
internal.addValue("\r\n");
|
||||
multipartHttpDatas.add(internal);
|
||||
multipartHttpDatas.add(data);
|
||||
globalBodySize += attribute.length()+internal.size();
|
||||
globalBodySize += attribute.length() + internal.size();
|
||||
} else if (data instanceof FileUpload) {
|
||||
FileUpload fileUpload = (FileUpload) data;
|
||||
InternalAttribute internal = new InternalAttribute();
|
||||
@ -441,7 +440,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
|
||||
// add endmixedmultipart delimiter, multipart body header and
|
||||
// Data to multipart list
|
||||
internal.addValue("--"+multipartMixedBoundary+"--");
|
||||
internal.addValue("--" + multipartMixedBoundary + "--");
|
||||
multipartHttpDatas.add(internal);
|
||||
multipartMixedBoundary = null;
|
||||
// start a new one (could be replaced if mixed start again from here
|
||||
@ -475,19 +474,19 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
// Content-Type: text/plain
|
||||
initMixedMultipart();
|
||||
InternalAttribute pastAttribute =
|
||||
(InternalAttribute) multipartHttpDatas.get(multipartHttpDatas.size()-2);
|
||||
(InternalAttribute) multipartHttpDatas.get(multipartHttpDatas.size() - 2);
|
||||
// remove past size
|
||||
globalBodySize -= pastAttribute.size();
|
||||
String replacement = HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\""+
|
||||
encodeAttribute(fileUpload.getName(), charset)+"\"\r\n";
|
||||
replacement += HttpHeaders.Names.CONTENT_TYPE+": "+
|
||||
HttpPostBodyUtil.MULTIPART_MIXED+"; "+HttpHeaders.Values.BOUNDARY+
|
||||
"="+multipartMixedBoundary+"\r\n\r\n";
|
||||
replacement += "--"+multipartMixedBoundary+"\r\n";
|
||||
replacement += HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FILE+"; "+HttpPostBodyUtil.FILENAME+"=\""+
|
||||
encodeAttribute(fileUpload.getFilename(), charset)+
|
||||
String replacement = HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" +
|
||||
encodeAttribute(fileUpload.getName(), charset) + "\"\r\n";
|
||||
replacement += HttpHeaders.Names.CONTENT_TYPE + ": " +
|
||||
HttpPostBodyUtil.MULTIPART_MIXED + "; " + HttpHeaders.Values.BOUNDARY +
|
||||
"=" + multipartMixedBoundary + "\r\n\r\n";
|
||||
replacement += "--" + multipartMixedBoundary + "\r\n";
|
||||
replacement += HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FILE + "; " + HttpPostBodyUtil.FILENAME + "=\"" +
|
||||
encodeAttribute(fileUpload.getFilename(), charset) +
|
||||
"\"\r\n";
|
||||
pastAttribute.setValue(replacement, 1);
|
||||
// update past size
|
||||
@ -510,51 +509,51 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
if (localMixed) {
|
||||
// add mixedmultipart delimiter, mixedmultipart body header and
|
||||
// Data to multipart list
|
||||
internal.addValue("--"+multipartMixedBoundary+"\r\n");
|
||||
internal.addValue("--" + multipartMixedBoundary + "\r\n");
|
||||
// Content-Disposition: file; filename="file1.txt"
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FILE+"; "+HttpPostBodyUtil.FILENAME+"=\""+
|
||||
encodeAttribute(fileUpload.getFilename(), charset)+
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FILE + "; " + HttpPostBodyUtil.FILENAME + "=\"" +
|
||||
encodeAttribute(fileUpload.getFilename(), charset) +
|
||||
"\"\r\n");
|
||||
|
||||
} else {
|
||||
internal.addValue("--"+multipartDataBoundary+"\r\n");
|
||||
internal.addValue("--" + multipartDataBoundary + "\r\n");
|
||||
// Content-Disposition: form-data; name="files"; filename="file1.txt"
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\""+
|
||||
encodeAttribute(fileUpload.getName(), charset)+"\"; "+
|
||||
HttpPostBodyUtil.FILENAME+"=\""+
|
||||
encodeAttribute(fileUpload.getFilename(), charset)+
|
||||
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
|
||||
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" +
|
||||
encodeAttribute(fileUpload.getName(), charset) + "\"; " +
|
||||
HttpPostBodyUtil.FILENAME + "=\"" +
|
||||
encodeAttribute(fileUpload.getFilename(), charset) +
|
||||
"\"\r\n");
|
||||
}
|
||||
// Content-Type: image/gif
|
||||
// Content-Type: text/plain; charset=ISO-8859-1
|
||||
// Content-Transfer-Encoding: binary
|
||||
internal.addValue(HttpHeaders.Names.CONTENT_TYPE+": "+
|
||||
internal.addValue(HttpHeaders.Names.CONTENT_TYPE + ": " +
|
||||
fileUpload.getContentType());
|
||||
String contentTransferEncoding = fileUpload.getContentTransferEncoding();
|
||||
if (contentTransferEncoding != null &&
|
||||
contentTransferEncoding.equals(
|
||||
HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value)) {
|
||||
internal.addValue("\r\n"+HttpHeaders.Names.CONTENT_TRANSFER_ENCODING+
|
||||
": "+HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value+
|
||||
internal.addValue("\r\n" + HttpHeaders.Names.CONTENT_TRANSFER_ENCODING +
|
||||
": " + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value +
|
||||
"\r\n\r\n");
|
||||
} else if (fileUpload.getCharset() != null) {
|
||||
internal.addValue("; "+HttpHeaders.Values.CHARSET+"="+
|
||||
fileUpload.getCharset()+"\r\n\r\n");
|
||||
internal.addValue("; " + HttpHeaders.Values.CHARSET + "=" +
|
||||
fileUpload.getCharset() + "\r\n\r\n");
|
||||
} else {
|
||||
internal.addValue("\r\n\r\n");
|
||||
}
|
||||
multipartHttpDatas.add(internal);
|
||||
multipartHttpDatas.add(data);
|
||||
globalBodySize += fileUpload.length()+internal.size();
|
||||
globalBodySize += fileUpload.length() + internal.size();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator to be used when encoding will be called chunk after chunk
|
||||
*/
|
||||
private ListIterator<InterfaceHttpData> iterator = null;
|
||||
private ListIterator<InterfaceHttpData> iterator;
|
||||
|
||||
/**
|
||||
* Finalize the request by preparing the Header in the request and
|
||||
@ -573,9 +572,9 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
if (isMultipart) {
|
||||
InternalAttribute internal = new InternalAttribute();
|
||||
if (duringMixedMode) {
|
||||
internal.addValue("\r\n--"+multipartMixedBoundary+"--");
|
||||
internal.addValue("\r\n--" + multipartMixedBoundary + "--");
|
||||
}
|
||||
internal.addValue("\r\n--"+multipartDataBoundary+"--\r\n");
|
||||
internal.addValue("\r\n--" + multipartDataBoundary + "--\r\n");
|
||||
multipartHttpDatas.add(internal);
|
||||
multipartMixedBoundary = null;
|
||||
currentFileUpload = null;
|
||||
@ -597,7 +596,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
HttpHeaders.Values.MULTIPART_FORM_DATA)) {
|
||||
// ignore
|
||||
} else if (contentType.toLowerCase().startsWith(
|
||||
HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)){
|
||||
HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)) {
|
||||
// ignore
|
||||
} else {
|
||||
request.addHeader(HttpHeaders.Names.CONTENT_TYPE, contentType);
|
||||
@ -675,11 +674,11 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
/**
|
||||
* The ChannelBuffer currently used by the encoder
|
||||
*/
|
||||
private ChannelBuffer currentBuffer = null;
|
||||
private ChannelBuffer currentBuffer;
|
||||
/**
|
||||
* The current InterfaceHttpData to encode (used if more chunks are available)
|
||||
*/
|
||||
private InterfaceHttpData currentData = null;
|
||||
private InterfaceHttpData currentData;
|
||||
/**
|
||||
* If not multipart, does the currentBuffer stands for the Key or for the Value
|
||||
*/
|
||||
@ -787,12 +786,12 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
currentBuffer = ChannelBuffers.wrappedBuffer(
|
||||
buffer, ChannelBuffers.wrappedBuffer("=".getBytes()));
|
||||
//continue
|
||||
size -= buffer.readableBytes()+1;
|
||||
size -= buffer.readableBytes() + 1;
|
||||
} else {
|
||||
currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer,
|
||||
buffer, ChannelBuffers.wrappedBuffer("=".getBytes()));
|
||||
//continue
|
||||
size -= buffer.readableBytes()+1;
|
||||
size -= buffer.readableBytes() + 1;
|
||||
}
|
||||
if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {
|
||||
buffer = fillChannelBuffer();
|
||||
|
@ -71,7 +71,7 @@ public class HttpRequestDecoder extends HttpMessageDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpMessage createMessage(String[] initialLine) throws Exception{
|
||||
protected HttpMessage createMessage(String[] initialLine) throws Exception {
|
||||
return new DefaultHttpRequest(
|
||||
HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1]);
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ public class MemoryAttribute extends AbstractMemoryHttpData implements Attribute
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IOException
|
||||
*/
|
||||
public MemoryAttribute(String name, String value)
|
||||
throws NullPointerException, IllegalArgumentException, IOException {
|
||||
public MemoryAttribute(String name, String value) throws IOException {
|
||||
super(name, HttpCodecUtil.DEFAULT_CHARSET, 0); // Attribute have no default size
|
||||
setValue(value);
|
||||
}
|
||||
|
@ -24,15 +24,14 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUpload {
|
||||
|
||||
private String filename = null;
|
||||
private String filename;
|
||||
|
||||
private String contentType = null;
|
||||
private String contentType;
|
||||
|
||||
private String contentTransferEncoding = null;
|
||||
private String contentTransferEncoding;
|
||||
|
||||
public MemoryFileUpload(String name, String filename, String contentType,
|
||||
String contentTransferEncoding, Charset charset, long size)
|
||||
throws NullPointerException, IllegalArgumentException {
|
||||
String contentTransferEncoding, Charset charset, long size) {
|
||||
super(name, charset, size);
|
||||
setFilename(filename);
|
||||
setContentType(contentType);
|
||||
@ -116,11 +115,11 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
|
||||
@Override
|
||||
public String toString() {
|
||||
return HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
|
||||
HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\"" + getName() +
|
||||
"\"; "+HttpPostBodyUtil.FILENAME+"=\"" + filename + "\"\r\n" +
|
||||
HttpHeaders.Names.CONTENT_TYPE+": " + contentType +
|
||||
(charset != null? "; "+HttpHeaders.Values.CHARSET+"=" + charset + "\r\n" : "\r\n") +
|
||||
HttpHeaders.Names.CONTENT_LENGTH+": " + length() + "\r\n" +
|
||||
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME+"=\"" + getName() +
|
||||
"\"; " + HttpPostBodyUtil.FILENAME + "=\"" + filename + "\"\r\n" +
|
||||
HttpHeaders.Names.CONTENT_TYPE + ": " + contentType +
|
||||
(charset != null? "; " + HttpHeaders.Values.CHARSET + "=" + charset + "\r\n" : "\r\n") +
|
||||
HttpHeaders.Names.CONTENT_LENGTH + ": " + length() + "\r\n" +
|
||||
"Completed: " + isCompleted() +
|
||||
"\r\nIsInMemory: " + isInMemory();
|
||||
}
|
||||
|
@ -26,20 +26,16 @@ import io.netty.buffer.ChannelBuffer;
|
||||
* Mixed implementation using both in Memory and in File with a limit of size
|
||||
*/
|
||||
public class MixedAttribute implements Attribute {
|
||||
private Attribute attribute = null;
|
||||
private Attribute attribute;
|
||||
|
||||
private long limitSize = 0;
|
||||
private long limitSize;
|
||||
|
||||
public MixedAttribute(String name,
|
||||
long limitSize) throws NullPointerException,
|
||||
IllegalArgumentException {
|
||||
public MixedAttribute(String name, long limitSize) {
|
||||
this.limitSize = limitSize;
|
||||
attribute = new MemoryAttribute(name);
|
||||
}
|
||||
|
||||
public MixedAttribute(String name, String value,
|
||||
long limitSize) throws NullPointerException,
|
||||
IllegalArgumentException {
|
||||
public MixedAttribute(String name, String value, long limitSize) {
|
||||
this.limitSize = limitSize;
|
||||
if (value.length() > this.limitSize) {
|
||||
try {
|
||||
@ -62,8 +58,7 @@ public class MixedAttribute implements Attribute {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContent(ChannelBuffer buffer, boolean last)
|
||||
throws IOException {
|
||||
public void addContent(ChannelBuffer buffer, boolean last) throws IOException {
|
||||
if (attribute instanceof MemoryAttribute) {
|
||||
if (attribute.length() + buffer.readableBytes() > limitSize) {
|
||||
DiskAttribute diskAttribute = new DiskAttribute(attribute
|
||||
|
@ -26,16 +26,15 @@ import io.netty.buffer.ChannelBuffer;
|
||||
* Mixed implementation using both in Memory and in File with a limit of size
|
||||
*/
|
||||
public class MixedFileUpload implements FileUpload {
|
||||
private FileUpload fileUpload = null;
|
||||
private FileUpload fileUpload;
|
||||
|
||||
private long limitSize = 0;
|
||||
private long limitSize;
|
||||
|
||||
private long definedSize = 0;
|
||||
private long definedSize;
|
||||
|
||||
public MixedFileUpload(String name, String filename, String contentType,
|
||||
String contentTransferEncoding, Charset charset, long size,
|
||||
long limitSize) throws NullPointerException,
|
||||
IllegalArgumentException {
|
||||
long limitSize) {
|
||||
this.limitSize = limitSize;
|
||||
if (size > this.limitSize) {
|
||||
fileUpload = new DiskFileUpload(name, filename, contentType,
|
||||
@ -57,7 +56,7 @@ public class MixedFileUpload implements FileUpload {
|
||||
.getContentType(), fileUpload
|
||||
.getContentTransferEncoding(), fileUpload.getCharset(),
|
||||
definedSize);
|
||||
if (((MemoryFileUpload) fileUpload).getChannelBuffer() != null){
|
||||
if (((MemoryFileUpload) fileUpload).getChannelBuffer() != null) {
|
||||
diskFileUpload.addContent(((MemoryFileUpload) fileUpload)
|
||||
.getChannelBuffer(), last);
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class QueryStringDecoder {
|
||||
* Creates a new decoder that decodes the specified URI encoded in the
|
||||
* specified charset.
|
||||
*/
|
||||
public QueryStringDecoder(URI uri, Charset charset){
|
||||
public QueryStringDecoder(URI uri, Charset charset) {
|
||||
this(uri, charset, DEFAULT_MAX_PARAMS);
|
||||
}
|
||||
|
||||
@ -174,8 +174,7 @@ public class QueryStringDecoder {
|
||||
int pathEndPos = uri.indexOf('?');
|
||||
if (pathEndPos < 0) {
|
||||
path = uri;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return path = uri.substring(0, pathEndPos);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class QueryStringEncoder {
|
||||
sb.append(encodeComponent(param.name, charset));
|
||||
sb.append("=");
|
||||
sb.append(encodeComponent(param.value, charset));
|
||||
if(i != params.size() - 1) {
|
||||
if (i != params.size() - 1) {
|
||||
sb.append("&");
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import io.netty.util.CharsetUtil;
|
||||
*/
|
||||
public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
private String aggregatedText = null;
|
||||
private String aggregatedText;
|
||||
|
||||
/**
|
||||
* Creates a new empty continuation frame.
|
||||
|
@ -42,7 +42,7 @@ final class UTF8Output {
|
||||
12, 12, 12, 12, 12, 12, 12, 12 };
|
||||
|
||||
private int state = UTF8_ACCEPT;
|
||||
private int codep = 0;
|
||||
private int codep;
|
||||
|
||||
private final StringBuilder stringBuilder;
|
||||
|
||||
@ -60,7 +60,7 @@ final class UTF8Output {
|
||||
public void write(int b) {
|
||||
byte type = TYPES[b & 0xFF];
|
||||
|
||||
codep = (state != UTF8_ACCEPT) ? (b & 0x3f) | (codep << 6) : (0xff >> type) & (b);
|
||||
codep = (state != UTF8_ACCEPT) ? (b & 0x3f) | (codep << 6) : (0xff >> type) & b;
|
||||
|
||||
state = STATES[state + type];
|
||||
|
||||
|
@ -64,20 +64,20 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
|
||||
private static final byte OPCODE_PING = 0x9;
|
||||
private static final byte OPCODE_PONG = 0xA;
|
||||
|
||||
private UTF8Output fragmentedFramesText = null;
|
||||
private int fragmentedFramesCount = 0;
|
||||
private UTF8Output fragmentedFramesText;
|
||||
private int fragmentedFramesCount;
|
||||
|
||||
private boolean frameFinalFlag;
|
||||
private int frameRsv;
|
||||
private int frameOpcode;
|
||||
private long framePayloadLength;
|
||||
private ChannelBuffer framePayload = null;
|
||||
private int framePayloadBytesRead = 0;
|
||||
private ChannelBuffer framePayload;
|
||||
private int framePayloadBytesRead;
|
||||
private ChannelBuffer maskingKey;
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean maskedPayload = false;
|
||||
private boolean receivedClosingHandshake = false;
|
||||
private boolean allowExtensions;
|
||||
private boolean maskedPayload;
|
||||
private boolean receivedClosingHandshake;
|
||||
|
||||
public enum State {
|
||||
FRAME_START, MASKING_KEY, PAYLOAD, CORRUPT
|
||||
@ -118,7 +118,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
|
||||
byte b = buffer.readByte();
|
||||
frameFinalFlag = (b & 0x80) != 0;
|
||||
frameRsv = (b & 0x70) >> 4;
|
||||
frameOpcode = (b & 0x0F);
|
||||
frameOpcode = b & 0x0F;
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Decoding WebSocket Frame opCode=" + frameOpcode);
|
||||
@ -127,7 +127,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
|
||||
// MASK, PAYLOAD LEN 1
|
||||
b = buffer.readByte();
|
||||
boolean frameMasked = (b & 0x80) != 0;
|
||||
int framePayloadLen1 = (b & 0x7F);
|
||||
int framePayloadLen1 = b & 0x7F;
|
||||
|
||||
if (frameRsv != 0 && !this.allowExtensions) {
|
||||
protocolViolation(channel, "RSV != 0 and no extension negotiated, RSV:" + frameRsv);
|
||||
|
@ -66,7 +66,7 @@ public class WebSocket08FrameEncoder extends OneToOneEncoder {
|
||||
private static final byte OPCODE_PING = 0x9;
|
||||
private static final byte OPCODE_PONG = 0xA;
|
||||
|
||||
private boolean maskPayload = false;
|
||||
private boolean maskPayload;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -116,7 +116,7 @@ public class WebSocket08FrameEncoder extends OneToOneEncoder {
|
||||
|
||||
int b0 = 0;
|
||||
if (frame.isFinalFragment()) {
|
||||
b0 |= (1 << 7);
|
||||
b0 |= 1 << 7;
|
||||
}
|
||||
b0 |= (frame.getRsv() % 8) << 4;
|
||||
b0 |= opcode % 128;
|
||||
@ -138,13 +138,13 @@ public class WebSocket08FrameEncoder extends OneToOneEncoder {
|
||||
} else if (length <= 0xFFFF) {
|
||||
header = ChannelBuffers.buffer(4 + maskLength);
|
||||
header.writeByte(b0);
|
||||
header.writeByte(this.maskPayload ? (0xFE) : 126);
|
||||
header.writeByte(this.maskPayload ? 0xFE : 126);
|
||||
header.writeByte((length >>> 8) & 0xFF);
|
||||
header.writeByte((length) & 0xFF);
|
||||
header.writeByte(length & 0xFF);
|
||||
} else {
|
||||
header = ChannelBuffers.buffer(10 + maskLength);
|
||||
header.writeByte(b0);
|
||||
header.writeByte(this.maskPayload ? (0xFF) : 127);
|
||||
header.writeByte(this.maskPayload ? 0xFF : 127);
|
||||
header.writeLong(length);
|
||||
}
|
||||
|
||||
|
@ -36,20 +36,14 @@ public abstract class WebSocketClientHandshaker {
|
||||
|
||||
private WebSocketVersion version = WebSocketVersion.UNKNOWN;
|
||||
|
||||
private boolean openingHandshakeCompleted = false;
|
||||
private boolean openingHandshakeCompleted;
|
||||
|
||||
private String subProtocolRequest = null;
|
||||
private String subProtocolRequest;
|
||||
|
||||
private String subProtocolResponse = null;
|
||||
private String subProtocolResponse;
|
||||
|
||||
protected Map<String, String> customHeaders = null;
|
||||
protected Map<String, String> customHeaders;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param webSocketURL
|
||||
* @param version
|
||||
* @param subProtocol
|
||||
*/
|
||||
public WebSocketClientHandshaker(URI webSocketURL, WebSocketVersion version, String subProtocol,
|
||||
Map<String, String> customHeaders) {
|
||||
this.webSocketURL = webSocketURL;
|
||||
|
@ -45,7 +45,7 @@ import io.netty.handler.codec.http.HttpVersion;
|
||||
*/
|
||||
public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
|
||||
|
||||
private byte[] expectedChallengeResponseBytes = null;
|
||||
private byte[] expectedChallengeResponseBytes;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location and version to initiate
|
||||
|
@ -46,11 +46,11 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
|
||||
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
private String expectedChallengeResponseString = null;
|
||||
private String expectedChallengeResponseString;
|
||||
|
||||
private static final String protocol = null;
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean allowExtensions;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location and version to initiate
|
||||
|
@ -46,11 +46,11 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
|
||||
public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
private String expectedChallengeResponseString = null;
|
||||
private String expectedChallengeResponseString;
|
||||
|
||||
private static final String protocol = null;
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean allowExtensions;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location and version to initiate
|
||||
|
@ -31,7 +31,7 @@ public abstract class WebSocketFrame {
|
||||
/**
|
||||
* RSV1, RSV2, RSV3 used for extensions
|
||||
*/
|
||||
private int rsv = 0;
|
||||
private int rsv;
|
||||
|
||||
/**
|
||||
* Contents of this frame
|
||||
|
@ -34,7 +34,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
private String subProtocols;
|
||||
|
||||
private String[] subProtocolsArray = null;
|
||||
private String[] subProtocolsArray;
|
||||
|
||||
private WebSocketVersion version = WebSocketVersion.UNKNOWN;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
|
||||
public static final String WEBSOCKET_08_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean allowExtensions;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
|
@ -50,7 +50,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
|
||||
public static final String WEBSOCKET_13_ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean allowExtensions;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
|
@ -32,7 +32,7 @@ public class WebSocketServerHandshakerFactory {
|
||||
|
||||
private final String subProtocols;
|
||||
|
||||
private boolean allowExtensions = false;
|
||||
private boolean allowExtensions;
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
|
@ -32,7 +32,7 @@ import io.netty.buffer.HeapChannelBufferFactory;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses io.netty.handler.codec.base64.Base64Dialect
|
||||
*/
|
||||
public class Base64 {
|
||||
public final class Base64 {
|
||||
|
||||
/** Maximum line length (76) of Base64 output. */
|
||||
private static final int MAX_LINE_LENGTH = 76;
|
||||
@ -207,7 +207,7 @@ public class Base64 {
|
||||
// We have to shift left 24 in order to flush out the 1's that appear
|
||||
// when Java treats a value as negative that is cast from a byte to an int.
|
||||
int inBuff =
|
||||
(numSigBytes > 0? src.getByte(srcOffset ) << 24 >>> 8 : 0) |
|
||||
(numSigBytes > 0? src.getByte(srcOffset) << 24 >>> 8 : 0) |
|
||||
(numSigBytes > 1? src.getByte(srcOffset + 1) << 24 >>> 16 : 0) |
|
||||
(numSigBytes > 2? src.getByte(srcOffset + 2) << 24 >>> 24 : 0);
|
||||
|
||||
@ -301,9 +301,9 @@ public class Base64 {
|
||||
sbiDecode = DECODABET[sbiCrop];
|
||||
|
||||
if (sbiDecode >= WHITE_SPACE_ENC) { // White space, Equals sign or better
|
||||
if (sbiDecode >= EQUALS_SIGN_ENC) {
|
||||
if (sbiDecode >= EQUALS_SIGN_ENC) { // Equals sign or better
|
||||
b4[b4Posn ++] = sbiCrop;
|
||||
if (b4Posn > 3) {
|
||||
if (b4Posn > 3) { // Quartet built
|
||||
outBuffPosn += decode4to3(
|
||||
b4, 0, dest, outBuffPosn, dialect);
|
||||
b4Posn = 0;
|
||||
@ -312,10 +312,9 @@ public class Base64 {
|
||||
if (sbiCrop == EQUALS_SIGN) {
|
||||
break;
|
||||
}
|
||||
} // end if: quartet built
|
||||
} // end if: equals sign or better
|
||||
} // end if: white space, equals sign or better
|
||||
else {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"bad Base64 input character at " + i + ": " +
|
||||
src.getUnsignedByte(i) + " (decimal)");
|
||||
@ -331,18 +330,16 @@ public class Base64 {
|
||||
|
||||
byte[] DECODABET = decodabet(dialect);
|
||||
|
||||
// Example: Dk==
|
||||
if (src[srcOffset + 2] == EQUALS_SIGN) {
|
||||
// Example: Dk==
|
||||
int outBuff =
|
||||
(DECODABET[src[srcOffset ]] & 0xFF) << 18 |
|
||||
(DECODABET[src[srcOffset + 1]] & 0xFF) << 12;
|
||||
|
||||
dest.setByte(destOffset, (byte) (outBuff >>> 16));
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else if (src[srcOffset + 3] == EQUALS_SIGN) {
|
||||
// Example: DkL=
|
||||
else if (src[srcOffset + 3] == EQUALS_SIGN) {
|
||||
int outBuff =
|
||||
(DECODABET[src[srcOffset ]] & 0xFF) << 18 |
|
||||
(DECODABET[src[srcOffset + 1]] & 0xFF) << 12 |
|
||||
@ -351,10 +348,8 @@ public class Base64 {
|
||||
dest.setByte(destOffset , (byte) (outBuff >>> 16));
|
||||
dest.setByte(destOffset + 1, (byte) (outBuff >>> 8));
|
||||
return 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Example: DkLE
|
||||
else {
|
||||
int outBuff;
|
||||
try {
|
||||
outBuff =
|
||||
|
@ -56,7 +56,7 @@ public class ByteArrayDecoder extends OneToOneDecoder {
|
||||
if (!(msg instanceof ChannelBuffer)) {
|
||||
return msg;
|
||||
}
|
||||
ChannelBuffer buf = (ChannelBuffer )msg;
|
||||
ChannelBuffer buf = (ChannelBuffer) msg;
|
||||
byte[] array;
|
||||
if (buf.hasArray()) {
|
||||
if (buf.arrayOffset() == 0 && buf.readableBytes() == buf.capacity()) {
|
||||
|
@ -157,7 +157,7 @@ public class ZlibEncoder extends OneToOneEncoder implements LifeCycleAwareChanne
|
||||
ZlibUtil.fail(z, "initialization failure", resultCode);
|
||||
} else {
|
||||
resultCode = z.deflateSetDictionary(dictionary, dictionary.length);
|
||||
if (resultCode != JZlib.Z_OK){
|
||||
if (resultCode != JZlib.Z_OK) {
|
||||
ZlibUtil.fail(z, "failed to set the dictionary", resultCode);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import io.netty.channel.ChannelPipeline;
|
||||
|
||||
/**
|
||||
*/
|
||||
class EmbeddedChannelFactory implements ChannelFactory {
|
||||
final class EmbeddedChannelFactory implements ChannelFactory {
|
||||
|
||||
static final ChannelFactory INSTANCE = new EmbeddedChannelFactory();
|
||||
|
||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ChannelBuffers;
|
||||
/**
|
||||
* A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}.
|
||||
*/
|
||||
public class Delimiters {
|
||||
public final class Delimiters {
|
||||
|
||||
/**
|
||||
* Returns a {@code NUL (0x00)} delimiter, which could be used for
|
||||
|
@ -145,8 +145,8 @@ import io.netty.handler.codec.serialization.ObjectDecoder;
|
||||
* header from the frame. If you don't want to strip the prepended header, you
|
||||
* could specify <tt>0</tt> for <tt>initialBytesToSkip</tt>.
|
||||
* <pre>
|
||||
* lengthFieldOffset</b> = 1 (= the length of HDR1)
|
||||
* lengthFieldLength</b> = 2
|
||||
* lengthFieldOffset = 1 (= the length of HDR1)
|
||||
* lengthFieldLength = 2
|
||||
* <b>lengthAdjustment</b> = <b>1</b> (= the length of HDR2)
|
||||
* <b>initialBytesToStrip</b> = <b>3</b> (= the length of HDR1 + LEN)
|
||||
*
|
||||
@ -403,14 +403,12 @@ public class LengthFieldBasedFrameDecoder extends FrameDecoder {
|
||||
this.tooLongFrameLength = 0;
|
||||
discardingTooLongFrame = false;
|
||||
if ((!failFast) ||
|
||||
(failFast && firstDetectionOfTooLongFrame))
|
||||
{
|
||||
(failFast && firstDetectionOfTooLongFrame)) {
|
||||
fail(ctx, tooLongFrameLength);
|
||||
}
|
||||
} else {
|
||||
// Keep discarding and notify handlers if necessary.
|
||||
if (failFast && firstDetectionOfTooLongFrame)
|
||||
{
|
||||
if (failFast && firstDetectionOfTooLongFrame) {
|
||||
fail(ctx, this.tooLongFrameLength);
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class ProtobufDecoder extends OneToOneDecoder {
|
||||
ChannelBuffer buf = (ChannelBuffer) msg;
|
||||
if (buf.hasArray()) {
|
||||
final int offset = buf.readerIndex();
|
||||
if(extensionRegistry == null) {
|
||||
if (extensionRegistry == null) {
|
||||
return prototype.newBuilderForType().mergeFrom(
|
||||
buf.array(), buf.arrayOffset() + offset, buf.readableBytes()).build();
|
||||
} else {
|
||||
|
@ -19,7 +19,7 @@ import java.lang.ref.Reference;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ClassResolvers {
|
||||
public final class ClassResolvers {
|
||||
|
||||
/**
|
||||
* cache disabled
|
||||
@ -86,4 +86,8 @@ public class ClassResolvers {
|
||||
|
||||
return ClassResolvers.class.getClassLoader();
|
||||
}
|
||||
|
||||
private ClassResolvers() {
|
||||
// Unused
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +191,9 @@ public class ObjectDecoderInputStream extends InputStream implements
|
||||
return in.readInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link java.io.BufferedReader#readLine()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final String readLine() throws IOException {
|
||||
|
@ -26,7 +26,7 @@ import java.util.Map;
|
||||
* A utility class that provides various common operations and constants
|
||||
* related with {@link Charset} and its relevant classes.
|
||||
*/
|
||||
public class CharsetUtil {
|
||||
public final class CharsetUtil {
|
||||
|
||||
/**
|
||||
* 16-bit UTF (UCS Transformation Format) whose byte order is identified by
|
||||
@ -61,7 +61,7 @@ public class CharsetUtil {
|
||||
public static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
|
||||
private static final ThreadLocal<Map<Charset, CharsetEncoder>> encoders =
|
||||
new ThreadLocal<Map<Charset,CharsetEncoder>>() {
|
||||
new ThreadLocal<Map<Charset, CharsetEncoder>>() {
|
||||
@Override
|
||||
protected Map<Charset, CharsetEncoder> initialValue() {
|
||||
return new IdentityHashMap<Charset, CharsetEncoder>();
|
||||
@ -69,7 +69,7 @@ public class CharsetUtil {
|
||||
};
|
||||
|
||||
private static final ThreadLocal<Map<Charset, CharsetDecoder>> decoders =
|
||||
new ThreadLocal<Map<Charset,CharsetDecoder>>() {
|
||||
new ThreadLocal<Map<Charset, CharsetDecoder>>() {
|
||||
@Override
|
||||
protected Map<Charset, CharsetDecoder> initialValue() {
|
||||
return new IdentityHashMap<Charset, CharsetDecoder>();
|
||||
|
@ -19,7 +19,7 @@ package io.netty.util;
|
||||
* A utility class that provides the convenient shutdown of
|
||||
* {@link ExternalResourceReleasable}s.
|
||||
*/
|
||||
public class ExternalResourceUtil {
|
||||
public final class ExternalResourceUtil {
|
||||
|
||||
/**
|
||||
* Releases the specified {@link ExternalResourceReleasable}s.
|
||||
|
@ -545,7 +545,7 @@ public class HashedWheelTimer implements Timer {
|
||||
}
|
||||
|
||||
if (isCancelled()) {
|
||||
buf.append (", cancelled");
|
||||
buf.append(", cancelled");
|
||||
}
|
||||
|
||||
return buf.append(')').toString();
|
||||
|
@ -20,11 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Utility which checks if {@value #UNSAFE} class can be found in the classpath
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class UnsafeDetectUtil {
|
||||
public final class UnsafeDetectUtil {
|
||||
|
||||
private static final String UNSAFE = "sun.misc.Unsafe";
|
||||
private static final boolean UNSAFE_FOUND = isUnsafeFound(AtomicInteger.class.getClassLoader());
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||
|
||||
/**
|
||||
*/
|
||||
class AtomicFieldUpdaterUtil {
|
||||
final class AtomicFieldUpdaterUtil {
|
||||
|
||||
private static final boolean AVAILABLE;
|
||||
|
||||
@ -49,7 +49,7 @@ class AtomicFieldUpdaterUtil {
|
||||
AVAILABLE = available;
|
||||
}
|
||||
|
||||
static <T, V> AtomicReferenceFieldUpdater<T,V> newRefUpdater(Class<T> tclass, Class<V> vclass, String fieldName) {
|
||||
static <T, V> AtomicReferenceFieldUpdater<T, V> newRefUpdater(Class<T> tclass, Class<V> vclass, String fieldName) {
|
||||
if (AVAILABLE) {
|
||||
return AtomicReferenceFieldUpdater.newUpdater(tclass, vclass, fieldName);
|
||||
} else {
|
||||
|
@ -42,7 +42,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* @param <V> the type of mapped values
|
||||
*/
|
||||
public final class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||
implements ConcurrentMap<K, V>{
|
||||
implements ConcurrentMap<K, V> {
|
||||
|
||||
/**
|
||||
* The default initial capacity for this table, used when not otherwise
|
||||
@ -65,7 +65,7 @@ public final class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||
/**
|
||||
* The maximum capacity, used if a higher value is implicitly specified by
|
||||
* either of the constructors with arguments. MUST be a power of two
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
*/
|
||||
static final int MAXIMUM_CAPACITY = 1 << 30;
|
||||
|
||||
@ -262,7 +262,7 @@ public final class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||
|
||||
Segment(int initialCapacity, float lf) {
|
||||
loadFactor = lf;
|
||||
setTable(HashEntry.<K, V> newArray(initialCapacity));
|
||||
setTable(HashEntry.<K, V>newArray(initialCapacity));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -42,7 +42,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* @param <V> the type of mapped values
|
||||
*/
|
||||
public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
|
||||
implements ConcurrentMap<K, V>{
|
||||
implements ConcurrentMap<K, V> {
|
||||
|
||||
/**
|
||||
* The default initial capacity for this table, used when not otherwise
|
||||
@ -65,7 +65,7 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
|
||||
/**
|
||||
* The maximum capacity, used if a higher value is implicitly specified by
|
||||
* either of the constructors with arguments. MUST be a power of two
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
*/
|
||||
static final int MAXIMUM_CAPACITY = 1 << 30;
|
||||
|
||||
@ -262,7 +262,7 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
|
||||
|
||||
Segment(int initialCapacity, float lf) {
|
||||
loadFactor = lf;
|
||||
setTable(HashEntry.<K, V> newArray(initialCapacity));
|
||||
setTable(HashEntry.<K, V>newArray(initialCapacity));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -72,7 +72,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
|
||||
/**
|
||||
* The maximum capacity, used if a higher value is implicitly specified by
|
||||
* either of the constructors with arguments. MUST be a power of two
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
*/
|
||||
static final int MAXIMUM_CAPACITY = 1 << 30;
|
||||
|
||||
@ -307,7 +307,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
|
||||
|
||||
Segment(int initialCapacity, float lf) {
|
||||
loadFactor = lf;
|
||||
setTable(HashEntry.<K, V> newArray(initialCapacity));
|
||||
setTable(HashEntry.<K, V>newArray(initialCapacity));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -72,7 +72,7 @@ public final class ConcurrentWeakKeyHashMap<K, V> extends AbstractMap<K, V> impl
|
||||
/**
|
||||
* The maximum capacity, used if a higher value is implicitly specified by
|
||||
* either of the constructors with arguments. MUST be a power of two
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
* <= 1<<30 to ensure that entries are indexable using integers.
|
||||
*/
|
||||
static final int MAXIMUM_CAPACITY = 1 << 30;
|
||||
|
||||
@ -307,7 +307,7 @@ public final class ConcurrentWeakKeyHashMap<K, V> extends AbstractMap<K, V> impl
|
||||
|
||||
Segment(int initialCapacity, float lf) {
|
||||
loadFactor = lf;
|
||||
setTable(HashEntry.<K, V> newArray(initialCapacity));
|
||||
setTable(HashEntry.<K, V>newArray(initialCapacity));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -22,7 +22,7 @@ import java.util.List;
|
||||
* Conversion utility class to parse a property represented as a string or
|
||||
* an object.
|
||||
*/
|
||||
public class ConversionUtil {
|
||||
public final class ConversionUtil {
|
||||
|
||||
/**
|
||||
* Converts the specified object into an integer.
|
||||
@ -89,7 +89,7 @@ public class ConversionUtil {
|
||||
|
||||
private static final String[] INTEGERS = {
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
"10","11","12","13","14","15",
|
||||
"10", "11", "12", "13", "14", "15",
|
||||
};
|
||||
|
||||
public static String toString(int value) {
|
||||
|
@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* their termination. An {@link Executor} which is not an {@link ExecutorService}
|
||||
* will be ignored silently.
|
||||
*/
|
||||
public class ExecutorUtil {
|
||||
public final class ExecutorUtil {
|
||||
|
||||
/**
|
||||
* Returns {@code true} if and only if the specified {@code executor}
|
||||
|
@ -26,7 +26,7 @@ import io.netty.util.UnsafeDetectUtil;
|
||||
|
||||
|
||||
*/
|
||||
public class QueueFactory {
|
||||
public final class QueueFactory {
|
||||
|
||||
private static final boolean useUnsafe = UnsafeDetectUtil.isUnsafeFound(QueueFactory.class.getClassLoader());
|
||||
|
||||
@ -41,7 +41,7 @@ public class QueueFactory {
|
||||
* @param itemClass the {@link Class} type which will be used as {@link BlockingQueue} items
|
||||
* @return queue the {@link BlockingQueue} implementation
|
||||
*/
|
||||
public static final <T> BlockingQueue<T> createQueue(Class<T> itemClass) {
|
||||
public static <T> BlockingQueue<T> createQueue(Class<T> itemClass) {
|
||||
if (useUnsafe) {
|
||||
return new LinkedTransferQueue<T>();
|
||||
} else {
|
||||
@ -56,7 +56,7 @@ public class QueueFactory {
|
||||
* @param itemClass the {@link Class} type which will be used as {@link BlockingQueue} items
|
||||
* @return queue the {@link BlockingQueue} implementation
|
||||
*/
|
||||
public static final <T> BlockingQueue<T> createQueue(Collection<? extends T> collection, Class<T> itemClass) {
|
||||
public static <T> BlockingQueue<T> createQueue(Collection<? extends T> collection, Class<T> itemClass) {
|
||||
if (useUnsafe) {
|
||||
return new LinkedTransferQueue<T>(collection);
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ import java.util.Formatter;
|
||||
/**
|
||||
* String utility class.
|
||||
*/
|
||||
public class StringUtil {
|
||||
public final class StringUtil {
|
||||
|
||||
private StringUtil() {
|
||||
// Unused.
|
||||
|
@ -20,7 +20,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Accesses the system property swallowing a {@link SecurityException}.
|
||||
*/
|
||||
public class SystemPropertyUtil {
|
||||
public final class SystemPropertyUtil {
|
||||
|
||||
/**
|
||||
* Returns the value of the Java system property with the specified
|
||||
|
@ -48,9 +48,9 @@ import java.util.Random;
|
||||
*/
|
||||
final class ThreadLocalRandom extends Random {
|
||||
// same constants as Random, but must be redeclared because private
|
||||
private final static long multiplier = 0x5DEECE66DL;
|
||||
private final static long addend = 0xBL;
|
||||
private final static long mask = (1L << 48) - 1;
|
||||
private static final long multiplier = 0x5DEECE66DL;
|
||||
private static final long addend = 0xBL;
|
||||
private static final long mask = (1L << 48) - 1;
|
||||
|
||||
/**
|
||||
* The random seed. We can't use super.seed.
|
||||
@ -118,7 +118,7 @@ final class ThreadLocalRandom extends Random {
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
rnd = rnd * multiplier + addend & mask;
|
||||
return (int) (rnd >>> 48-bits);
|
||||
return (int) (rnd >>> 48 - bits);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -5851777807851030925L;
|
||||
|
@ -49,6 +49,20 @@ public class DiscardClient {
|
||||
firstMessageSize = 256;
|
||||
}
|
||||
|
||||
new DiscardClient(host, port, firstMessageSize).run();
|
||||
}
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int firstMessageSize;
|
||||
|
||||
public DiscardClient(String host, int port, int firstMessageSize) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.firstMessageSize = firstMessageSize;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the client.
|
||||
ClientBootstrap bootstrap = new ClientBootstrap(
|
||||
new NioClientSocketChannelFactory(
|
||||
|
@ -38,7 +38,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler {
|
||||
private static final Logger logger = Logger.getLogger(
|
||||
DiscardClientHandler.class.getName());
|
||||
|
||||
private long transferredBytes = 0;
|
||||
private long transferredBytes;
|
||||
private final byte[] content;
|
||||
|
||||
public DiscardClientHandler(int messageSize) {
|
||||
@ -84,7 +84,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
@Override
|
||||
public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) {
|
||||
transferredBytes =+e.getWrittenAmount();
|
||||
transferredBytes += e.getWrittenAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,11 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class DiscardServer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new DiscardServer().run();
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
new NioServerSocketChannelFactory(
|
||||
|
@ -34,7 +34,7 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler {
|
||||
private static final Logger logger = Logger.getLogger(
|
||||
DiscardServerHandler.class.getName());
|
||||
|
||||
private long transferredBytes = 0;
|
||||
private long transferredBytes;
|
||||
|
||||
public long getTransferredBytes() {
|
||||
return transferredBytes;
|
||||
@ -53,7 +53,7 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler {
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
|
||||
// Discard received data silently by doing nothing.
|
||||
transferredBytes += (((ChannelBuffer) e.getMessage()).readableBytes());
|
||||
transferredBytes += ((ChannelBuffer) e.getMessage()).readableBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,6 +52,20 @@ public class EchoClient {
|
||||
firstMessageSize = 256;
|
||||
}
|
||||
|
||||
new EchoClient(host, port, firstMessageSize).run();
|
||||
}
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int firstMessageSize;
|
||||
|
||||
public EchoClient(String host, int port, int firstMessageSize) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.firstMessageSize = firstMessageSize;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the client.
|
||||
ClientBootstrap bootstrap = new ClientBootstrap(
|
||||
new NioClientSocketChannelFactory(
|
||||
|
@ -30,6 +30,11 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class EchoServer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new EchoServer().run();
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
new NioServerSocketChannelFactory(
|
||||
|
@ -46,6 +46,20 @@ public class FactorialClient {
|
||||
throw new IllegalArgumentException("count must be a positive integer.");
|
||||
}
|
||||
|
||||
new FactorialClient(host, port, count).run();
|
||||
}
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int count;
|
||||
|
||||
public FactorialClient(String host, int port, int count) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the client.
|
||||
ClientBootstrap bootstrap = new ClientBootstrap(
|
||||
new NioClientSocketChannelFactory(
|
||||
|
@ -45,7 +45,7 @@ public class FactorialClientHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
// Stateful properties
|
||||
private int i = 1;
|
||||
private int receivedMessages = 0;
|
||||
private int receivedMessages;
|
||||
private final int count;
|
||||
final BlockingQueue<BigInteger> answer = new LinkedBlockingQueue<BigInteger>();
|
||||
|
||||
|
@ -28,6 +28,11 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class FactorialServer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new FactorialServer().run();
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
new NioServerSocketChannelFactory(
|
||||
|
@ -134,8 +134,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
// Cache Validation
|
||||
String ifModifiedSince = request.getHeader(HttpHeaders.Names.IF_MODIFIED_SINCE);
|
||||
if (ifModifiedSince != null && !ifModifiedSince.equals(""))
|
||||
{
|
||||
if (ifModifiedSince != null && !ifModifiedSince.equals("")) {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
|
||||
Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);
|
||||
|
||||
|
@ -140,7 +140,7 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler {
|
||||
if (cookieString != null) {
|
||||
CookieDecoder cookieDecoder = new CookieDecoder();
|
||||
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
|
||||
if(!cookies.isEmpty()) {
|
||||
if (!cookies.isEmpty()) {
|
||||
// Reset the cookies if necessary.
|
||||
CookieEncoder cookieEncoder = new CookieEncoder(true);
|
||||
for (Cookie cookie : cookies) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -66,14 +66,14 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private volatile HttpRequest request;
|
||||
|
||||
private volatile boolean readingChunks = false;
|
||||
private volatile boolean readingChunks;
|
||||
|
||||
private final StringBuilder responseContent = new StringBuilder();
|
||||
|
||||
private static final HttpDataFactory factory = new DefaultHttpDataFactory(
|
||||
DefaultHttpDataFactory.MINSIZE); // Disk if size exceed MINSIZE
|
||||
|
||||
private HttpPostRequestDecoder decoder = null;
|
||||
private HttpPostRequestDecoder decoder;
|
||||
static {
|
||||
DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file
|
||||
// on exit (in normal
|
||||
|
@ -50,7 +50,7 @@ import io.netty.util.CharsetUtil;
|
||||
public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketServerHandler.class);
|
||||
|
||||
private WebSocketServerHandshaker handshaker = null;
|
||||
private WebSocketServerHandshaker handshaker;
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
|
@ -36,13 +36,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ConsoleHandler ch = new ConsoleHandler();
|
||||
ch.setLevel(Level.FINE);
|
||||
Logger.getLogger("").addHandler(ch);
|
||||
Logger.getLogger("").setLevel(Level.FINE);
|
||||
|
||||
runClient();
|
||||
System.exit(0);
|
||||
new App().runClient();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +44,7 @@ public class App {
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void runClient() throws Exception {
|
||||
public void runClient() throws Exception {
|
||||
|
||||
MyCallbackHandler callbackHandler = new MyCallbackHandler();
|
||||
WebSocketClientFactory factory = new WebSocketClientFactory();
|
||||
@ -91,7 +85,7 @@ public class App {
|
||||
* Our web socket callback handler for this app
|
||||
*/
|
||||
public static class MyCallbackHandler implements WebSocketCallback {
|
||||
public boolean connected = false;
|
||||
public boolean connected;
|
||||
public ArrayList<String> messagesReceived = new ArrayList<String>();
|
||||
|
||||
public MyCallbackHandler() {
|
||||
|
@ -53,9 +53,9 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler impleme
|
||||
private URI url;
|
||||
private final WebSocketCallback callback;
|
||||
private Channel channel;
|
||||
private WebSocketClientHandshaker handshaker = null;
|
||||
private WebSocketClientHandshaker handshaker;
|
||||
private final WebSocketVersion version;
|
||||
private Map<String, String> customHeaders = null;
|
||||
private Map<String, String> customHeaders;
|
||||
|
||||
public WebSocketClientHandler(ClientBootstrap bootstrap, URI url, WebSocketVersion version,
|
||||
WebSocketCallback callback, Map<String, String> customHeaders) {
|
||||
|
@ -24,14 +24,12 @@ package io.netty.example.http.websocketx.client;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Copied from https://github.com/cgbystrom/netty-tools
|
||||
*
|
||||
* A WebSocket related exception
|
||||
*
|
||||
* Copied from https://github.com/cgbystrom/netty-tools
|
||||
*/
|
||||
public class WebSocketException extends IOException {
|
||||
|
||||
/**
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public WebSocketException(String s) {
|
||||
|
@ -52,7 +52,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private static final String WEBSOCKET_PATH = "/websocket";
|
||||
|
||||
private WebSocketServerHandshaker handshaker = null;
|
||||
private WebSocketServerHandshaker handshaker;
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
|
@ -22,7 +22,7 @@ import io.netty.util.CharsetUtil;
|
||||
/**
|
||||
* Generates the demo HTML page which is served at http://localhost:8080/
|
||||
*/
|
||||
public class WebSocketServerIndexPage {
|
||||
public final class WebSocketServerIndexPage {
|
||||
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
@ -89,4 +89,8 @@ public class WebSocketServerIndexPage {
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketServerIndexPage() {
|
||||
// Unused
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private static final String WEBSOCKET_PATH = "/websocket";
|
||||
|
||||
private WebSocketServerHandshaker handshaker = null;
|
||||
private WebSocketServerHandshaker handshaker;
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
|
@ -22,7 +22,7 @@ import io.netty.util.CharsetUtil;
|
||||
/**
|
||||
* Generates the demo HTML page which is served at http://localhost:8080/
|
||||
*/
|
||||
public class WebSocketSslServerIndexPage {
|
||||
public final class WebSocketSslServerIndexPage {
|
||||
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
@ -89,4 +89,8 @@ public class WebSocketSslServerIndexPage {
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketSslServerIndexPage() {
|
||||
// Unused
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import io.netty.logging.InternalLoggerFactory;
|
||||
/**
|
||||
* Creates a {@link SSLContext} for just server certificates.
|
||||
*/
|
||||
public class WebSocketSslServerSslContext {
|
||||
public final class WebSocketSslServerSslContext {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerSslContext.class);
|
||||
private static final String PROTOCOL = "TLS";
|
||||
|
@ -18,19 +18,16 @@
|
||||
* <p>This package contains an example web socket web server with server SSL.
|
||||
* <p>To run this example, follow the steps below:
|
||||
* <dl>
|
||||
* <dt>Step 1. Generate Your Key</dt>
|
||||
* <dt>Step 1. Generate Your Key
|
||||
* <dd>
|
||||
* <code>keytool -genkey -keystore mySrvKeystore -keyalg RSA</code>.
|
||||
* Make sure that you set the key password to be the same the key file password.
|
||||
* </dd>
|
||||
* <dt>Step 2. Specify your key store file and password as system properties</dt>
|
||||
* <dt>Step 2. Specify your key store file and password as system properties
|
||||
* <dd>
|
||||
* <code>-Dkeystore.file.path=<path to mySrvKeystore> -Dkeystore.file.password=<password></code>
|
||||
* </dd>
|
||||
* <dt>Step 3. Run WebSocketSslServer as a Java application</dt>
|
||||
* <dt>Step 3. Run WebSocketSslServer as a Java application
|
||||
* <dd>
|
||||
* Once started, you can test the web server against your browser by navigating to https://localhost:8081/
|
||||
* </dd>
|
||||
* </dl>
|
||||
* <p>To find out more about setting up key stores, refer to this
|
||||
* <a href="http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html">giude</a>.
|
||||
|
@ -15,8 +15,18 @@
|
||||
*/
|
||||
package io.netty.example.iostream;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import io.netty.bootstrap.ClientBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelPipelineFactory;
|
||||
import io.netty.channel.DefaultChannelPipeline;
|
||||
import io.netty.channel.MessageEvent;
|
||||
import io.netty.channel.SimpleChannelHandler;
|
||||
import io.netty.channel.iostream.IOStreamAddress;
|
||||
import io.netty.channel.iostream.IOStreamChannelFactory;
|
||||
import io.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||
@ -24,9 +34,6 @@ import io.netty.handler.codec.frame.Delimiters;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* An example demonstrating the use of the {@link io.netty.channel.iostream.IOStreamChannel}.
|
||||
*/
|
||||
|
@ -66,7 +66,7 @@ public class LocalExampleMultthreaded {
|
||||
// Read commands from array
|
||||
String[] commands = { "First", "Second", "Third", "quit" };
|
||||
for (int j = 0; j < 5 ; j++) {
|
||||
System.err.println("Start "+j);
|
||||
System.err.println("Start " + j);
|
||||
ChannelFuture channelFuture = cb.connect(socketAddress);
|
||||
channelFuture.awaitUninterruptibly();
|
||||
if (! channelFuture.isSuccess()) {
|
||||
@ -87,7 +87,7 @@ public class LocalExampleMultthreaded {
|
||||
channelFuture.getChannel().close();
|
||||
// Wait until the connection is closed or the connection attempt fails.
|
||||
channelFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
||||
System.err.println("End "+j);
|
||||
System.err.println("End " + j);
|
||||
}
|
||||
|
||||
// Release all resources
|
||||
|
@ -73,7 +73,7 @@ public class LocalServerPipelineFactory implements ChannelPipelineFactory {
|
||||
Channels.close(e.getChannel());
|
||||
return;
|
||||
}
|
||||
System.err.println("SERVER:"+msg);
|
||||
System.err.println("SERVER:" + msg);
|
||||
// Write back
|
||||
Channels.write(e.getChannel(), msg);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user