* Simplified DefaultObjectSizeEstimator as suggested by Stefan
* Made sure HttpMessage.getContent() does not return null at any case * Improved TelnetServerHandler to send DOS style line delimiter so that it does not look bad in Windows
This commit is contained in:
parent
2bd880e949
commit
4d6255d4ea
@ -65,8 +65,8 @@ public class TelnetServerHandler extends SimpleChannelHandler {
|
|||||||
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||||
// Send greeting for a new connection.
|
// Send greeting for a new connection.
|
||||||
e.getChannel().write(
|
e.getChannel().write(
|
||||||
"Welcome to " + InetAddress.getLocalHost().getHostName() + "!\n");
|
"Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n");
|
||||||
e.getChannel().write("It is " + new Date() + " now.\n");
|
e.getChannel().write("It is " + new Date() + " now.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,12 +81,12 @@ public class TelnetServerHandler extends SimpleChannelHandler {
|
|||||||
String response;
|
String response;
|
||||||
boolean close = false;
|
boolean close = false;
|
||||||
if (request.length() == 0) {
|
if (request.length() == 0) {
|
||||||
response = "Please type something.\n";
|
response = "Please type something.\r\n";
|
||||||
} else if (request.toLowerCase().equals("bye")) {
|
} else if (request.toLowerCase().equals("bye")) {
|
||||||
response = "Have a good day!\n";
|
response = "Have a good day!\r\n";
|
||||||
close = true;
|
close = true;
|
||||||
} else {
|
} else {
|
||||||
response = "Did you say '" + request + "'?\n";
|
response = "Did you say '" + request + "'?\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not need to write a ChannelBuffer here.
|
// We do not need to write a ChannelBuffer here.
|
||||||
|
@ -178,7 +178,10 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
headers.clear();
|
headers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(final ChannelBuffer content) {
|
public void setContent(ChannelBuffer content) {
|
||||||
|
if (content == null) {
|
||||||
|
content = ChannelBuffers.EMPTY_BUFFER;
|
||||||
|
}
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder {
|
|||||||
header.writeBytes(CRLF);
|
header.writeBytes(CRLF);
|
||||||
|
|
||||||
ChannelBuffer content = request.getContent();
|
ChannelBuffer content = request.getContent();
|
||||||
if (content == null) {
|
if (!content.readable()) {
|
||||||
return header; // no content
|
return header; // no content
|
||||||
} else {
|
} else {
|
||||||
return wrappedBuffer(header, content);
|
return wrappedBuffer(header, content);
|
||||||
|
@ -130,10 +130,9 @@ public class DefaultObjectSizeEstimator implements ObjectSizeEstimator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int align(int size) {
|
private static int align(int size) {
|
||||||
if (size % 8 != 0) {
|
int r = size % 8;
|
||||||
size /= 8;
|
if (r != 0) {
|
||||||
size ++;
|
size += 8 - r;
|
||||||
size *= 8;
|
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user