public CachedData encode(Object o) {
    byte[] b = null;
    int flags = 0;
    if (o instanceof String) {
      b = encodeW1String((String) o);
      if (StringUtils.isJsonObject((String) o)) {
        return new CachedData(flags, b, getMaxSize());
      }
    } else if (o instanceof StringBuffer) {
      b = encodeStringBuffer((StringBuffer) o);
    } else if (o instanceof StringBuilder) {
      b = encodeStringbuilder((StringBuilder) o);
    } else if (o instanceof Long) {
      b = encodeLong((Long) o);
    } else if (o instanceof Integer) {
      b = encodeInteger((Integer) o);
    } else if (o instanceof Short) {
      b = encodeShort((Short) o);
    } else if (o instanceof Boolean) {
      b = encodeBoolean((Boolean) o);
    } else if (o instanceof Date) {
      b = encodeLong(((Date) o).getTime(), SPECIAL_DATE);
    } else if (o instanceof Byte) {
      b = encodeByte((Byte) o);
    } else if (o instanceof Float) {
      b = encodeFloat((Float) o);
    } else if (o instanceof Double) {
      b = encodeDouble((Double) o);
    } else if (o instanceof Character) {
      b = encodeCharacter((Character) o);
    } else {
      b = serialize(o);
      flags |= SERIALIZED;
    }
    assert b != null;
    if (b.length > compressionThreshold) {
      byte[] compressed = compress(b);
      if (compressed.length < b.length) {
        getLogger().info("Compressed %s from %d to %d", o.getClass().getName(),
            b.length, compressed.length);
        b = compressed;
        flags |= COMPRESSED;
      } else {
        getLogger().info("Compression increased the size of %s from %d to %d",
            o.getClass().getName(), b.length, compressed.length);
      }
    }
    return new CachedData(flags, b, getMaxSize());
  }
Handles old whalin (tested with v1.6) encoding: data type is in the first
byte of the value.

@author bpartensky
@since Oct 16, 2008
src/main/java/net/spy/memcached/transcoders/WhalinV1Transcoder.java