title: read a String from the Channelbuffer
body: <p>I am sendung a String to the server via Socket. I implemented the TCPClient class to simulate a real scenario. The message starts always with <code>#</code> and ends with <code>##</code>. Everything in between are information. I just trying to read the ASCii characters when receiving the stream inside the <code>decodeMessage()</code>. So when reading the first byte which contains <code>35</code> Ascci code, then I want to search the buffer for the end the message <code>##</code> which are 3535 in ASCCII table.</p>
  
  <p>How can I read the message from the buffer?</p>
  
  <p><strong>Client</strong></p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.DataOutputStream;
  import java.io.InputStreamReader;
  import java.io.StringReader;
  import java.net.Socket;
  
  
  public class TCPClient {
  
      public static void main(String argv[]) throws Exception {
  
          String message;
          String result;
          String aString = "#201601140000006#13534035454#1#0000#AUT#2#0000050000020027#114.034407,E,22.648272,N,,0.00,0.00#010104#004500#114.034407,E,22.648272,N,0.00,0.00#010104#004500##";
          // String aString = "###";
          BufferedReader inFromUser = new BufferedReader(new StringReader(aString));
  
          Socket clientSocket = new Socket("localhost", 39537);
          DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
          BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  
          message = inFromUser.readLine();
          outToServer.writeBytes(message + '\n');
          result = inFromServer.readLine();
          System.out.println(result);
          clientSocket.close();
      }
  }
  </code></pre>
  
  <p><strong>docodeMessage()</strong></p>
  
  <pre><code>private Object decodeMessage(final ChannelBuffer buffer) {
      // Here with my String I am getting 160 for readableBytes.
      int readableBytes = buffer.readableBytes();
      if (readableBytes &lt; 5) {
         //incase the messagejust contains ### also begining and end.
          return null;
      }
  
      if (readableBytes &gt;= 5) {
          boolean messageStart = false;
          int indexMessageBegin;
          for (int i = 0; i &lt; readableBytes; i++) {
              int readerIndex = buffer.readerIndex() + i;
              if (buffer.getByte(readerIndex) == 35) { // Message begin.
                  messageStart = true;
                  indexMessageBegin = i;
              }
              if (messageStart) {
                  if (buffer.getByte(i) == 35 &amp;&amp; buffer.getByte(i + 1) == 35) {
                      messageStart = false;
                      // when reading the message I want to cut it out from the stream
                      byte[] decoded = new byte[0x00 + i];
                  }
              }
  
          }
      }
  
      return null;
  }
  </code></pre>