[#766] Rename method to extractFrame(..), no need to make it more complicated in 3

This commit is contained in:
Norman Maurer 2012-11-25 17:53:56 +01:00
parent bc1ef572b9
commit ef481bfedb
7 changed files with 10 additions and 30 deletions

View File

@ -232,7 +232,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
if (minDelim != null) { if (minDelim != null) {
int minDelimLength = minDelim.capacity(); int minDelimLength = minDelim.capacity();
Object frame; ChannelBuffer frame;
if (discardingTooLongFrame) { if (discardingTooLongFrame) {
// We've just finished discarding a very large frame. // We've just finished discarding a very large frame.
@ -256,9 +256,9 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
} }
if (stripDelimiter) { if (stripDelimiter) {
frame = extract(buffer, buffer.readerIndex(), minFrameLength); frame = extractFrame(buffer, buffer.readerIndex(), minFrameLength);
} else { } else {
frame = extract(buffer, buffer.readerIndex(), minFrameLength + minDelimLength); frame = extractFrame(buffer, buffer.readerIndex(), minFrameLength + minDelimLength);
} }
buffer.skipBytes(minFrameLength + minDelimLength); buffer.skipBytes(minFrameLength + minDelimLength);

View File

@ -72,7 +72,7 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
if (buffer.readableBytes() < frameLength) { if (buffer.readableBytes() < frameLength) {
return null; return null;
} else { } else {
Object frame = extract(buffer, buffer.readerIndex(), frameLength); ChannelBuffer frame = extractFrame(buffer, buffer.readerIndex(), frameLength);
buffer.skipBytes(frameLength); buffer.skipBytes(frameLength);
return frame; return frame;
} }

View File

@ -382,7 +382,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
* Decodes the received packets so far into a frame. * Decodes the received packets so far into a frame.
* *
* If an sub-class wants to extract a frame out of the buffer it should use * If an sub-class wants to extract a frame out of the buffer it should use
* the {@link #extract(org.jboss.netty.buffer.ChannelBuffer, int, int)} method, * the {@link #extractFrame(org.jboss.netty.buffer.ChannelBuffer, int, int)} method,
* to make optimizations easier later. * to make optimizations easier later.
* *
* @param ctx the context of this handler * @param ctx the context of this handler
@ -566,7 +566,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
* <strong>Be sure that this method MUST not modify the readerIndex of the given buffer</strong> * <strong>Be sure that this method MUST not modify the readerIndex of the given buffer</strong>
* *
*/ */
protected Object extract(ChannelBuffer buffer, int index, int length) { protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) {
ChannelBuffer frame = buffer.factory().getBuffer(length); ChannelBuffer frame = buffer.factory().getBuffer(length);
frame.writeBytes(buffer, index, length); frame.writeBytes(buffer, index, length);
return frame; return frame;

View File

@ -390,21 +390,11 @@ public class LengthFieldBasedFrameDecoder extends FrameDecoder {
// extract frame // extract frame
int readerIndex = buffer.readerIndex(); int readerIndex = buffer.readerIndex();
int actualFrameLength = frameLengthInt - initialBytesToStrip; int actualFrameLength = frameLengthInt - initialBytesToStrip;
Object frame = extract(buffer, readerIndex, actualFrameLength); ChannelBuffer frame = extractFrame(buffer, readerIndex, actualFrameLength);
buffer.readerIndex(readerIndex + actualFrameLength); buffer.readerIndex(readerIndex + actualFrameLength);
return frame; return frame;
} }
protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) {
ChannelBuffer frame = buffer.factory().getBuffer(length);
frame.writeBytes(buffer, index, length);
return frame;
}
@Override
protected Object extract(ChannelBuffer buffer, int index, int length) {
return extractFrame(buffer, index, length);
}
private void failIfNecessary(ChannelHandlerContext ctx, boolean firstDetectionOfTooLongFrame) { private void failIfNecessary(ChannelHandlerContext ctx, boolean firstDetectionOfTooLongFrame) {
if (bytesToDiscard == 0) { if (bytesToDiscard == 0) {

View File

@ -74,7 +74,7 @@ public class LineBasedFrameDecoder extends FrameDecoder {
final ChannelBuffer buffer) throws Exception { final ChannelBuffer buffer) throws Exception {
final int eol = findEndOfLine(buffer); final int eol = findEndOfLine(buffer);
if (eol != -1) { if (eol != -1) {
final Object frame; final ChannelBuffer frame;
final int length = eol - buffer.readerIndex(); final int length = eol - buffer.readerIndex();
assert length >= 0: "Invalid length=" + length; assert length >= 0: "Invalid length=" + length;
if (discarding) { if (discarding) {
@ -92,9 +92,9 @@ public class LineBasedFrameDecoder extends FrameDecoder {
delimLength = 1; delimLength = 1;
} }
if (stripDelimiter) { if (stripDelimiter) {
frame = extract(buffer, buffer.readerIndex(), length); frame = extractFrame(buffer, buffer.readerIndex(), length);
} else { } else {
frame = extract(buffer, buffer.readerIndex(), length + delimLength); frame = extractFrame(buffer, buffer.readerIndex(), length + delimLength);
} }
buffer.skipBytes(length + delimLength); buffer.skipBytes(length + delimLength);

View File

@ -88,9 +88,4 @@ public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) { protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) {
return buffer.slice(index, length); return buffer.slice(index, length);
} }
@Override
protected final Object extract(ChannelBuffer buffer, int index, int length) {
return super.extract(buffer, index, length);
}
} }

View File

@ -132,9 +132,4 @@ public class ObjectDecoder extends LengthFieldBasedFrameDecoder {
protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) { protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) {
return buffer.slice(index, length); return buffer.slice(index, length);
} }
@Override
protected final Object extract(ChannelBuffer buffer, int index, int length) {
return super.extract(buffer, index, length);
}
} }