当前位置: 首页>>代码示例>>Java>>正文


Java Schema类代码示例

本文整理汇总了Java中io.protostuff.Schema的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Schema类属于io.protostuff包,在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import io.protostuff.Schema; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> byte[] serialize(T obj) {
    Class<T> cls = (Class<T>) obj.getClass();

    // 如果是基本类型,则转换为string
    if (isSupport(cls)) {
        return castToString(obj).getBytes();
    }

    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    try {
        Schema<T> schema = getSchema(cls);
        return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:20,代码来源:ConvertUtil.java

示例2: unSerialize

import io.protostuff.Schema; //导入依赖的package包/类
public static <T> T unSerialize(byte[] data, Class<T> cls) {
    if (data == null || data.length == 0) {
        return null;
    }

    // 如果是基本类型,则转换为string
    if (isSupport(cls)) {
        return castTo(new String(data), cls);
    }

    try {
        T message = cls.newInstance();
        Schema<T> schema = getSchema(cls);
        ProtostuffIOUtil.mergeFrom(data, message, schema);
        return message;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:20,代码来源:ConvertUtil.java

示例3: asFileConfig

import io.protostuff.Schema; //导入依赖的package包/类
@JsonIgnore
@SuppressWarnings({ "rawtypes", "unchecked" })
public FileConfig asFileConfig() {
  buffer.clear();
  FileConfig fc = new FileConfig();
  fc.setType(getFileType());
  fc.setName(name);
  fc.setOwner(owner);
  fc.setCtime(ctime);
  fc.setType(getFileType());
  fc.setVersion(getVersion());
  fc.setLocation(location);
  byte[] bytes = ProtobufIOUtil.toByteArray(this, (Schema) getPrivateSchema(), buffer);
  fc.setExtendedConfig(ByteString.copyFrom(bytes));
  fc.setFullPathList(fullPath);
  return fc;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:FileFormat.java

示例4: get

import io.protostuff.Schema; //导入依赖的package包/类
private static FileFormat get(FileConfig fileConfig) {
  // TODO (Amit H) Remove after defining classes for tsv, csv, and psv
  FileType fileType = fileConfig.getType();
  if (fileType == FileType.CSV || fileType == FileType.TSV || fileType == FileType.PSV) {
    fileType = FileType.TEXT;
  }
  final Class<? extends FileFormat> fileFormatClass = FileFormatDefinitions.CLASS_TYPES.get(fileType);
  final Schema<FileFormat> schema = (Schema<FileFormat>) FileFormatDefinitions.SCHEMAS.get(fileFormatClass);

  final FileFormat fileFormat = schema.newMessage();
  if (fileConfig.getExtendedConfig() != null) {
    ProtobufIOUtil.mergeFrom(fileConfig.getExtendedConfig().toByteArray(), fileFormat, schema);
  }

  fileFormat.setCtime(fileConfig.getCtime());
  fileFormat.setName(fileConfig.getName());
  fileFormat.setOwner(fileConfig.getOwner());
  fileFormat.setFullPath(fileConfig.getFullPathList());
  fileFormat.setVersion(fileConfig.getVersion());
  fileFormat.setLocation(fileConfig.getLocation());
  return fileFormat;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:FileFormat.java

示例5: copy

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Clone  a Protostuff object
 *
 * @param t the protobuf message to copy
 * @return a deep copy of {@code t}
 */
public static <T extends Message<T>> T copy(T t) {
  try {
    Schema<T> schema = t.cachedSchema();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GraphIOUtil.writeDelimitedTo(new DataOutputStream(out), t, schema);
    // TODO: avoid array copy
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    T newMessage = schema.newMessage();
    GraphIOUtil.mergeDelimitedFrom(in, newMessage, schema);
    return newMessage;
  } catch (IOException e) {
    throw UserException.dataReadError(e)
      .message("Failure decoding object, please ensure that you ran dremio-admin upgrade on Dremio.")
      .build(logger);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:ProtostuffUtil.java

示例6: readInternal

import io.protostuff.Schema; //导入依赖的package包/类
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {

    MediaType contentType = inputMessage.getHeaders().getContentType();
    if (MEDIA_TYPE.isCompatibleWith(contentType)) {
        final Schema<?> schema = getSchema(clazz);
        final Object value = schema.newMessage();

        try (final InputStream stream = inputMessage.getBody()) {
            ProtobufIOUtil.mergeFrom(stream, value, (Schema<Object>) schema);
            return value;
        }
    }

    throw new HttpMessageNotReadableException(
            "Unrecognized HTTP media type " + inputMessage.getHeaders().getContentType().getType() + ".");
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:18,代码来源:ProtostuffHttpMessageConverter.java

示例7: put

import io.protostuff.Schema; //导入依赖的package包/类
/**
  * Associates the specified value with the specified key in this map.
  * If the map previously contained a mapping for the key, the old
  * value is replaced.
  *
  * @param key key with which the specified value is to be associated
  * @param value value to be associated with the specified key
  * @return the previous value associated with <tt>key</tt>, or
  *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  */    
 public V put(K key, V value){
 	Object oldValue = null;
     if ((key != null) && ((oldValue = super.hashPut((key.toString()+"�Map�"+gvName), value))!=null)){        	
     		        	
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);	
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
// ################ Serialization key ########################

     	super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
     }else{
    	 System.out.println("Null key or fault in put<K,V> on cluster!");
     }
     
     return (V)oldValue;
 }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:JCLHashMapPacu.java

示例8: putUnlock

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */

public V putUnlock(K key, V value){
	V oldValue = null;
    if (key != null){        	
    	if(DEFAULT_JCL.containsGlobalVar(key.toString()+"�Map�"+gvName)){
    		oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"�Map�"+gvName).getCorrectResult();
    		DEFAULT_JCL.setValueUnlocking((key.toString()+"�Map�"+gvName), value);
    	}else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"�Map�"+gvName), value)){
			
			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(key);	
			Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
			byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################

    		super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
		}
    }else{
   	 System.out.println("Can't put<K,V> with null key!");
    }        
    return (oldValue == null ? null : oldValue);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCLHashMapPacu.java

示例9: putAll

import io.protostuff.Schema; //导入依赖的package包/类
/**
   * Copies all of the mappings from the specified map to this map.
   * These mappings will replace any mappings that this map had for
   * any of the keys currently in the specified map.
   *
   * @param m mappings to be stored in this map
   * @throws NullPointerException if the specified map is null
   */
  public void putAll(Map<? extends K, ? extends V> m) {
      int numKeysToBeAdded = m.size();
              
      if (numKeysToBeAdded == 0)
          return;
      super.instantiateBin((Object)m.entrySet(), this.gvName);
              
      List<Object> obj =  new ArrayList<Object>();
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);

      for(K key:m.keySet()){
      	
	// ################ Serialization key ########################
	buffer.clear();
      	ObjectWrap objW = new ObjectWrap(key);	
	Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
	byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
	// ################ Serialization key ########################

      	obj.add(ByteBuffer.wrap(k));
      }   
      
      super.hashAdd(gvName, obj,idLocalize);                
  }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:33,代码来源:JCLHashMapPacu.java

示例10: containsValue

import io.protostuff.Schema; //导入依赖的package包/类
/**
  * Returns <tt>true</tt> if this map maps one or more keys to the
  * specified value.
  *
  * @param value value whose presence in this map is to be tested
  * @return <tt>true</tt> if this map maps one or more keys to the
  *         specified value
  */
 public boolean containsValue(Object value) {
 	Set table = super.getHashSet(gvName,idLocalize);
 	for(Object k:table){
 		
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
ProtobufIOUtil.mergeFrom(((ByteBuffer)k).getArray(), obj, scow);    		
 		K key = (K)obj.getobj();
 		
 		Object valueGV = DEFAULT_JCL.getValue(key.toString()+"�Map�"+gvName).getCorrectResult();
 		if(value.equals(valueGV)){
 			return true;
 		}
 	}
 	return false;
 }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:25,代码来源:JCLHashMapPacu.java

示例11: nextEntry

import io.protostuff.Schema; //导入依赖的package包/类
final Entry<K,V> nextEntry() {
        	current = queue.poll();
        	
        	double pag = size/(queue.size()+size);
        	if(((pag>0.4) || (gvList.size()==1)) && (intGvList.hasNext())){
    			java.util.Map.Entry<Integer, JCL_message_generic> entHost = intGvList.next();
    			ticket.add(JCLHashMapPacu.super.getHashValues(queue, entHost.getValue(), entHost.getKey()));        	
        	}
        	
        	
        	size++;
        	        	
			Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
			ObjectWrap obj = scow.newMessage();
			ProtobufIOUtil.mergeFrom(((ByteBuffer)current.getKey()).getArray(), obj, scow);    		
    		K key = (K)obj.getobj();
 
			ProtobufIOUtil.mergeFrom((byte[])current.getValue(), obj, scow);    		
    		V value = (V)obj.getobj();
        	
        	return new implementations.util.Entry<K, V>(key,value);
//            return current;
        }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:24,代码来源:JCLHashMapPacu.java

示例12: put

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */
public V put(K key, V value){
    Object oldValue = null;
    if ((key != null) && ((oldValue = super.hashPut((key.toString()+"¬Map¬"+gvName), value))!=null)){

        // ################ Serialization key ########################
        LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
        ObjectWrap objW = new ObjectWrap(key);
        Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
        byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
        // ################ Serialization key ########################

        super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
    }else{
        System.out.println("Null key or fault in put<K,V> on cluster!");
    }

    return (V)oldValue;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:JCLHashMapPacu.java

示例13: putUnlock

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */

public V putUnlock(K key, V value){
    V oldValue = null;
    if (key != null){
        if(DEFAULT_JCL.containsGlobalVar(key.toString()+"¬Map¬"+gvName)){
            oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"¬Map¬"+gvName).getCorrectResult();
            DEFAULT_JCL.setValueUnlocking((key.toString()+"¬Map¬"+gvName), value);
        }else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"¬Map¬"+gvName), value)){

            // ################ Serialization key ########################
            LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
            ObjectWrap objW = new ObjectWrap(key);
            Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
            byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
            // ################ Serialization key ########################

            super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
        }
    }else{
        System.out.println("Can't put<K,V> with null key!");
    }
    return (oldValue == null ? null : oldValue);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCLHashMapPacu.java

示例14: putAll

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Copies all of the mappings from the specified map to this map.
 * These mappings will replace any mappings that this map had for
 * any of the keys currently in the specified map.
 *
 * @param m mappings to be stored in this map
 * @throws NullPointerException if the specified map is null
 */
public void putAll(Map<? extends K, ? extends V> m) {
    int numKeysToBeAdded = m.size();

    if (numKeysToBeAdded == 0)
        return;
    super.instantiateBin((Object)m.entrySet(), this.gvName);

    List<Object> obj =  new ArrayList<Object>();
    LinkedBuffer buffer = LinkedBuffer.allocate(1048576);

    for(K key:m.keySet()){

        // ################ Serialization key ########################
        buffer.clear();
        ObjectWrap objW = new ObjectWrap(key);
        Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
        byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
        // ################ Serialization key ########################

        obj.add(ByteBuffer.wrap(k));
    }

    super.hashAdd(gvName, obj,idLocalize);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:33,代码来源:JCLHashMapPacu.java

示例15: containsValue

import io.protostuff.Schema; //导入依赖的package包/类
/**
 * Returns <tt>true</tt> if this map maps one or more keys to the
 * specified value.
 *
 * @param value value whose presence in this map is to be tested
 * @return <tt>true</tt> if this map maps one or more keys to the
 *         specified value
 */
public boolean containsValue(Object value) {
    Set table = super.getHashSet(gvName,idLocalize);
    for(Object k:table){

        Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
        ObjectWrap obj = scow.newMessage();
        ProtobufIOUtil.mergeFrom(((ByteBuffer)k).getArray(), obj, scow);
        K key = (K)obj.getobj();

        Object valueGV = DEFAULT_JCL.getValue(key.toString()+"¬Map¬"+gvName).getCorrectResult();
        if(value.equals(valueGV)){
            return true;
        }
    }
    return false;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:25,代码来源:JCLHashMapPacu.java


注:本文中的io.protostuff.Schema类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。