Example #1
0
 /**
  * Write list.
  *
  * @param <T> the generic type
  * @param dataOutput the data output
  * @param list the list
  * @throws IOException Signals that an I/O exception has occurred.
  */
 public static <T extends Writable> void writeList(DataOutput dataOutput, List<T> list)
     throws IOException {
   dataOutput.writeInt(list.size());
   for (T t : list) {
     t.write(dataOutput);
   }
 }
 @Override
 public void write(T record) {
   try {
     record.write(parquetWriteProtocol);
   } catch (TException e) {
     throw new ParquetEncodingException(e);
   }
 }
Example #3
0
  @Override
  void write(NBTOutputStream dos) throws IOException {
    if (list.size() > 0) type = list.get(0).getId();
    else type = 1;

    dos.writeByte(type);
    dos.writeInt(list.size());
    for (T aList : list) aList.write(dos);
  }
Example #4
0
 @Override
 public void write(LoggerEvent event, boolean endOfBatch) {
   byte[] bytes = event.toByteArray();
   if (bytes.length > 0) {
     handler.write(bytes);
     if (this.immediateFlush || endOfBatch) {
       handler.flush();
     }
   }
 }
  private static <T extends Writable> void testWritable(T expected, T actual) throws Exception {
    final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    expected.write(new DataOutputStream(bytesOut));

    final byte[] bytes = bytesOut.toByteArray();

    final ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
    actual.readFields(new DataInputStream(bytesIn));

    assertEquals(expected, actual);
  }
  public static <T extends TBase> void testDeserialization(
      TProtocolFactory factory, T object, Class<T> klass) throws Exception {
    TMemoryBuffer buf = new TMemoryBuffer(0);
    object.write(factory.getProtocol(buf));
    byte[] serialized = new byte[100 * 1024];
    buf.read(serialized, 0, 100 * 1024);

    long startTime = System.currentTimeMillis();
    for (int i = 0; i < HOW_MANY; i++) {
      T o2 = klass.newInstance();
      o2.read(factory.getProtocol(new TMemoryInputTransport(serialized)));
    }
    long endTime = System.currentTimeMillis();

    System.out.println("Deserialization test time: " + (endTime - startTime) + " ms");
  }
  @Override
  public SerializationResult addRecord(T record) throws IOException {
    if (CHECKED) {
      if (this.dataBuffer.hasRemaining()) {
        throw new IllegalStateException("Pending serialization of previous record.");
      }
    }

    this.serializationBuffer.clear();
    this.lengthBuffer.clear();

    // write data and length
    record.write(this.serializationBuffer);

    this.lengthBuffer.putInt(0, this.serializationBuffer.length());

    this.dataBuffer = this.serializationBuffer.wrapAsByteBuffer();

    // Copy from intermediate buffers to current target memory segment
    copyToTargetBufferFrom(this.lengthBuffer);
    copyToTargetBufferFrom(this.dataBuffer);

    return getSerializationResult();
  }
 @Override
 public void encode(T value, OutputStream outStream, Context context) throws IOException {
   value.write(new DataOutputStream(outStream));
 }