Skip to content

Commit

Permalink
ISPN-8594 Memcached not finding UTF-8 data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Fernandes authored and tristantarrant committed Dec 11, 2017
1 parent 0f68451 commit 0ed4343
Showing 1 changed file with 17 additions and 17 deletions.
Expand Up @@ -20,7 +20,8 @@
* @since 4.1
*/
public class TextProtocolUtil {
private TextProtocolUtil() { }
private TextProtocolUtil() {
}
// todo: refactor name once old code has been removed?

public static final String CRLF = "\r\n";
Expand Down Expand Up @@ -56,7 +57,7 @@ private TextProtocolUtil() { }
* found instead of end of operation character, then it'd return the element and false.
*/
static boolean readElement(ByteBuf buffer, OutputStream byteBuffer) throws IOException {
for (;;) {
for (; ; ) {
byte next = buffer.readByte();
if (next == SP) { // Space
return false;
Expand All @@ -80,7 +81,7 @@ static String extractString(ByteArrayOutputStream byteBuffer) {
}

static KeyValuePair<String, Boolean> readElement(ByteBuf buffer, StringBuilder sb) {
for(;;) {
for (; ; ) {
byte next = buffer.readByte();
if (next == SP) { // Space
return new KeyValuePair<>(sb.toString().trim(), false);
Expand Down Expand Up @@ -109,7 +110,7 @@ private static int readableBytes(ByteBuf buffer) {
}

private static String readDiscardedLine(ByteBuf buffer, StringBuilder sb) {
for(;;) {
for (; ; ) {
byte next = buffer.readByte();
if (next == CR) { // CR
next = buffer.readByte();
Expand All @@ -128,7 +129,7 @@ private static String readDiscardedLine(ByteBuf buffer, StringBuilder sb) {
}

static void skipLine(ByteBuf buffer) {
for (;;) {
for (; ; ) {
byte next = buffer.readByte();
if (next == CR) { // CR
next = buffer.readByte();
Expand All @@ -142,33 +143,32 @@ static void skipLine(ByteBuf buffer) {
}

static byte[] concat(byte[] a, byte[] b) {
byte[] data = new byte[a.length + b.length];
System.arraycopy(a, 0, data, 0, a.length);
System.arraycopy(b, 0, data, a.length, b.length);
return data;
byte[] data = new byte[a.length + b.length];
System.arraycopy(a, 0, data, 0, a.length);
System.arraycopy(b, 0, data, a.length, b.length);
return data;
}

static List<String> readSplitLine(ByteBuf buffer) {
List<String> r = new ArrayList<>(3);
StringBuilder sb = new StringBuilder();
for(;;) {
ByteArrayOutputStream sb = new ByteArrayOutputStream();
for (; ; ) {
byte next = buffer.readByte();
if (next == CR) { // CR
next = buffer.readByte();
if (next == LF) { // LF
r.add(sb.toString());
r.add(extractString(sb));
return r;
} else {
sb.append((char) next);
sb.write(next);
}
} else if (next == LF) { // LF
r.add(sb.toString());
r.add(extractString(sb));
return r;
} else if (next == SP) {
r.add(sb.toString());
sb = new StringBuilder();
r.add(extractString(sb));
} else {
sb.append((char) next);
sb.write(next);
}
}
}
Expand Down

0 comments on commit 0ed4343

Please sign in to comment.