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 fb5cf936a8..c1ae1c206d 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 @@ -20,12 +20,15 @@ import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpRequest; import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpConstants.*; + /** * Encodes an RTSP request represented in {@link FullHttpRequest} into * a {@link ByteBuf}. */ public class RtspRequestEncoder extends RtspObjectEncoder { + private static final byte[] CRLF = { CR, LF }; @Override public boolean acceptOutboundMessage(Object msg) throws Exception { @@ -35,12 +38,11 @@ public class RtspRequestEncoder extends RtspObjectEncoder { @Override protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception { - buf.writeBytes(request.getMethod().toString().getBytes(CharsetUtil.US_ASCII)); - buf.writeByte((byte) ' '); + encodeAscii(request.getMethod().toString(), buf); + buf.writeByte(SP); buf.writeBytes(request.getUri().getBytes(CharsetUtil.UTF_8)); - buf.writeByte((byte) ' '); - buf.writeBytes(request.getProtocolVersion().toString().getBytes(CharsetUtil.US_ASCII)); - buf.writeByte((byte) '\r'); - buf.writeByte((byte) '\n'); + buf.writeByte(SP); + encodeAscii(request.getProtocolVersion().toString(), buf); + 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 34724f0f4f..3474901267 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 @@ -20,12 +20,15 @@ import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpResponse; import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpConstants.*; + /** * Encodes an RTSP response represented in {@link FullHttpResponse} into * a {@link ByteBuf}. */ public class RtspResponseEncoder extends RtspObjectEncoder { + private static final byte[] CRLF = { CR, LF }; @Override public boolean acceptOutboundMessage(Object msg) throws Exception { @@ -35,12 +38,11 @@ public class RtspResponseEncoder extends RtspObjectEncoder { @Override protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception { - buf.writeBytes(response.getProtocolVersion().toString().getBytes(CharsetUtil.US_ASCII)); - buf.writeByte((byte) ' '); + encodeAscii(response.getProtocolVersion().toString(), buf); + buf.writeByte(SP); buf.writeBytes(String.valueOf(response.getStatus().code()).getBytes(CharsetUtil.US_ASCII)); - buf.writeByte((byte) ' '); - buf.writeBytes(String.valueOf(response.getStatus().reasonPhrase()).getBytes(CharsetUtil.US_ASCII)); - buf.writeByte((byte) '\r'); - buf.writeByte((byte) '\n'); + buf.writeByte(SP); + encodeAscii(String.valueOf(response.getStatus().reasonPhrase()), buf); + buf.writeBytes(CRLF); } }