Пример #1
0
 /**
  * Gets a materialized object of this option.
  *
  * @return the materialized object
  */
 public Object materializeObject() {
   if ((this.currentValue == null) || this.requiredType.isInstance(this.currentValue)) {
     return this.currentValue;
   } else if (this.currentValue instanceof File) {
     File inputFile = (File) this.currentValue;
     Object result = null;
     try {
       result = SerializeUtils.readFromFile(inputFile);
     } catch (Exception ex) {
       throw new RuntimeException(
           "Problem loading "
               + this.requiredType.getName()
               + " object from file '"
               + inputFile.getName()
               + "':\n"
               + ex.getMessage(),
           ex);
     }
     return result;
   } else {
     throw new RuntimeException(
         "Could not materialize object of required type "
             + this.requiredType.getName()
             + ", found "
             + this.currentValue.getClass().getName()
             + " instead.");
   }
 }
Пример #2
0
 @Override
 public void writeExternal(ObjectOutput out) throws IOException {
   super.writeExternal(out);
   if (data != null) {
     out.writeObject(SerializeUtils.ByteBufferToByteArray(data));
   } else {
     out.writeObject(null);
   }
 }
Пример #3
0
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   super.readExternal(in);
   byte[] byteBuf = (byte[]) in.readObject();
   if (byteBuf != null) {
     data = IoBuffer.allocate(byteBuf.length);
     data.setAutoExpand(true);
     SerializeUtils.ByteArrayToByteBuffer(byteBuf, data);
   }
 }
 /**
  * 将字符串值 value 关联到 key 。 如果 key 已经持有其他值, SET 就覆写旧值,无视类型。
  *
  * @param key
  * @param value
  * @return 总是返回 OK ,因为 SET 不可能失败。
  */
 public static String set(String key, Object object) {
   String l = null;
   Jedis jedis = null;
   try {
     jedis = jedisPool.getResource();
     jedis.set(SerializeUtils.serialize(key), SerializeUtils.serialize(object));
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (jedis != null) {
       try {
         jedisPool.returnResource(jedis);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   return l;
 }
 /**
  * 将字符串值 value 关联到 key 。
  *
  * @param key
  * @param value
  */
 public Object getObject(String key) {
   Object o = null;
   Jedis jedis = null;
   try {
     jedis = jedisPool.getResource();
     byte[] bs = jedis.get(SerializeUtils.serialize(key));
     if (bs != null) {
       o = SerializeUtils.unserialize(bs);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (jedis != null) {
       try {
         jedisPool.returnResource(jedis);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   return o;
 }
Пример #6
0
 @SuppressWarnings("unchecked")
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   super.readExternal(in);
   call = (IServiceCall) in.readObject();
   connectionParams = (Map<String, Object>) in.readObject();
   invokeId = in.readInt();
   byte[] byteBuf = (byte[]) in.readObject();
   if (byteBuf != null) {
     data = IoBuffer.allocate(0);
     data.setAutoExpand(true);
     SerializeUtils.ByteArrayToByteBuffer(byteBuf, data);
   }
 }