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


Java Output类代码示例

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


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

示例1: writeTo

import io.protostuff.Output; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void writeTo(Output output, T message) throws IOException {
  if (!ProtobufFeatureUtils.isUseProtobufMapCodec()) {
    runtimeMapField.writeTo(output, message);
    return;
  }

  final Map<Object, Object> existing;
  try {
    existing = (Map<Object, Object>) field.get(message);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  if (existing != null) {
    for (Entry<Object, Object> entry : existing.entrySet()) {
      output.writeObject(number, entry, entrySchema, true);
    }
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:RuntimeMapFieldProtobuf.java

示例2: writeUnmodifiableCollectionTo

import io.protostuff.Output; //导入依赖的package包/类
private static void writeUnmodifiableCollectionTo(Output output,
        Object value, Schema<?> currentSchema, IdStrategy strategy, int id)
        throws IOException
{
    final Object c;
    try
    {
        c = fUnmodifiableCollection_c.get(value);
    }
    catch (IllegalArgumentException | IllegalAccessException e)
    {
        throw new RuntimeException(e);
    }

    output.writeObject(id, c, strategy.POLYMORPHIC_COLLECTION_SCHEMA, false);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:17,代码来源:PolymorphicCollectionSchema.java

示例3: writeObjectTo

import io.protostuff.Output; //导入依赖的package包/类
static void writeObjectTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
    final Class<?> c = ((Class<?>) value);
    if (c.isArray())
    {
        int dimensions = 1;
        Class<?> componentType = c.getComponentType();
        while (componentType.isArray())
        {
            dimensions++;
            componentType = componentType.getComponentType();
        }

        strategy.writeClassIdTo(output, componentType, true);
        // write the dimensions of the array
        output.writeUInt32(ID_ARRAY_DIMENSION, dimensions, false);
        return;
    }

    strategy.writeClassIdTo(output, c, false);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:23,代码来源:ClassSchema.java

示例4: writeCollectionIdTo

import io.protostuff.Output; //导入依赖的package包/类
@Override
protected void writeCollectionIdTo(Output output, int fieldNumber,
        Class<?> clazz) throws IOException
{
    final CollectionSchema.MessageFactory factory = collectionMapping
            .get(clazz);
    if (factory == null && clazz.getName().startsWith("java.util"))
    {
        // jdk collection
        // better not to register the jdk collection if using this strategy
        // as it saves space by not writing the full package
        output.writeString(fieldNumber, clazz.getSimpleName(), false);
    }
    else
    {
        output.writeString(fieldNumber, clazz.getName(), false);
    }
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:19,代码来源:DefaultIdStrategy.java

示例5: writeObjectTo

import io.protostuff.Output; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
    final HasSchema<Object> hs = strategy.tryWritePojoIdTo(output, ID_POJO, 
            (Class<Object>)value.getClass(), true);
    
    if (hs == null)
    {
        PolymorphicCollectionSchema.writeObjectTo(output, value, currentSchema, 
                strategy);
        return;
    }
    
    final Schema<Object> schema = hs.getSchema();
    
    if (output instanceof StatefulOutput)
    {
        // update using the derived schema.
        ((StatefulOutput) output).updateLast(schema, currentSchema);
    }
    
    schema.writeTo(output, value);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:25,代码来源:PolymorphicPojoCollectionSchema.java

示例6: writeMessageIdTo

import io.protostuff.Output; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber,
        Message<T> message) throws IOException
{
    int id;
    BaseHS<T> wrapper = (BaseHS<T>) getSchemaWrapper(message.getClass(), true);

    // wait till everything is completely set
    while (0 == (id = wrapper.id))
        LockSupport.parkNanos(1);

    output.writeUInt32(fieldNumber, id, false);

    // TODO allow the wrapper to return an override schema?
    return message.cachedSchema();
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:18,代码来源:IncrementalIdStrategy.java

示例7: writeTo

import io.protostuff.Output; //导入依赖的package包/类
/**
 * Delegates to the schema derived from the {@code value}.
 */
@Override
@SuppressWarnings("unchecked")
public void writeTo(final Output output, final Object value)
        throws IOException
{
    final Schema<Object> schema = strategy.writePojoIdTo(output, ID_POJO,
            (Class<Object>) value.getClass()).getSchema();

    if (output instanceof StatefulOutput)
    {
        // update using the derived schema.
        ((StatefulOutput) output).updateLast(schema, this);
    }

    // write the rest of the fields of the exact type
    schema.writeTo(output, value);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:21,代码来源:DerivativeSchema.java

示例8: writeObjectTo

import io.protostuff.Output; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
    final Schema<Object> schema = strategy.writePojoIdTo(output,
            ID_THROWABLE, (Class<Object>) value.getClass()).getSchema();

    if (output instanceof StatefulOutput)
    {
        // update using the derived schema.
        ((StatefulOutput) output).updateLast(schema, currentSchema);
    }

    if (tryWriteWithoutCause(output, value, schema))
        return;

    schema.writeTo(output, value);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:PolymorphicThrowableSchema.java

示例9: writeUnmodifiableMapTo

import io.protostuff.Output; //导入依赖的package包/类
private static void writeUnmodifiableMapTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy, int id)
        throws IOException
{
    final Object m;
    try
    {
        m = fUnmodifiableMap_m.get(value);
    }
    catch (IllegalArgumentException | IllegalAccessException e)
    {
        throw new RuntimeException(e);
    }

    output.writeObject(id, m, strategy.POLYMORPHIC_MAP_SCHEMA, false);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:17,代码来源:PolymorphicMapSchema.java

示例10: writeObject

import io.protostuff.Output; //导入依赖的package包/类
default void writeObject(Output output, Object value, ProtobufFeature protobufFeature) throws Exception {
  ProtobufFeatureUtils.setProtobufFeature(protobufFeature);
  try {
    writeObject(output, value);
  } finally {
    ProtobufFeatureUtils.removeProtobufFeature();
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:WrapSchema.java

示例11: writeObject

import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
  if (value == null) {
    return;
  }

  schema.writeTo(output, value);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:NotWrapSchema.java

示例12: writeObject

import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
  if (value == null) {
    return;
  }

  SingleWrapper wrapper = (SingleWrapper) schema.newMessage();
  wrapper.writeField(value);

  schema.writeTo(output, wrapper);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:NormalWrapSchema.java

示例13: writeObject

import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
  Object writeValue = ((Object[]) value)[0];
  if (writeValue == null) {
    return;
  }

  schema.writeTo(output, writeValue);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:ArgsNotWrapSchema.java

示例14: writeTo

import io.protostuff.Output; //导入依赖的package包/类
@Override
public void writeTo(Output output, Message message) throws IOException {
  // Write headers
  if (!message.headers().isEmpty()) {
    for (Map.Entry<String, String> headerEntry : message.headers().entrySet()) {
      if (headerEntry.getKey() != null && headerEntry.getValue() != null) {
        output.writeString(HEADER_KEYS_FIELD_NUMBER, headerEntry.getKey(), true);
        output.writeString(HEADER_VALUES_FIELD_NUMBER, headerEntry.getValue(), true);
      }
    }
  }

  // Write data
  Object originalData = message.data();
  if (originalData != null) {
    if (originalData instanceof byte[]) {
      // Write data byte array as is
      output.writeByteArray(DATA_FIELD_NUMBER, (byte[]) originalData, false);
    } else {
      // Write data class as an additional header
      Class<?> dataClass = originalData.getClass();
      output.writeString(HEADER_KEYS_FIELD_NUMBER, Message.HEADER_DATA_TYPE, true);
      output.writeString(HEADER_VALUES_FIELD_NUMBER, dataClass.getName(), true);

      // Write data as serialized byte array
      Schema dataSchema = RuntimeSchema.getSchema(dataClass);
      try (RecyclableLinkedBuffer rlb = recyclableLinkedBuffer.get()) {
        byte[] array = ProtostuffIOUtil.toByteArray(originalData, dataSchema, rlb.buffer());
        output.writeByteArray(DATA_FIELD_NUMBER, array, false);
      }
    }
  }

  // Write sender
  Address sender = message.sender();
  if (sender != null) {
    output.writeString(SENDER_HOST_FIELD_NUMBER, sender.host(), false);
    output.writeInt32(SENDER_PORT_FIELD_NUMBER, sender.port(), false);
  }
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:41,代码来源:MessageSchema.java

示例15: writeObjectTo

import io.protostuff.Output; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
    if (Collections.class == value.getClass().getDeclaringClass())
    {
        writeNonPublicCollectionTo(output, value, currentSchema, strategy);
        return;
    }

    if (EnumSet.class.isAssignableFrom(value.getClass()))
    {
        strategy.writeEnumIdTo(output, ID_ENUM_SET,
                EnumIO.getElementTypeFromEnumSet(value));

        // TODO optimize
    }
    else
    {
        strategy.writeCollectionIdTo(output, ID_COLLECTION,
                value.getClass());
    }

    if (output instanceof StatefulOutput)
    {
        // update using the derived schema.
        ((StatefulOutput) output).updateLast(strategy.COLLECTION_SCHEMA,
                currentSchema);
    }

    strategy.COLLECTION_SCHEMA.writeTo(output, (Collection<Object>) value);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:33,代码来源:PolymorphicCollectionSchema.java


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