From 4baea3ea7a04bb0390055b57fe6ca82c58580c1d Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Sat, 25 Apr 2015 14:24:39 -0700 Subject: [PATCH] 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. --- .../io/netty/handler/codec/http/HttpRequestEncoder.java | 5 +++-- .../io/netty/handler/codec/http/HttpResponseEncoder.java | 7 ++++--- .../io/netty/handler/codec/rtsp/RtspRequestEncoder.java | 5 +++-- .../io/netty/handler/codec/rtsp/RtspResponseEncoder.java | 7 ++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java index 14164fcc66..a8229d2fbf 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java @@ -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 { @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 { buf.writeByte(SP); AsciiString version = request.protocolVersion().text(); - buf.writeBytes(version.array()); + ByteBufUtil.copy(version, version.arrayOffset(), buf, version.length()); buf.writeBytes(CRLF); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java index 8e6e513650..8b790a70fb 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java @@ -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 { @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); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestEncoder.java index 259571cb6a..d73fd5d8f9 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspRequestEncoder.java @@ -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 { @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); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseEncoder.java index b723e6ebcf..499c4c9579 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspResponseEncoder.java @@ -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 { @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); } }