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(
|
||||
NioDatagramChannel channel, ChannelFuture future,
|
||||
SocketAddress remoteAddress) {
|
||||
InetSocketAddress remoteAddress) {
|
||||
|
||||
boolean bound = channel.isBound();
|
||||
boolean connected = false;
|
||||
|
@ -15,14 +15,6 @@
|
||||
*/
|
||||
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.ChannelBuffers;
|
||||
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.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 {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
@ -292,10 +292,7 @@ public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (fileUpload.length() < 10000) {
|
||||
responseContent.append("\tContent of file\r\n");
|
||||
try {
|
||||
responseContent
|
||||
.append(((FileUpload) data)
|
||||
.getString(((FileUpload) data)
|
||||
.getCharset()));
|
||||
responseContent.append(fileUpload.getString(fileUpload.getCharset()));
|
||||
} catch (IOException e1) {
|
||||
// do nothing for the example
|
||||
e1.printStackTrace();
|
||||
|
@ -65,8 +65,8 @@ public class Base64Decoder extends OneToOneDecoder {
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
|
||||
throws Exception {
|
||||
if (msg instanceof String) {
|
||||
msg = ChannelBuffers.copiedBuffer((String) msg, CharsetUtil.US_ASCII);
|
||||
if (msg instanceof CharSequence) {
|
||||
msg = ChannelBuffers.copiedBuffer((CharSequence) msg, CharsetUtil.US_ASCII);
|
||||
} else if (!(msg instanceof ChannelBuffer)) {
|
||||
return msg;
|
||||
}
|
||||
|
@ -15,16 +15,6 @@
|
||||
*/
|
||||
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.ChannelBuffers;
|
||||
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.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.
|
||||
*/
|
||||
@ -743,7 +743,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
buffer = ((FileUpload) currentData).getChunk(sizeleft);
|
||||
buffer = ((HttpData) currentData).getChunk(sizeleft);
|
||||
} catch (IOException e) {
|
||||
throw new ErrorDataEncoderException(e);
|
||||
}
|
||||
@ -805,7 +805,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
|
||||
}
|
||||
}
|
||||
try {
|
||||
buffer = ((Attribute) currentData).getChunk(size);
|
||||
buffer = ((HttpData) currentData).getChunk(size);
|
||||
} catch (IOException e) {
|
||||
throw new ErrorDataEncoderException(e);
|
||||
}
|
||||
|
@ -15,10 +15,6 @@
|
||||
*/
|
||||
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.channel.Channel;
|
||||
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.oneone.OneToOneEncoder;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
||||
|
||||
/**
|
||||
* 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:
|
||||
@ -87,9 +87,10 @@ public class StringEncoder extends OneToOneEncoder {
|
||||
@Override
|
||||
protected Object encode(
|
||||
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
||||
if (!(msg instanceof String)) {
|
||||
if (!(msg instanceof CharSequence)) {
|
||||
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")
|
||||
K key() {
|
||||
return ((WeakReference<K>) keyRef).get();
|
||||
return ((Reference<K>) keyRef).get();
|
||||
}
|
||||
|
||||
V value() {
|
||||
|
@ -198,7 +198,7 @@ public final class ConcurrentWeakKeyHashMap<K, V> extends AbstractMap<K, V> impl
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
K key() {
|
||||
return ((WeakReference<K>) keyRef).get();
|
||||
return ((Reference<K>) keyRef).get();
|
||||
}
|
||||
|
||||
V value() {
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.jboss.netty.util.internal;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test for {@link StringUtil}.
|
||||
*/
|
||||
@ -37,8 +37,8 @@ public class StringUtilTest {
|
||||
@Test
|
||||
public void stripControlCharactersRightTrim() {
|
||||
final char controlCode = 0x0000;
|
||||
final Object object = "abbb" + controlCode;
|
||||
assertEquals(5, ((String) object).length());
|
||||
final String object = "abbb" + controlCode;
|
||||
assertEquals(5, object.length());
|
||||
|
||||
final String stripped = StringUtil.stripControlCharacters(object);
|
||||
assertFalse(object.equals(stripped));
|
||||
|
Loading…
x
Reference in New Issue
Block a user