Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Mayank Dang
2014-05-30 16:16:23 +05:30
3 changed files with 28 additions and 5 deletions

View File

@@ -9,7 +9,7 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>2.5.1-SNAPSHOT</version> <version>2.5.2-SNAPSHOT</version>
<name>Jedis</name> <name>Jedis</name>
<description>Jedis is a blazingly small and sane Redis java client.</description> <description>Jedis is a blazingly small and sane Redis java client.</description>
<url>https://github.com/xetorthio/jedis</url> <url>https://github.com/xetorthio/jedis</url>

View File

@@ -34,10 +34,10 @@ public final class RedisOutputStream extends FilterOutputStream {
} }
public void write(final byte b) throws IOException { public void write(final byte b) throws IOException {
buf[count++] = b;
if (count == buf.length) { if (count == buf.length) {
flushBuffer(); flushBuffer();
} }
buf[count++] = b;
} }
public void write(final byte[] b) throws IOException { public void write(final byte[] b) throws IOException {
@@ -63,10 +63,10 @@ public final class RedisOutputStream extends FilterOutputStream {
final int size = in.length(); final int size = in.length();
for (int i = 0; i != size; ++i) { for (int i = 0; i != size; ++i) {
buf[count++] = (byte) in.charAt(i);
if (count == buf.length) { if (count == buf.length) {
flushBuffer(); flushBuffer();
} }
buf[count++] = (byte) in.charAt(i);
} }
writeCrLf(); writeCrLf();
@@ -111,19 +111,19 @@ public final class RedisOutputStream extends FilterOutputStream {
char c = str.charAt(i); char c = str.charAt(i);
if (!(c < 0x80)) if (!(c < 0x80))
break; break;
buf[count++] = (byte) c;
if (count == buf.length) { if (count == buf.length) {
flushBuffer(); flushBuffer();
} }
buf[count++] = (byte) c;
} }
for (; i < strLen; i++) { for (; i < strLen; i++) {
char c = str.charAt(i); char c = str.charAt(i);
if (c < 0x80) { if (c < 0x80) {
buf[count++] = (byte) c;
if (count == buf.length) { if (count == buf.length) {
flushBuffer(); flushBuffer();
} }
buf[count++] = (byte) c;
} else if (c < 0x800) { } else if (c < 0x800) {
if (2 >= buf.length - count) { if (2 >= buf.length - count) {
flushBuffer(); flushBuffer();

View File

@@ -4,6 +4,7 @@ import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
@@ -39,6 +40,28 @@ public class ProtocolTest extends JedisTestBase {
assertEquals(expectedCommand, sb.toString()); assertEquals(expectedCommand, sb.toString());
} }
@Test(expected=IOException.class)
public void writeOverflow() throws IOException {
RedisOutputStream ros = new RedisOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
throw new IOException("thrown exception");
}
});
ros.write(new byte[8191]);
try {
ros.write((byte)'*');
} catch (IOException ioe) {}
ros.write((byte)'*');
}
@Test @Test
public void bulkReply() { public void bulkReply() {
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes()); InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());