Package net.rubyeye.xmemcached.transcoders

Examples of net.rubyeye.xmemcached.transcoders.CachedData


  @Override
  @SuppressWarnings("unchecked")
  protected CachedData encodeValue() {

    final CachedData value = this.transcoder.encode(this.value);
    // If disable save primitive type as string,prepend 4 bytes flag to
    // value
    if (!this.transcoder.isPrimitiveAsString()) {
      int flags = value.getFlag();
      byte[] flagBytes = KestrelGetCommand.transcoderUtils
          .encodeInt(flags);
      byte[] origData = value.getData();
      byte[] newData = new byte[origData.length + 4];
      System.arraycopy(flagBytes, 0, newData, 0, 4);
      System.arraycopy(origData, 0, newData, 4, origData.length);
      value.setCapacity(newData.length);
      value.setData(newData);
    }
    return value;
  }
View Full Code Here


  public void testToString() throws Exception {
    String exp="{CachedData flags=13 data=[84, 104, 105, 115, 32, 105, "
      + "115, 32, 97, 32, 115, 105, 109, 112, 108, 101, 32, 116, 101, "
      + "115, 116, 32, 115, 116, 114, 105, 110, 103, 46]}";
    CachedData cd=new CachedData(13,
      "This is a simple test string.".getBytes("UTF-8"),
      CachedData.MAX_SIZE,-1);
    assertEquals(exp, String.valueOf(cd));
  }
View Full Code Here

  public void testInt() throws Exception {
    assertEquals(923, tc.decode(tc.encode(923)).intValue());
  }

  public void testBadFlags() throws Exception {
    CachedData cd=tc.encode(9284);
    assertNull(tc.decode(new CachedData(cd.getFlag()+1, cd.getData(),
        CachedData.MAX_SIZE,-1)));
  }
View Full Code Here

  public void testSomethingBigger() throws Exception {
    Collection<Date> dates=new ArrayList<Date>();
    for(int i=0; i<1024; i++) {
      dates.add(new Date());
    }
    CachedData d=this.tc.encode(dates);
    assertEquals(dates, this.tc.decode(d));
  }
View Full Code Here

    assertEquals(dates, this.tc.decode(d));
  }

  public void testDate() throws Exception {
    Date d=new Date();
    CachedData cd=this.tc.encode(d);
    assertEquals(d, this.tc.decode(cd));
  }
View Full Code Here

    assertDouble(Double.POSITIVE_INFINITY);
    assertDouble(Double.NEGATIVE_INFINITY);
  }

  private void assertLong(long l) {
    CachedData encoded=this.tc.encode(l);
    long decoded=(Long)this.tc.decode(encoded);
    assertEquals(l, decoded);
  }
View Full Code Here

    assertLong(-23835);
    assertLong(Long.MAX_VALUE);
  }

  private void assertInt(int i) {
    CachedData encoded=this.tc.encode(i);
    int decoded=(Integer)this.tc.decode(encoded);
    assertEquals(i, decoded);
  }
View Full Code Here

    assertFalse((Boolean)this.tc.decode(this.tc.encode(false)));
  }

  public void testByteArray() throws Exception {
    byte[] a={'a', 'b', 'c'};
    CachedData cd=this.tc.encode(a);
    assertTrue(Arrays.equals(a, cd.getData()));
    assertTrue(Arrays.equals(a, (byte[])this.tc.decode(cd)));
  }
View Full Code Here

    assertTrue(Arrays.equals(a, (byte[])this.tc.decode(cd)));
  }

  public void testStrings() throws Exception {
    String s1="This is a simple test string.";
    CachedData cd=this.tc.encode(s1);
    assertEquals(getStringFlags(), cd.getFlag());
    assertEquals(s1, this.tc.decode(cd));
  }
View Full Code Here

  public void testUTF8String() throws Exception {
    String s1="\u2013\u00f3\u2013\u00a5\u2014\u00c4\u2013\u221e\u2013"
      + "\u2264\u2014\u00c5\u2014\u00c7\u2013\u2264\u2014\u00c9\u2013"
      + "\u03c0, \u2013\u00ba\u2013\u220f\u2014\u00c4.";
    CachedData cd=this.tc.encode(s1);
    assertEquals(getStringFlags(), cd.getFlag());
    assertEquals(s1, this.tc.decode(cd));
  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.transcoders.CachedData

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.