org.apache.avro.io.Encoder.writeArrayStart()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.apache.avro.io.Encoder.writeArrayStart()方法的一些代码示例,展示了Encoder.writeArrayStart()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Encoder.writeArrayStart()方法的具体详情如下:
包路径:org.apache.avro.io.Encoder
类名称:Encoder
方法名:writeArrayStart

Encoder.writeArrayStart介绍

[英]Call this method to start writing an array. When starting to serialize an array, call #writeArrayStart. Then, before writing any data for any item call #setItemCount followed by a sequence of #startItem() and the item itself. The number of #startItem() should match the number specified in #setItemCount. When actually writing the data of the item, you can call any Encoder method (e.g., #writeLong). When all items of the array have been written, call #writeArrayEnd. As an example, let's say you want to write an array of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:

out.writeArrayStart(); 
out.setItemCount(list.size()); 
for (Record r : list) { 
out.startItem(); 
out.writeLong(r.longField); 
out.writeBoolean(r.boolField); 
} 
out.writeArrayEnd();

[中]调用此方法以开始写入数组。开始序列化数组时,请调用#writeArrayStart。然后,在为任何项调用写入任何数据之前#setItemCount后跟#startItem()序列和项本身。#startItem()的数目应与#setItemCount中指定的数目匹配。在实际写入项的数据时,可以调用任何编码器方法(例如#writeLong)。写入数组的所有项后,调用#writearlayend。例如,假设您要编写一个记录数组,该记录由一个长字段和一个布尔字段组成。您的代码如下所示:

out.writeArrayStart(); 
out.setItemCount(list.size()); 
for (Record r : list) { 
out.startItem(); 
out.writeLong(r.longField); 
out.writeBoolean(r.boolField); 
} 
out.writeArrayEnd();

代码示例

代码示例来源:origin: apache/avro

@Override
public void writeArrayStart() throws IOException {
 e.writeArrayStart();
 sizeWrittenSignal.countDown();
 try {
  eltAddedSignal.await();
 } catch (InterruptedException e) {
  // ignore
 }
}

代码示例来源:origin: apache/avro

@Override
public void writeArrayStart() throws IOException {
 push();
 parser.advance(Symbol.ARRAY_START);
 out.writeArrayStart();
}

代码示例来源:origin: org.apache.avro/avro

@Override
public void writeArrayStart() throws IOException {
 push();
 parser.advance(Symbol.ARRAY_START);
 out.writeArrayStart();
}

代码示例来源:origin: apache/avro

/** Called to write a array.  May be overridden for alternate array
 * representations.*/
protected void writeArray(Schema schema, Object datum, Encoder out)
 throws IOException {
 Schema element = schema.getElementType();
 long size = getArraySize(datum);
 long actualSize = 0;
 out.writeArrayStart();
 out.setItemCount(size);
 for (Iterator<? extends Object> it = getArrayElements(datum); it.hasNext();) {
  out.startItem();
  write(element, it.next(), out);
  actualSize++;
 }
 out.writeArrayEnd();
 if (actualSize != size) {
  throw new ConcurrentModificationException("Size of array written was " +
    size + ", but number of elements written was " + actualSize + ". ");
 }
}

代码示例来源:origin: org.apache.avro/avro

/** Called to write a array.  May be overridden for alternate array
 * representations.*/
protected void writeArray(Schema schema, Object datum, Encoder out)
 throws IOException {
 Schema element = schema.getElementType();
 long size = getArraySize(datum);
 long actualSize = 0;
 out.writeArrayStart();
 out.setItemCount(size);
 for (Iterator<? extends Object> it = getArrayElements(datum); it.hasNext();) {
  out.startItem();
  write(element, it.next(), out);
  actualSize++;
 }
 out.writeArrayEnd();
 if (actualSize != size) {
  throw new ConcurrentModificationException("Size of array written was " +
    size + ", but number of elements written was " + actualSize + ". ");
 }
}

代码示例来源:origin: apache/avro

if (elementClass.isPrimitive()) {
 Schema.Type type = element.getType();
 out.writeArrayStart();
 switch(type) {
 case BOOLEAN:
 out.writeArrayStart();
 writeObjectArray(element, (Object[]) datum, out);
 out.writeArrayEnd();

代码示例来源:origin: org.apache.avro/avro

if (elementClass.isPrimitive()) {
 Schema.Type type = element.getType();
 out.writeArrayStart();
 switch(type) {
 case BOOLEAN:
 out.writeArrayStart();
 writeObjectArray(element, (Object[]) datum, out);
 out.writeArrayEnd();

代码示例来源:origin: apache/avro

@Override protected void customEncode(org.apache.avro.io.Encoder out)
 throws java.io.IOException
{
 long size0 = this.productsInCart.size();
 out.writeArrayStart();
 out.setItemCount(size0);
 long actualSize0 = 0;
 for (java.lang.String e0: this.productsInCart) {
  actualSize0++;
  out.startItem();
  out.writeString(e0);
 }
 out.writeArrayEnd();
 if (actualSize0 != size0)
  throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
}

代码示例来源:origin: apache/avro

@Override protected void customEncode(org.apache.avro.io.Encoder out)
 throws java.io.IOException
{
 out.writeString(this.label);
 long size0 = this.children.size();
 out.writeArrayStart();
 out.setItemCount(size0);
 long actualSize0 = 0;
 for (org.apache.avro.Node e0: this.children) {
  actualSize0++;
  out.startItem();
  e0.customEncode(out);
 }
 out.writeArrayEnd();
 if (actualSize0 != size0)
  throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
}

代码示例来源:origin: apache/avro

@Override protected void customEncode(org.apache.avro.io.Encoder out)
 throws java.io.IOException
{
 out.writeString(this.label);
 long size0 = this.children.size();
 out.writeArrayStart();
 out.setItemCount(size0);
 long actualSize0 = 0;
 for (org.apache.avro.Node e0: this.children) {
  actualSize0++;
  out.startItem();
  e0.customEncode(out);
 }
 out.writeArrayEnd();
 if (actualSize0 != size0)
  throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
}

代码示例来源:origin: apache/avro

@Override protected void customEncode(org.apache.avro.io.Encoder out)
 throws java.io.IOException
{
 out.writeEnum(this.method.ordinal());
 out.writeString(this.path);
 long size0 = this.parameters.size();
 out.writeArrayStart();
 out.setItemCount(size0);
 long actualSize0 = 0;
 for (org.apache.avro.test.http.QueryParameter e0: this.parameters) {
  actualSize0++;
  out.startItem();
  e0.customEncode(out);
 }
 out.writeArrayEnd();
 if (actualSize0 != size0)
  throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
}

代码示例来源:origin: apache/avro

@Override
 void writeInternal(Encoder e) throws IOException {
  int items = sourceData.length/4;
  e.writeArrayStart();
  e.setItemCount(1);
  e.startItem();
  e.writeArrayStart();
  e.setItemCount(items);
  for (int i = 0; i < sourceData.length;i+=4) {
   e.startItem();
   e.writeFloat(sourceData[i]);
   e.writeFloat(sourceData[i+1]);
   e.writeFloat(sourceData[i+2]);
   e.writeFloat(sourceData[i+3]);
  }
  e.writeArrayEnd();
  e.writeArrayEnd();
 }
}

代码示例来源:origin: apache/avro

out.writeArrayStart();
out.setItemCount(size0);
long actualSize0 = 0;
out.writeArrayStart();
out.setItemCount(size1);
long actualSize1 = 0;

代码示例来源:origin: apache/avro

case START_ARRAY:
 out.writeIndex(JsonType.ARRAY.ordinal());
 out.writeArrayStart();
 out.setItemCount(node.size());
 for (JsonNode element : node) {

代码示例来源:origin: apache/avro

out.writeArrayStart();
out.setItemCount(size0);
long actualSize0 = 0;
out.writeArrayStart();
out.setItemCount(size1);
long actualSize1 = 0;

代码示例来源:origin: apache/avro

out.writeArrayStart();
out.setItemCount(size0);
long actualSize0 = 0;
out.writeArrayStart();
out.setItemCount(size1);
long actualSize1 = 0;

代码示例来源:origin: apache/avro

counts[stackTop]++;
cos.writeArrayStart();
isArray[++stackTop] = true;
counts[stackTop] = 0;

代码示例来源:origin: org.apache.avro/avro

case START_ARRAY:
 out.writeIndex(JsonType.ARRAY.ordinal());
 out.writeArrayStart();
 out.setItemCount(node.size());
 for (JsonNode element : node) {

代码示例来源:origin: apache/avro

out.writeIndex(1);
long size1 = this.nullableArray.size();
out.writeArrayStart();
out.setItemCount(size1);
long actualSize1 = 0;

代码示例来源:origin: apache/avro

static void generateComplexData(Encoder e) throws IOException {
 e.writeArrayStart();
 e.setItemCount(1);
 e.startItem();
 e.writeInt(1);
 e.writeArrayEnd();
 e.writeMapStart();
 e.setItemCount(2);
 e.startItem();
 e.writeString("foo");
 e.writeInt(-1);
 e.writeDouble(33.3);
 e.startItem();
 e.writeString("bar");
 e.writeInt(1);
 e.writeDouble(-33.3);
 e.writeMapEnd();
 e.flush();
}

相关文章