Package com.google.code.yanf4j.util

Examples of com.google.code.yanf4j.util.ByteBufferMatcher


import com.google.code.yanf4j.util.ShiftOrByteBufferMatcher;

public abstract class ByteBufferMatcherTest extends TestCase {
  public void testMatchFirst() {
    String hello = "hel;lo";
    ByteBufferMatcher m = createByteBufferMatcher(hello);
    assertEquals(0, m.matchFirst(IoBuffer.wrap("hel;lo".getBytes())));
    assertEquals(-1, m.matchFirst(IoBuffer.wrap("hel;l0".getBytes())));
    assertEquals(6, m
        .matchFirst(IoBuffer.wrap("hello hel;lo".getBytes())));
    assertEquals(0, (m.matchFirst(IoBuffer
        .wrap("hel;lo good ".getBytes()))));
    assertEquals(7, m.matchFirst(IoBuffer.wrap("abcdefghel;lo good "
        .getBytes())));
    assertEquals(-1, m.matchFirst(IoBuffer.wrap("".getBytes())));

    assertEquals(6, m.matchFirst(IoBuffer.wrap(
        "hello hel;lo".getBytes()).position(4)));
    assertEquals(6, m.matchFirst(IoBuffer.wrap(
        "hello hel;lo".getBytes()).position(6)));
    assertEquals(-1, m.matchFirst(IoBuffer.wrap(
        "hello hel;lo".getBytes()).limit(6)));

    assertEquals(-1, m.matchFirst(null));
    assertEquals(-1, m.matchFirst(IoBuffer.allocate(0)));


    ByteBufferMatcher newline = new ShiftAndByteBufferMatcher(IoBuffer
        .wrap("\r\n".getBytes()));

    String memcachedGet = "VALUE test 0 0 100\r\nhello\r\n";
    assertEquals(memcachedGet.indexOf("\r\n"), newline
        .matchFirst(IoBuffer.wrap(memcachedGet.getBytes())));
    assertEquals(25, newline.matchFirst(IoBuffer.wrap(
        memcachedGet.getBytes()).position(20)));
  }
View Full Code Here


  public abstract ByteBufferMatcher createByteBufferMatcher(String hello);

  public void testMatchAll() {
    String memcachedGet = "VALUE test 0 0 100\r\nhello\r\n\rtestgood\r\nh\rfasdfasd\n\rdfasdfad\r\n\r\n";
    ByteBufferMatcher newline = new ShiftOrByteBufferMatcher(IoBuffer
        .wrap("\r\n".getBytes()));
    List<Integer> list = newline.matchAll(IoBuffer.wrap(memcachedGet
        .getBytes()));
    for (int i : list) {
      System.out.println(i);
    }
View Full Code Here

import com.google.code.yanf4j.util.ShiftOrByteBufferMatcher;

public class ShiftOrByteBufferMatcherTest  extends ByteBufferMatcherTest {
  @Override
  public ByteBufferMatcher createByteBufferMatcher(String hello) {
    ByteBufferMatcher m = new ShiftOrByteBufferMatcher(IoBuffer.wrap(hello
        .getBytes()));
    return m;
  }
View Full Code Here

import com.google.code.yanf4j.util.ShiftAndByteBufferMatcher;

public class ShiftAndByteBufferMatcherTest  extends ByteBufferMatcherTest {
  @Override
  public ByteBufferMatcher createByteBufferMatcher(String hello) {
    ByteBufferMatcher m = new ShiftAndByteBufferMatcher(IoBuffer.wrap(hello
        .getBytes()));
    return m;
  }
View Full Code Here

TOP

Related Classes of com.google.code.yanf4j.util.ByteBufferMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.