Skip to content

Commit

Permalink
Deprecate ByteBufIndexFinder
Browse files Browse the repository at this point in the history
- Prefer ByteBufProcessor
- Related: netty#1378
  • Loading branch information
trustin committed Jun 27, 2013
1 parent 4dd9b6e commit 792edf6
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 20 deletions.
7 changes: 5 additions & 2 deletions buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ public int indexOf(int fromIndex, int toIndex, byte value) {
}

@Override
@Deprecated
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
return ByteBufUtil.indexOf(this, fromIndex, toIndex, indexFinder);
}
Expand All @@ -997,6 +998,7 @@ public int bytesBefore(byte value) {
}

@Override
@Deprecated
public int bytesBefore(ByteBufIndexFinder indexFinder) {
return bytesBefore(readerIndex(), readableBytes(), indexFinder);
}
Expand All @@ -1008,6 +1010,7 @@ public int bytesBefore(int length, byte value) {
}

@Override
@Deprecated
public int bytesBefore(int length, ByteBufIndexFinder indexFinder) {
checkReadableBytes(length);
return bytesBefore(readerIndex(), length, indexFinder);
Expand All @@ -1023,8 +1026,8 @@ public int bytesBefore(int index, int length, byte value) {
}

@Override
public int bytesBefore(int index, int length,
ByteBufIndexFinder indexFinder) {
@Deprecated
public int bytesBefore(int index, int length, ByteBufIndexFinder indexFinder) {
int endIndex = indexOf(index, index + length, indexFinder);
if (endIndex < 0) {
return -1;
Expand Down
25 changes: 17 additions & 8 deletions buffer/src/main/java/io/netty/buffer/ByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,12 @@
*
* <h3>Search operations</h3>
*
* Various {@link #indexOf(int, int, byte)} methods help you locate an index of
* a value which meets a certain criteria. Complicated dynamic sequential
* search can be done with {@link ByteBufIndexFinder} as well as simple
* static single byte search.
* <p>
* If you are decoding variable length data such as NUL-terminated string, you
* will find {@link #bytesBefore(byte)} also useful.
* For simple single-byte searches, use {@link #indexOf(int, int, byte)} and {@link #bytesBefore(int, int, byte)}.
* {@link #bytesBefore(byte)} is especially useful when you deal with a {@code NUL}-terminated string.
* For complicated searches, use {@link #forEachByte(int, int, ByteBufProcessor)} with a {@link ByteBufProcessor}
* implementation.
*
* <h3>Mark and reset</h3>
* <h3>Mark and reset</h3>
*
* There are two marker indexes in every buffer. One is for storing
* {@link #readerIndex() readerIndex} and the other is for storing
Expand Down Expand Up @@ -1577,6 +1574,8 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
int indexOf(int fromIndex, int toIndex, byte value);

/**
* @deprecated Use {@link #forEachByte(int, int, ByteBufProcessor)} instead.
*
* Locates the first place where the specified {@code indexFinder}
* returns {@code true}. The search takes place from the specified
* {@code fromIndex} (inclusive) to the specified {@code toIndex}
Expand All @@ -1592,6 +1591,7 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
* returned {@code true}. {@code -1} if the {@code indexFinder}
* did not return {@code true} at all.
*/
@Deprecated
int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder);

/**
Expand All @@ -1608,6 +1608,8 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
int bytesBefore(byte value);

/**
* @deprecated Use {@link #forEachByte(ByteBufProcessor)} instead.
*
* Locates the first place where the specified {@code indexFinder} returns
* {@code true}. The search takes place from the current {@code readerIndex}
* (inclusive) to the current {@code writerIndex}.
Expand All @@ -1620,6 +1622,7 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
* {@code true}. {@code -1} if the {@code indexFinder} did not
* return {@code true} at all.
*/
@Deprecated
int bytesBefore(ByteBufIndexFinder indexFinder);

/**
Expand All @@ -1639,6 +1642,8 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
int bytesBefore(int length, byte value);

/**
* @deprecated Use {@link #forEachByte(int, int, ByteBufProcessor)} instead.
*
* Locates the first place where the specified {@code indexFinder} returns
* {@code true}. The search starts the current {@code readerIndex}
* (inclusive) and lasts for the specified {@code length}.
Expand All @@ -1654,6 +1659,7 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
* @throws IndexOutOfBoundsException
* if {@code length} is greater than {@code this.readableBytes}
*/
@Deprecated
int bytesBefore(int length, ByteBufIndexFinder indexFinder);

/**
Expand All @@ -1673,6 +1679,8 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
int bytesBefore(int index, int length, byte value);

/**
* @deprecated Use {@link #forEachByte(int, int, ByteBufProcessor)} instead.
*
* Locates the first place where the specified {@code indexFinder} returns
* {@code true}. The search starts the specified {@code index} (inclusive)
* and lasts for the specified {@code length}.
Expand All @@ -1688,6 +1696,7 @@ public interface ByteBuf extends ReferenceCounted, Comparable<ByteBuf> {
* @throws IndexOutOfBoundsException
* if {@code index + length} is greater than {@code this.capacity}
*/
@Deprecated
int bytesBefore(int index, int length, ByteBufIndexFinder indexFinder);

/**
Expand Down
42 changes: 36 additions & 6 deletions buffer/src/main/java/io/netty/buffer/ByteBufIndexFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


/**
* @deprecated Use {@link ByteBufProcessor} instead.
*
* Locates an index of data in a {@link ByteBuf}.
* <p>
* This interface enables the sequential search for the data which meets more
Expand All @@ -25,6 +27,7 @@
* {@link ByteBuf#bytesBefore(int, int, ByteBufIndexFinder)}
* for more explanation.
*/
@Deprecated
public interface ByteBufIndexFinder {

/**
Expand All @@ -38,8 +41,11 @@ public interface ByteBufIndexFinder {
boolean find(ByteBuf buffer, int guessedIndex);

/**
* @deprecated Use {@link ByteBufProcessor#FIND_NUL} instead.
*
* Index finder which locates a {@code NUL (0x00)} byte.
*/
@Deprecated
ByteBufIndexFinder NUL = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -48,8 +54,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_NON_NUL} instead.
*
* Index finder which locates a non-{@code NUL (0x00)} byte.
*/
@Deprecated
ByteBufIndexFinder NOT_NUL = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -58,8 +67,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_CR} instead.
*
* Index finder which locates a {@code CR ('\r')} byte.
*/
@Deprecated
ByteBufIndexFinder CR = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -68,8 +80,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_NON_CR} instead.
*
* Index finder which locates a non-{@code CR ('\r')} byte.
*/
@Deprecated
ByteBufIndexFinder NOT_CR = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -78,8 +93,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_LF} instead.
*
* Index finder which locates a {@code LF ('\n')} byte.
*/
@Deprecated
ByteBufIndexFinder LF = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -88,8 +106,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_NON_LF} instead.
*
* Index finder which locates a non-{@code LF ('\n')} byte.
*/
@Deprecated
ByteBufIndexFinder NOT_LF = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -98,8 +119,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* @deprecated Use {@link ByteBufProcessor#FIND_CRLF} instead.
*
* Index finder which locates a {@code CR ('\r')} or {@code LF ('\n')}.
*/
@Deprecated
ByteBufIndexFinder CRLF = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -109,9 +133,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* Index finder which locates a byte which is neither a {@code CR ('\r')}
* nor a {@code LF ('\n')}.
* @deprecated Use {@link ByteBufProcessor#FIND_NON_CRLF} instead.
*
* Index finder which locates a byte which is neither a {@code CR ('\r')} nor a {@code LF ('\n')}.
*/
@Deprecated
ByteBufIndexFinder NOT_CRLF = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -121,9 +147,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* Index finder which locates a linear whitespace
* ({@code ' '} and {@code '\t'}).
* @deprecated Use {@link ByteBufProcessor#FIND_LINEAR_WHITESPACE} instead.
*
* Index finder which locates a linear whitespace ({@code ' '} and {@code '\t'}).
*/
@Deprecated
ByteBufIndexFinder LINEAR_WHITESPACE = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand All @@ -133,9 +161,11 @@ public boolean find(ByteBuf buffer, int guessedIndex) {
};

/**
* Index finder which locates a byte which is not a linear whitespace
* (neither {@code ' '} nor {@code '\t'}).
* @deprecated Use {@link ByteBufProcessor#FIND_NON_LINEAR_WHITESPACE} instead.
*
* Index finder which locates a byte which is not a linear whitespace (neither {@code ' '} nor {@code '\t'}).
*/
@Deprecated
ByteBufIndexFinder NOT_LINEAR_WHITESPACE = new ByteBufIndexFinder() {
@Override
public boolean find(ByteBuf buffer, int guessedIndex) {
Expand Down
Loading

0 comments on commit 792edf6

Please sign in to comment.