public void writeIntCrLf(int value) throws IOException { if (value < 0) { write((byte) '-'); value = -value; flushBuffer(); writeCrLf();
private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) { try { os.write(ASTERISK_BYTE); os.writeIntCrLf(args.length + 1); os.write(DOLLAR_BYTE); os.writeIntCrLf(command.length); os.write(command); os.writeCrLf(); for (final byte[] arg : args) { os.write(DOLLAR_BYTE); os.writeIntCrLf(arg.length); os.write(arg); os.writeCrLf(); } } catch (IOException e) { throw new JedisConnectionException(e); } }
public void writeAsciiCrLf(final String in) throws IOException { final int size = in.length(); for (int i = 0; i != size; ++i) { if (count == buf.length) { flushBuffer(); } buf[count++] = (byte) in.charAt(i); } writeCrLf(); }
if (!(c < 0x80)) break; if (count == buf.length) { flushBuffer(); if (c < 0x80) { if (count == buf.length) { flushBuffer(); flushBuffer(); } else if (isSurrogate(c)) { if (4 >= buf.length - count) { flushBuffer(); } else { if (3 >= buf.length - count) { flushBuffer(); writeCrLf();
public void writeCrLf() throws IOException { if (2 >= buf.length - count) { flushBuffer(); } buf[count++] = '\r'; buf[count++] = '\n'; }
protected void flush() { try { outputStream.flush(); } catch (IOException ex) { broken = true; throw new JedisConnectionException(ex); } }
public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
public static int utf8Length(final String str) { int strLen = str.length(), utfLen = 0; for (int i = 0; i != strLen; ++i) { char c = str.charAt(i); if (c < 0x80) { utfLen++; } else if (c < 0x800) { utfLen += 2; } else if (isSurrogate(c)) { i++; utfLen += 4; } else { utfLen += 3; } } return utfLen; }
public void connect() { if (!isConnected()) { try { socket = new Socket(); // ->@wjw_add socket.setReuseAddress(true); socket.setKeepAlive(true); // Will monitor the TCP connection is // valid socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to // ensure timely delivery of data socket.setSoLinger(true, 0); // Control calls close () method, // the underlying socket is closed // immediately // <-@wjw_add socket.connect(new InetSocketAddress(host, port), connectionTimeout); socket.setSoTimeout(soTimeout); outputStream = new RedisOutputStream(socket.getOutputStream()); inputStream = new RedisInputStream(socket.getInputStream()); } catch (IOException ex) { UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis()); broken = true; throw new JedisConnectionException(ex); } } }
public void write(final byte b) throws IOException { if (count == buf.length) { flushBuffer(); } buf[count++] = b; }
public void disconnect() { if (isConnected()) { try { outputStream.flush(); socket.close(); } catch (IOException ex) { UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis()); broken = true; throw new JedisConnectionException(ex); } finally { IOUtils.closeQuietly(socket); } } }
public void write(final byte b[], final int off, final int len) throws IOException { if (len >= buf.length) { flushBuffer(); out.write(b, off, len); } else { if (len >= buf.length - count) { flushBuffer(); } System.arraycopy(b, off, buf, count, len); count += len; } }
public void flush() throws IOException { flushBuffer(); out.flush(); } }