Java Code Examples for com.esotericsoftware.kryo.io.Output#writeBytes()

The following examples show how to use com.esotericsoftware.kryo.io.Output#writeBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameSerializer.java    From StormCV with Apache License 2.0 6 votes vote down vote up
@Override
protected void writeObject(Kryo kryo, Output output, Frame frame) throws IOException{
	output.writeLong(frame.getTimestamp());
	output.writeString(frame.getImageType());
	byte[] buffer = frame.getImageBytes();
	if(buffer != null){
		output.writeInt(buffer.length);
		output.writeBytes(buffer);
	}else{
		output.writeInt(0);
	}
	output.writeFloat((float)frame.getBoundingBox().getX());
	output.writeFloat((float)frame.getBoundingBox().getY());
	output.writeFloat((float)frame.getBoundingBox().getWidth());
	output.writeFloat((float)frame.getBoundingBox().getHeight());
	
	kryo.writeObject(output, frame.getFeatures());
}
 
Example 2
Source File: HBaseElementSerializer.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
public void write(Kryo kryo, Output output, E element) {
    byte[] idBytes = ValueUtils.serialize(element.id());
    output.writeInt(idBytes.length);
    output.writeBytes(idBytes);
    output.writeString(element.label());
    output.writeLong(element.createdAt());
    output.writeLong(element.updatedAt());
    Map<String, Object> properties = element.getProperties();
    output.writeInt(properties.size());
    properties.forEach((key, value) -> {
        output.writeString(key);
        byte[] bytes = ValueUtils.serialize(value);
        output.writeInt(bytes.length);
        output.writeBytes(bytes);
    });
}
 
Example 3
Source File: OnlineStatisticsProvider.java    From metron with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Kryo kryo, Output output) {
  //storing tdigest
  ByteBuffer outBuffer = ByteBuffer.allocate(digest.byteSize());
  digest.asBytes(outBuffer);
  byte[] tdigestSerialized = outBuffer.array();
  output.writeInt(tdigestSerialized.length);
  output.writeBytes(tdigestSerialized);
  output.writeLong(n);
  output.writeDouble(sum);
  output.writeDouble(sumOfSquares);
  output.writeDouble(sumOfLogs);
  output.writeDouble(getMin());
  output.writeDouble(getMax());
  output.writeDouble(M1);
  output.writeDouble(M2);
  output.writeDouble(M3);
  output.writeDouble(M4);
}
 
Example 4
Source File: Ip6AddressSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Ip6Address object) {
    byte[] octs = object.toOctets();
    // It is always Ip6Address.BYTE_LENGTH
    output.writeInt(octs.length);
    output.writeBytes(octs);
}
 
Example 5
Source File: BitSetSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, BitSet bitSet) {
    final int len = bitSet.length();

    output.writeInt(len, true);

    byte[] bytes = bitSet.toByteArray();
    output.writeInt(bytes.length, true);
    output.writeBytes(bitSet.toByteArray());
}
 
Example 6
Source File: AlignedAssemblyOrExcuse.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void writeContig( final Contig contig, final Output output ) {
    output.writeInt(contig.getSequence().length);
    output.writeBytes(contig.getSequence());
    final boolean hasCoverage = contig.getPerBaseCoverage() != null;
    output.writeBoolean(hasCoverage);
    if ( hasCoverage ) output.writeBytes(contig.getPerBaseCoverage());
    output.writeInt(contig.getNSupportingReads());
}
 
Example 7
Source File: Ip4PrefixSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output,
        Ip4Prefix object) {
    byte[] octs = object.address().toOctets();
    // It is always Ip4Address.BYTE_LENGTH
    output.writeInt(octs.length);
    output.writeBytes(octs);
    output.writeInt(object.prefixLength());
}
 
Example 8
Source File: RyaStatementSerializer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Uses Kryo to write RyaStatement to {@lin Output}
 * @param kryo - writes statement to output
 * @param output - output stream that statement is written to
 * @param object - statement written to output
 */
public static void writeToKryo(Kryo kryo, Output output, RyaStatement object) {
    Preconditions.checkNotNull(kryo);
    Preconditions.checkNotNull(output);
    Preconditions.checkNotNull(object);
    output.writeString(object.getSubject().getData());
    output.writeString(object.getPredicate().getData());
    output.writeString(object.getObject().getDataType().toString());
    output.writeString(object.getObject().getData());
    boolean hasContext = object.getContext() != null;
    output.writeBoolean(hasContext);
    if(hasContext){
        output.writeString(object.getContext().getData());
    }
    boolean shouldWrite = object.getColumnVisibility() != null;
    output.writeBoolean(shouldWrite);
    if(shouldWrite){
        output.writeInt(object.getColumnVisibility().length);
        output.writeBytes(object.getColumnVisibility());
    }
    shouldWrite = object.getQualifer() != null;
    output.writeBoolean(shouldWrite);
    if(shouldWrite){
        output.writeString(object.getQualifer());
    }
    shouldWrite = object.getTimestamp() != null;
    output.writeBoolean(shouldWrite);
    if(shouldWrite){
        output.writeLong(object.getTimestamp());
    }
    shouldWrite = object.getValue() != null;
    output.writeBoolean(shouldWrite);
    if(shouldWrite){
        output.writeBytes(object.getValue());
    }
}
 
Example 9
Source File: SerializableSerializer.java    From samoa with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Object object) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(object);
        oos.flush();
    } catch(IOException e) {
        throw new RuntimeException(e);
    }
    byte[] ser = bos.toByteArray();
    output.writeInt(ser.length);
    output.writeBytes(ser);
}
 
Example 10
Source File: ClusterSerializableSerializer.java    From atomix-vertx with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, T object) {
  Buffer buffer = Buffer.buffer();
  object.writeToBuffer(buffer);
  byte[] bytes = buffer.getBytes();
  output.writeVarInt(bytes.length, true);
  output.writeBytes(bytes);
}
 
Example 11
Source File: SerializableSerializer.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Object object) {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try {
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(object);
    oos.flush();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  byte[] ser = bos.toByteArray();
  output.writeInt(ser.length);
  output.writeBytes(ser);
}
 
Example 12
Source File: SerializableSerializer.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Object object) {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try {
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(object);
    oos.flush();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  byte[] ser = bos.toByteArray();
  output.writeInt(ser.length);
  output.writeBytes(ser);
}
 
Example 13
Source File: SerializableSerializer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Object object) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(object);
        oos.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    byte[] ser = bos.toByteArray();
    output.writeInt(ser.length);
    output.writeBytes(ser);
}
 
Example 14
Source File: NiciraNatSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, NiciraNat object) {
    output.writeInt(object.niciraNatFlags());
    output.writeInt(object.niciraNatPresentFlags());
    output.writeInt(object.niciraNatPortMin());
    output.writeInt(object.niciraNatPortMax());

    output.writeBytes(object.niciraNatIpAddressMin().toOctets());
    output.writeBytes(object.niciraNatIpAddressMax().toOctets());
}
 
Example 15
Source File: ResultCountingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output) {
    output.writeLong(count);
    byte[] expression = visibility.getExpression();
    output.writeInt(expression.length);
    output.writeBytes(expression);
}
 
Example 16
Source File: NDArrayKryoSerializer.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, NDArray ndArray)
{

  Object dataVal = ndArray.getData();
  if (dataVal == null) {
    return;
  }
  // NDArray throws an exception in constructor if not an array. So below value will never be null
  Class classNameForArrayType = dataVal.getClass().getComponentType(); // null if it is not an array
  int[] dimensions = ndArray.getDimensions();
  boolean signedFlag = ndArray.isUnsigned();
  int arraySizeInSingleDimension = 1;
  for (int aDimensionSize : dimensions) {
    arraySizeInSingleDimension = arraySizeInSingleDimension * aDimensionSize;
  }
  // write the single dimension length
  output.writeInt(arraySizeInSingleDimension);
  // write the dimension of the dimensions int array
  output.writeInt(dimensions.length);
  // next we write the dimensions array itself
  output.writeInts(dimensions);

  // next write the unsigned flag
  output.writeBoolean(signedFlag);

  // write the data type of the N-dimensional Array
  if (classNameForArrayType != null) {
    output.writeString(classNameForArrayType.getCanonicalName());
  } else {
    output.writeString(null);
  }

  // write the array contents
  if (dataVal != null) {
    switch (classNameForArrayType.getCanonicalName()) {
      case "float":
        output.writeFloats((float[])dataVal);
        break;
      case "int":
        output.writeInts((int[])dataVal);
        break;
      case "double":
        output.writeDoubles((double[])dataVal);
        break;
      case "long":
        output.writeLongs((long[])dataVal);
        break;
      case "short":
        output.writeShorts((short[])dataVal);
        break;
      case "byte":
        output.writeBytes((byte[])dataVal);
        break;
      case "boolean":
        boolean[] originalBoolArray = (boolean[])dataVal;
        short[] convertedBoolArray = new short[originalBoolArray.length];
        for (int i = 0; i < originalBoolArray.length; i++) {
          if (originalBoolArray[i]) {
            convertedBoolArray[i] = TRUE_AS_SHORTINT;
          } else {
            convertedBoolArray[i] = FALSE_AS_SHORTINT;
          }
        }
        output.writeShorts(convertedBoolArray);
        break;
      default:
        throw new RuntimeException("Unsupported NDArray type serialization object");
    }
  }
}
 
Example 17
Source File: PyLongSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, PyLong object) {
	byte[] data = object.getValue().toByteArray();
	output.writeShort(data.length);
	output.writeBytes(data);
}
 
Example 18
Source File: SVFastqUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void serialize( final Kryo kryo, final Output output ) {
    output.writeAscii(header);
    output.writeInt(bases.length);
    output.writeBytes(bases);
    output.writeBytes(quals);
}
 
Example 19
Source File: QNameAndInterval.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void serialize( final Kryo kryo, final Output output ) {
    output.writeInt(qName.length);
    output.writeBytes(qName);
    output.writeInt(hashVal);
    output.writeInt(intervalId);
}
 
Example 20
Source File: IpAddressSerializer.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, IpAddress object) {
    byte[] octs = object.toOctets();
    output.writeInt(octs.length);
    output.writeBytes(octs);
}