Fix overly-strong type casts
This commit is contained in:
parent
1a006fafad
commit
3e21e3250f
|
@ -147,7 +147,7 @@ class NioDatagramPipelineSink extends AbstractNioChannelSink {
|
||||||
|
|
||||||
private static void connect(
|
private static void connect(
|
||||||
NioDatagramChannel channel, ChannelFuture future,
|
NioDatagramChannel channel, ChannelFuture future,
|
||||||
SocketAddress remoteAddress) {
|
InetSocketAddress remoteAddress) {
|
||||||
|
|
||||||
boolean bound = channel.isBound();
|
boolean bound = channel.isBound();
|
||||||
boolean connected = false;
|
boolean connected = false;
|
||||||
|
|
|
@ -15,14 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jboss.netty.example.http.upload;
|
package org.jboss.netty.example.http.upload;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
|
@ -62,6 +54,14 @@ import org.jboss.netty.logging.InternalLogger;
|
||||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||||
import org.jboss.netty.util.CharsetUtil;
|
import org.jboss.netty.util.CharsetUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
private static final InternalLogger logger =
|
private static final InternalLogger logger =
|
||||||
|
@ -292,10 +292,7 @@ public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
||||||
if (fileUpload.length() < 10000) {
|
if (fileUpload.length() < 10000) {
|
||||||
responseContent.append("\tContent of file\r\n");
|
responseContent.append("\tContent of file\r\n");
|
||||||
try {
|
try {
|
||||||
responseContent
|
responseContent.append(fileUpload.getString(fileUpload.getCharset()));
|
||||||
.append(((FileUpload) data)
|
|
||||||
.getString(((FileUpload) data)
|
|
||||||
.getCharset()));
|
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
// do nothing for the example
|
// do nothing for the example
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
|
|
@ -65,8 +65,8 @@ public class Base64Decoder extends OneToOneDecoder {
|
||||||
@Override
|
@Override
|
||||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
|
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (msg instanceof String) {
|
if (msg instanceof CharSequence) {
|
||||||
msg = ChannelBuffers.copiedBuffer((String) msg, CharsetUtil.US_ASCII);
|
msg = ChannelBuffers.copiedBuffer((CharSequence) msg, CharsetUtil.US_ASCII);
|
||||||
} else if (!(msg instanceof ChannelBuffer)) {
|
} else if (!(msg instanceof ChannelBuffer)) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,16 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jboss.netty.handler.codec.http.multipart;
|
package org.jboss.netty.handler.codec.http.multipart;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
import org.jboss.netty.handler.codec.http.DefaultHttpChunk;
|
import org.jboss.netty.handler.codec.http.DefaultHttpChunk;
|
||||||
|
@ -35,6 +25,16 @@ import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||||
import org.jboss.netty.handler.stream.ChunkedInput;
|
import org.jboss.netty.handler.stream.ChunkedInput;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This encoder will help to encode Request for a FORM as POST.
|
* This encoder will help to encode Request for a FORM as POST.
|
||||||
*/
|
*/
|
||||||
|
@ -743,7 +743,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
buffer = ((FileUpload) currentData).getChunk(sizeleft);
|
buffer = ((HttpData) currentData).getChunk(sizeleft);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ErrorDataEncoderException(e);
|
throw new ErrorDataEncoderException(e);
|
||||||
}
|
}
|
||||||
|
@ -805,7 +805,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
buffer = ((Attribute) currentData).getChunk(size);
|
buffer = ((HttpData) currentData).getChunk(size);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ErrorDataEncoderException(e);
|
throw new ErrorDataEncoderException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jboss.netty.handler.codec.string;
|
package org.jboss.netty.handler.codec.string;
|
||||||
|
|
||||||
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||||
|
@ -29,6 +25,10 @@ import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||||
import org.jboss.netty.handler.codec.frame.Delimiters;
|
import org.jboss.netty.handler.codec.frame.Delimiters;
|
||||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes the requested {@link String} into a {@link ChannelBuffer}.
|
* Encodes the requested {@link String} into a {@link ChannelBuffer}.
|
||||||
* A typical setup for a text-based line protocol in a TCP/IP socket would be:
|
* A typical setup for a text-based line protocol in a TCP/IP socket would be:
|
||||||
|
@ -87,9 +87,10 @@ public class StringEncoder extends OneToOneEncoder {
|
||||||
@Override
|
@Override
|
||||||
protected Object encode(
|
protected Object encode(
|
||||||
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
||||||
if (!(msg instanceof String)) {
|
if (!(msg instanceof CharSequence)) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
return copiedBuffer(ctx.getChannel().getConfig().getBufferFactory().getDefaultOrder(), (String) msg, charset);
|
return copiedBuffer(
|
||||||
|
ctx.getChannel().getConfig().getBufferFactory().getDefaultOrder(), (CharSequence) msg, charset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
K key() {
|
K key() {
|
||||||
return ((WeakReference<K>) keyRef).get();
|
return ((Reference<K>) keyRef).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
V value() {
|
V value() {
|
||||||
|
|
|
@ -198,7 +198,7 @@ public final class ConcurrentWeakKeyHashMap<K, V> extends AbstractMap<K, V> impl
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
K key() {
|
K key() {
|
||||||
return ((WeakReference<K>) keyRef).get();
|
return ((Reference<K>) keyRef).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
V value() {
|
V value() {
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jboss.netty.util.internal;
|
package org.jboss.netty.util.internal;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for {@link StringUtil}.
|
* Unit test for {@link StringUtil}.
|
||||||
*/
|
*/
|
||||||
|
@ -37,8 +37,8 @@ public class StringUtilTest {
|
||||||
@Test
|
@Test
|
||||||
public void stripControlCharactersRightTrim() {
|
public void stripControlCharactersRightTrim() {
|
||||||
final char controlCode = 0x0000;
|
final char controlCode = 0x0000;
|
||||||
final Object object = "abbb" + controlCode;
|
final String object = "abbb" + controlCode;
|
||||||
assertEquals(5, ((String) object).length());
|
assertEquals(5, object.length());
|
||||||
|
|
||||||
final String stripped = StringUtil.stripControlCharacters(object);
|
final String stripped = StringUtil.stripControlCharacters(object);
|
||||||
assertFalse(object.equals(stripped));
|
assertFalse(object.equals(stripped));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user