ByteString arrayOffset master branch cleanup
Motivation:
Commit f1e122a
introduced the arrayOffset method into the ByteString class. That means anywhere that used the array() method must also use the arrayOffset() method.
Modifications:
- Find all uses of ByteString.array() and ensure they are taking into account ByteString.arrayOffset().
Result:
The correct data from ByteString.array() will be used.
This commit is contained in:
parent
f1e122a0c1
commit
4baea3ea7a
@ -19,6 +19,7 @@ import static io.netty.handler.codec.http.HttpConstants.CR;
|
||||
import static io.netty.handler.codec.http.HttpConstants.LF;
|
||||
import static io.netty.handler.codec.http.HttpConstants.SP;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.AsciiString;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
@ -39,7 +40,7 @@ public class HttpRequestEncoder extends HttpObjectEncoder<HttpRequest> {
|
||||
@Override
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception {
|
||||
AsciiString method = request.method().name();
|
||||
buf.writeBytes(method.array());
|
||||
ByteBufUtil.copy(method, method.arrayOffset(), buf, method.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
// Add / as absolute path if no is present.
|
||||
@ -76,7 +77,7 @@ public class HttpRequestEncoder extends HttpObjectEncoder<HttpRequest> {
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString version = request.protocolVersion().text();
|
||||
buf.writeBytes(version.array());
|
||||
ByteBufUtil.copy(version, version.arrayOffset(), buf, version.length());
|
||||
buf.writeBytes(CRLF);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import static io.netty.handler.codec.http.HttpConstants.CR;
|
||||
import static io.netty.handler.codec.http.HttpConstants.LF;
|
||||
import static io.netty.handler.codec.http.HttpConstants.SP;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.AsciiString;
|
||||
|
||||
/**
|
||||
@ -36,15 +37,15 @@ public class HttpResponseEncoder extends HttpObjectEncoder<HttpResponse> {
|
||||
@Override
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception {
|
||||
AsciiString version = response.protocolVersion().text();
|
||||
buf.writeBytes(version.array());
|
||||
ByteBufUtil.copy(version, version.arrayOffset(), buf, version.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString code = response.status().codeAsText();
|
||||
buf.writeBytes(code.array());
|
||||
ByteBufUtil.copy(code, code.arrayOffset(), buf, code.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString reasonPhrase = response.status().reasonPhrase();
|
||||
buf.writeBytes(reasonPhrase.array());
|
||||
ByteBufUtil.copy(reasonPhrase, reasonPhrase.arrayOffset(), buf, reasonPhrase.length());
|
||||
buf.writeBytes(CRLF);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import static io.netty.handler.codec.http.HttpConstants.CR;
|
||||
import static io.netty.handler.codec.http.HttpConstants.LF;
|
||||
import static io.netty.handler.codec.http.HttpConstants.SP;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.util.AsciiString;
|
||||
@ -40,14 +41,14 @@ public class RtspRequestEncoder extends RtspObjectEncoder<HttpRequest> {
|
||||
@Override
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception {
|
||||
AsciiString method = request.method().name();
|
||||
buf.writeBytes(method.array());
|
||||
ByteBufUtil.copy(method, method.arrayOffset(), buf, method.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
buf.writeBytes(request.uri().getBytes(CharsetUtil.UTF_8));
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString version = request.protocolVersion().text();
|
||||
buf.writeBytes(version.array());
|
||||
ByteBufUtil.copy(version, version.arrayOffset(), buf, version.length());
|
||||
buf.writeBytes(CRLF);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import static io.netty.handler.codec.http.HttpConstants.CR;
|
||||
import static io.netty.handler.codec.http.HttpConstants.LF;
|
||||
import static io.netty.handler.codec.http.HttpConstants.SP;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.util.AsciiString;
|
||||
@ -38,15 +39,15 @@ public class RtspResponseEncoder extends RtspObjectEncoder<HttpResponse> {
|
||||
@Override
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception {
|
||||
AsciiString version = response.protocolVersion().text();
|
||||
buf.writeBytes(version.array());
|
||||
ByteBufUtil.copy(version, version.arrayOffset(), buf, version.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString code = response.status().codeAsText();
|
||||
buf.writeBytes(code.array());
|
||||
ByteBufUtil.copy(code, code.arrayOffset(), buf, code.length());
|
||||
buf.writeByte(SP);
|
||||
|
||||
AsciiString reasonPhrase = response.status().reasonPhrase();
|
||||
buf.writeBytes(reasonPhrase.array());
|
||||
ByteBufUtil.copy(reasonPhrase, reasonPhrase.arrayOffset(), buf, reasonPhrase.length());
|
||||
buf.writeBytes(CRLF);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user