Beispiel #1
0
  private IBuffer detachBuffer() {
    IBuffer buffer = m_buffer;
    if (buffer == null) {
      buffer = m_session.createBuffer();
      buffer.reserveHead(HEAD_RESERVE_SIZE);
    } else m_buffer = null;

    return buffer;
  }
Beispiel #2
0
  IBuffer buffer() {
    IBuffer buffer = m_buffer;
    if (buffer == null) {
      buffer = m_session.createBuffer();
      buffer.reserveHead(HEAD_RESERVE_SIZE);
      m_buffer = buffer;
    }

    return buffer;
  }
Beispiel #3
0
  @Override
  public void flush() {
    final IBuffer buffer;
    synchronized (this) {
      buffer = m_buffer;
      if (buffer == null || buffer.isEmpty()) return;

      m_buffer = null;

      prependLength(buffer);
    }
    m_ss.write(m_session, buffer);
  }
Beispiel #4
0
  public void writeOut(String prompt) {
    IBuffer out;
    synchronized (this) {
      if (isClosed()) return;

      m_closed = true;

      out = detachBuffer();
      if (!out.isEmpty() && !out.endsWith(CR) && !out.endsWith(LF)) {
        out.write(CR[0]);
        out.write(LF[0]);
      }

      if (!prompt.isEmpty()) out.write(prompt, StringCodec.utf_8());

      if (!out.isEmpty()) prependLength(out);

      // EOF
      out.write((byte) 0);
      out.write(0, IntCodec.bigEndian());
    }

    m_ss.write(m_session, out);
  }
Beispiel #5
0
 private static void prependLength(IBuffer buffer) {
   int n = buffer.size();
   buffer.prepend((byte) (n & 0x7F));
   while ((n >>= 7) > 0) buffer.prepend((byte) ((n & 0x7F) | 0x80));
 }