本文整理汇总了Java中io.protostuff.Schema.newMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.newMessage方法的具体用法?Java Schema.newMessage怎么用?Java Schema.newMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.protostuff.Schema
的用法示例。
在下文中一共展示了Schema.newMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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() + ".");
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: deserializeObject
import io.protostuff.Schema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object deserializeObject(Buffer buffer) {
Input input = new ZeroCopyBufferInput(buffer, true);
byte type = buffer.readByte();
Schema<Object> schema;
if (type == CRC32_TYPE) {
long crc = buffer.readLong();
schema = (Schema<Object>) registeredCrc.get(crc).schema;
} else {
schema = (Schema<Object>) registeredSha1.get(buffer, SHA1_DIGEST_SIZE).schema;
}
int size = buffer.readInt();
Object message = schema.newMessage();
try {
buffer.limitNext(size);
schema.mergeFrom(input, message);
buffer.resetNextLimit();
} catch (Exception e) {
throw new RuntimeException(e);
}
return message;
}
示例9: decodeAndCheckCrc
import io.protostuff.Schema; //导入方法依赖的package包/类
/**
* Decode a message from the passed input stream, and compute and verify its CRC. This method reads
* data written by the method {@link EntryEncodingUtil#encodeWithLengthAndCrc}.
*
* @param inputStream Input stream, opened for reading and positioned just before the length-prepended header
* @return The deserialized, constructed, validated message
* @throws IOException if a problem is encountered while reading or parsing
* @throws EntryEncodingUtil.CrcError if the recorded CRC of the message does not match its computed CRC.
*/
public static <T> T decodeAndCheckCrc(InputStream inputStream, Schema<T> schema)
throws IOException, CrcError {
// TODO this should check the length first and compare it with a passed-in maximum length
final T message = schema.newMessage();
final CrcInputStream crcStream = new CrcInputStream(inputStream, new Adler32());
ProtobufIOUtil.mergeDelimitedFrom(crcStream, message, schema);
final long computedCrc = crcStream.getValue();
final long diskCrc = readCrc(inputStream);
if (diskCrc != computedCrc) {
throw new CrcError("CRC mismatch on deserialized message " + message.toString());
}
return message;
}
示例10: verifyObjectListField
import io.protostuff.Schema; //导入方法依赖的package包/类
private void verifyObjectListField() throws IOException
{
ObjectWrapper wrapper = new ObjectWrapper();
wrapper.obj = new PersistentObjectList<Object>(15);
Schema<ObjectWrapper> schema = RuntimeSchema.getSchema(ObjectWrapper.class);
byte[] data = toByteArray(wrapper, schema);
ObjectWrapper parsed = schema.newMessage();
mergeFrom(data, 0, data.length, parsed, schema);
assertNotNull(parsed.obj);
assertTrue(parsed.obj instanceof PersistentObjectList);
@SuppressWarnings("unchecked")
PersistentObjectList<Object> list = (PersistentObjectList<Object>)parsed.obj;
assertEquals(15, list.id);
}
示例11: verifyListField
import io.protostuff.Schema; //导入方法依赖的package包/类
private void verifyListField() throws IOException
{
ListWrapper wrapper = new ListWrapper();
wrapper.obj = new PersistentObjectList<Object>(15);
Schema<ListWrapper> schema = RuntimeSchema.getSchema(ListWrapper.class);
byte[] data = toByteArray(wrapper, schema);
ListWrapper parsed = schema.newMessage();
mergeFrom(data, 0, data.length, parsed, schema);
assertNotNull(parsed.obj);
assertTrue(parsed.obj instanceof PersistentObjectList);
@SuppressWarnings("unchecked")
PersistentObjectList<Object> list = (PersistentObjectList<Object>)parsed.obj;
assertEquals(15, list.id);
}
示例12: fromSource
import io.protostuff.Schema; //导入方法依赖的package包/类
private static <S extends Source> S fromSource(Schema<S> schema, ByteString config) {
final S source = schema.newMessage();
if (config != null) {
ProtobufIOUtil.mergeFrom(config.toByteArray(), source, schema);
}
return source;
}
示例13: deserialize
import io.protostuff.Schema; //导入方法依赖的package包/类
@Override
public <T> T deserialize(InputStream inputStream, Class<T> objectClass) throws IOException {
Schema<T> schema = RuntimeSchema.getSchema(objectClass);
T result = schema.newMessage();
ProtostuffIOUtil.mergeFrom(inputStream, result, schema, LinkedBuffer.allocate());
return objectClass.cast(result);
}
示例14: deserialize
import io.protostuff.Schema; //导入方法依赖的package包/类
@Override
public <T> T deserialize(byte[] data, Class<T> clazz) throws Exception {
Schema<T> schema = SchemaCache.getOrCreate(clazz);
T message = schema.newMessage();
ByteBuf bb = Unpooled.copiedBuffer(data, 0, data.length);
ProtostuffIOUtil.mergeFrom(new ByteBufInputStream(bb), message, schema);
return message;
}
示例15: keySet
import io.protostuff.Schema; //导入方法依赖的package包/类
/**
* Returns a {@link Set} view of the keys contained in this map.
* The set is backed by the map, so changes to the map are
* reflected in the set, and vice-versa. If the map is modified
* while an iteration over the set is in progress (except through
* the iterator's own <tt>remove</tt> operation), the results of
* the iteration are undefined. The set supports element removal,
* which removes the corresponding mapping from the map, via the
* <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
* <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
* operations. It does not support the <tt>add</tt> or <tt>addAll</tt>
* operations.
*/
public Set<K> keySet(){
Set ks = super.getHashSet(gvName,idLocalize);
Set<K> retSet = new HashSet<K>();
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
for(Object key:ks){
ProtobufIOUtil.mergeFrom(((ByteBuffer)key).getArray(), obj, scow);
retSet.add((K)obj.getobj());
}
return retSet;
}