Package net.spy.memcached

Examples of net.spy.memcached.CachedData


    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());
  }
View Full Code Here


    int flags = 0;
    if (o instanceof String) {
      b = encodeString((String) o);
      flags |= SPECIAL_STRING;
      if (StringUtils.isJsonObject((String) o)) {
        return new CachedData(flags, b, getMaxSize());
      }
    } else if (o instanceof StringBuffer) {
      flags |= SPECIAL_STRINGBUFFER;
      b = encodeString(String.valueOf(o));
    } else if (o instanceof StringBuilder) {
      flags |= SPECIAL_STRINGBUILDER;
      b = encodeString(String.valueOf(o));
    } else if (o instanceof Long) {
      b = tu.encodeLong((Long) o);
      flags |= SPECIAL_LONG;
    } else if (o instanceof Integer) {
      b = tu.encodeInt((Integer) o);
      flags |= SPECIAL_INT;
    } else if (o instanceof Short) {
      b = tu.encodeInt((Short) o);
      flags |= SPECIAL_SHORT;
    } else if (o instanceof Boolean) {
      b = this.encodeBoolean((Boolean) o);
      flags |= SPECIAL_BOOLEAN;
    } else if (o instanceof Date) {
      b = tu.encodeLong(((Date) o).getTime());
      flags |= SPECIAL_DATE;
    } else if (o instanceof Byte) {
      b = tu.encodeByte((Byte) o);
      flags |= SPECIAL_BYTE;
    } else if (o instanceof Float) {
      b = tu.encodeInt(Float.floatToIntBits((Float) o));
      flags |= SPECIAL_FLOAT;
    } else if (o instanceof Double) {
      b = tu.encodeLong(Double.doubleToLongBits((Double) o));
      flags |= SPECIAL_DOUBLE;
    } else if (o instanceof byte[]) {
      b = (byte[]) o;
      flags |= SPECIAL_BYTEARRAY;
    } else if (o instanceof Character) {
      b = tu.encodeInt((Character) o);
      flags |= SPECIAL_CHARACTER;
    } else {
      b = serialize(o);
      flags |= SERIALIZED;
    }
    assert b != null;
    if (b.length > compressionThreshold) {
      byte[] compressed = compress(b);
      if (compressed.length < b.length) {
        getLogger().debug("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());
  }
View Full Code Here

      private final Transcoder<Object> transcoder = new SerializingTranscoder();

      @Override
      protected ByteBuffer objectToBuffer(Object o, int estimatedSize) {
         CachedData encoded = transcoder.encode(o);
         return new ByteBufferImpl(encoded.getData(), 0, encoded.getData().length);
      }
View Full Code Here

         return new ByteBufferImpl(encoded.getData(), 0, encoded.getData().length);
      }

      @Override
      public Object objectFromByteBuffer(byte[] buf, int offset, int length) {
         return transcoder.decode(new CachedData(0, buf, length));
      }
View Full Code Here

      private final Transcoder<Object> transcoder = new SerializingTranscoder();

      @Override
      protected ByteBuffer objectToBuffer(Object o, int estimatedSize) {
         CachedData encoded = transcoder.encode(o);
         return new ByteBufferImpl(encoded.getData(), 0, encoded.getData().length);
      }
View Full Code Here

        getLogger().info(
          "Compression increased the size of %s from %d to %d",
          o.getClass().getName(), b.length, compressed.length);
      }
    }
    return new CachedData(flags, b);
  }
View Full Code Here

  private static final int flags = SerializingTranscoder.SPECIAL_INT;

  private final TranscoderUtils tu=new TranscoderUtils(true);

  public CachedData encode(java.lang.Integer l) {
    return new CachedData(flags, tu.encodeInt(l));
  }
View Full Code Here

  private static final int flags = SerializingTranscoder.SPECIAL_LONG;

  private final TranscoderUtils tu=new TranscoderUtils(true);

  public CachedData encode(java.lang.Long l) {
    return new CachedData(flags, tu.encodeLong(l));
  }
View Full Code Here

        getLogger().info(
          "Compression increased the size of %s from %d to %d",
          o.getClass().getName(), b.length, compressed.length);
      }
    }
    return new CachedData(flags, b);
  }
View Full Code Here

        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());
  }
View Full Code Here

TOP

Related Classes of net.spy.memcached.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.