* 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:
Trustin Lee 2009-04-02 09:10:57 +00:00
parent 2bd880e949
commit 4d6255d4ea
4 changed files with 13 additions and 11 deletions

View File

@ -65,8 +65,8 @@ public class TelnetServerHandler extends SimpleChannelHandler {
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
// Send greeting for a new connection.
e.getChannel().write(
"Welcome to " + InetAddress.getLocalHost().getHostName() + "!\n");
e.getChannel().write("It is " + new Date() + " now.\n");
"Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n");
e.getChannel().write("It is " + new Date() + " now.\r\n");
}
@Override
@ -81,12 +81,12 @@ public class TelnetServerHandler extends SimpleChannelHandler {
String response;
boolean close = false;
if (request.length() == 0) {
response = "Please type something.\n";
response = "Please type something.\r\n";
} else if (request.toLowerCase().equals("bye")) {
response = "Have a good day!\n";
response = "Have a good day!\r\n";
close = true;
} else {
response = "Did you say '" + request + "'?\n";
response = "Did you say '" + request + "'?\r\n";
}
// We do not need to write a ChannelBuffer here.

View File

@ -178,7 +178,10 @@ public class DefaultHttpMessage implements HttpMessage {
headers.clear();
}
public void setContent(final ChannelBuffer content) {
public void setContent(ChannelBuffer content) {
if (content == null) {
content = ChannelBuffers.EMPTY_BUFFER;
}
this.content = content;
}

View File

@ -58,7 +58,7 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder {
header.writeBytes(CRLF);
ChannelBuffer content = request.getContent();
if (content == null) {
if (!content.readable()) {
return header; // no content
} else {
return wrappedBuffer(header, content);

View File

@ -130,10 +130,9 @@ public class DefaultObjectSizeEstimator implements ObjectSizeEstimator {
}
private static int align(int size) {
if (size % 8 != 0) {
size /= 8;
size ++;
size *= 8;
int r = size % 8;
if (r != 0) {
size += 8 - r;
}
return size;
}