more optimizations on write side

This commit is contained in:
Alex Tkachman
2010-09-12 17:05:58 +02:00
parent aed824c94c
commit f9e7887e02
5 changed files with 186 additions and 109 deletions

View File

@@ -1,21 +1,15 @@
package redis.clients.util;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
/**
* The class implements a buffered output stream without synchronization
* There are also special operations like in-place string encoding
* There are also special operations like in-place string encoding.
* This stream fully ignore mark/reset and should not be used outside Jedis
*/
public final class RedisOutputStream extends FilterOutputStream {
protected final byte buf[];
protected final ByteBuffer outByteBuffer;
private final CharsetEncoder CHARSET_ENCODER = CHARSET.newEncoder();
protected int count;
public static final Charset CHARSET = Charset.forName("UTF-8");
@@ -30,13 +24,11 @@ public final class RedisOutputStream extends FilterOutputStream {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
outByteBuffer = ByteBuffer.wrap(buf);
}
private void flushBuffer() throws IOException {
if (count > 0) {
out.write(buf, 0, count);
outByteBuffer.position(0);
count = 0;
}
}
@@ -233,4 +225,4 @@ public final class RedisOutputStream extends FilterOutputStream {
flushBuffer();
out.flush();
}
}
}