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


Java Coder.decode方法代码示例

本文整理汇总了Java中org.apache.beam.sdk.coders.Coder.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Coder.decode方法的具体用法?Java Coder.decode怎么用?Java Coder.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.beam.sdk.coders.Coder的用法示例。


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

示例1: decode

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
@VisibleForTesting
static <T> T decode(
    Coder<T> coder, Coder.Context context, byte[] bytes) throws CoderException, IOException {
  @SuppressWarnings("unchecked")
  Coder<T> deserializedCoder = SerializableUtils.clone(coder);

  byte[] buffer;
  if (context == Coder.Context.NESTED) {
    buffer = new byte[bytes.length + 1];
    System.arraycopy(bytes, 0, buffer, 0, bytes.length);
    buffer[bytes.length] = 1;
  } else {
    buffer = bytes;
  }

  CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(buffer));
  T value = deserializedCoder.decode(new UnownedInputStream(cis), context);
  assertThat("consumed bytes equal to encoded bytes", cis.getCount(),
      equalTo((long) bytes.length));
  return value;
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:CoderProperties.java

示例2: restoreKeyGroupState

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
/**
 * Restore the state {@code (stateName -> (valueCoder && (namespace -> value)))}
 * for a given {@code keyGroupIdx}.
 *
 * @param keyGroupIdx the id of the key-group to be put in the snapshot.
 * @param in the stream to read from.
 * @param userCodeClassLoader the class loader that will be used to deserialize
 *                            the valueCoder.
 */
public void restoreKeyGroupState(int keyGroupIdx, DataInputStream in,
                                 ClassLoader userCodeClassLoader) throws Exception {
  int localIdx = getIndexForKeyGroup(keyGroupIdx);
  Map<String, Tuple2<Coder<?>, Map<String, ?>>> stateTable = stateTables[localIdx];
  int numStates = in.readShort();
  for (int i = 0; i < numStates; ++i) {
    String stateName = in.readUTF();
    Coder coder = InstantiationUtil.deserializeObject(in, userCodeClassLoader);
    Tuple2<Coder<?>, Map<String, ?>> tuple2 = stateTable.get(stateName);
    if (tuple2 == null) {
      tuple2 = new Tuple2<>();
      tuple2.f0 = coder;
      tuple2.f1 = new HashMap<>();
      stateTable.put(stateName, tuple2);
    }
    Map<String, Object> map = (Map<String, Object>) tuple2.f1;
    int mapSize = in.readInt();
    for (int j = 0; j < mapSize; j++) {
      String namespace = StringUtf8Coder.of().decode(in);
      Object value = coder.decode(in);
      map.put(namespace, value);
    }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:34,代码来源:FlinkKeyGroupStateInternals.java

示例3: decodeFromSafeStream

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
/**
 * Decodes a value from the given {@code stream}, which should be a stream that never throws
 * {@code IOException}, such as {@code ByteArrayInputStream} or
 * {@link ExposedByteArrayInputStream}.
 */
private static <T> T decodeFromSafeStream(
    Coder<T> coder, InputStream stream, Coder.Context context) throws CoderException {
  try {
    return coder.decode(new UnownedInputStream(stream), context);
  } catch (IOException exn) {
    Throwables.propagateIfPossible(exn, CoderException.class);
    throw new IllegalArgumentException(
        "Forbidden IOException when reading from InputStream", exn);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:CoderUtils.java

示例4: readRows

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
private List<TableRow> readRows(String filename) throws IOException {
  Coder<TableRow> coder = TableRowJsonCoder.of();
  List<TableRow> tableRows = Lists.newArrayList();
  try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
    String line;
    while ((line = reader.readLine()) != null) {
      TableRow tableRow = coder.decode(
          new ByteArrayInputStream(line.getBytes(StandardCharsets.UTF_8)), Context.OUTER);
      tableRows.add(tableRow);
    }
  }
  return tableRows;
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:FakeJobService.java

示例5: fromByteArray

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
/**
 * Utility method for deserializing a byte array using the specified coder.
 *
 * @param serialized bytearray to be deserialized.
 * @param coder      Coder to deserialize with.
 * @param <T>        Type of object to be returned.
 * @return Deserialized object.
 */
public static <T> T fromByteArray(byte[] serialized, Coder<T> coder) {
  ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
  try {
    return coder.decode(bais, new Coder.Context(true));
  } catch (IOException e) {
    throw new IllegalStateException("Error decoding bytes for coder: " + coder, e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:CoderHelpers.java

示例6: decode

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
@Override
public KV<Integer, WindowedValue<?>> decode(InputStream in)
    throws IOException {
  Integer id = VarIntCoder.of().decode(in);
  Coder<WindowedValue<?>> coder = idsToCoders.get(id);
  WindowedValue<?> value = coder.decode(in);
  return KV.<Integer, WindowedValue<?>>of(id, value);
}
 
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DoFnOperator.java

示例7: decode

import org.apache.beam.sdk.coders.Coder; //导入方法依赖的package包/类
@Override
public InvoiceGroupingKey decode(InputStream inStream) throws IOException {
  Coder<String> stringCoder = StringUtf8Coder.of();
  return new AutoValue_BillingEvent_InvoiceGroupingKey(
      stringCoder.decode(inStream),
      stringCoder.decode(inStream),
      stringCoder.decode(inStream),
      stringCoder.decode(inStream),
      stringCoder.decode(inStream),
      Double.parseDouble(stringCoder.decode(inStream)),
      stringCoder.decode(inStream),
      stringCoder.decode(inStream));
}
 
开发者ID:google,项目名称:nomulus,代码行数:14,代码来源:BillingEvent.java


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