org.mapdb.DataOutput2 Java Examples

The following examples show how to use org.mapdb.DataOutput2. 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: MapSerializer.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void serialize(DataOutput2 out, Map<String, Object> map) throws IOException {
    Objects.requireNonNull(out);
    Objects.requireNonNull(map);

    out.packInt(map.size());

    for (String k : map.keySet()) {
        Object o = map.get(k);
        if (o instanceof Double) {
            out.writeUTF("D" + k);
            out.writeDouble((Double) o);
        } else if (o instanceof Long) {
            out.writeUTF("L" + k);
            out.writeLong((Long) o);
        } else if (o instanceof String) {
            out.writeUTF("S" + k);
            out.writeUTF((String) o);
        } else if (o instanceof Integer) {
            out.writeUTF("I" + k);
            out.writeInt((Integer) o);
        } else {
            throw new RuntimeException("Unexpected type " + o.getClass());
        }
    }
}
 
Example #2
Source File: CachedEventGroupSerializer.java    From eagle with Apache License 2.0 6 votes vote down vote up
private void writePartitionedEvent(DataOutput2 out, PartitionedEvent event) throws IOException {
    out.packLong(event.getPartitionKey());
    int partitionHashCode = 0;
    if (event.getPartition() != null) {
        partitionHashCode = event.getPartition().hashCode();
        if (!hashCodePartitionDict.containsKey(partitionHashCode)) {
            hashCodePartitionDict.put(partitionHashCode, event.getPartition());
        }
    }
    out.packInt(partitionHashCode);
    if (event.getEvent() != null) {
        byte[] eventBytes = SerializableUtils.serializeToCompressedByteArray(event.getEvent());
        out.packInt(eventBytes.length);
        out.write(eventBytes);
    } else {
        out.packInt(0);
    }
}
 
Example #3
Source File: MapSerializer.java    From NNAnalytics with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull Map<String, Long> value)
    throws IOException {
  out.writeInt(value.size());
  for (Map.Entry<String, Long> entry : value.entrySet()) {
    out.writeUTF(entry.getKey());
    out.writeLong(entry.getValue());
  }
}
 
Example #4
Source File: MapSerializer.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void valueArraySerialize(DataOutput2 out, Object vals) throws IOException {
    Objects.requireNonNull(vals);
    if (vals instanceof TreeMap) {
        this.serialize(out, (TreeMap) vals);
    } else {
        Object[] maps = (Object[]) vals;
        for (Object t : maps) {
            this.serialize(out, (Map<String, Object>) t);
        }
    }
}
 
Example #5
Source File: CachedEventGroupSerializer.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(DataOutput2 out, PartitionedEvent[] value) throws IOException {
    out.packInt(value.length);
    for (PartitionedEvent event : value) {
        writePartitionedEvent(out, event);
    }
}
 
Example #6
Source File: MapDBTools.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull int[] data)
	throws IOException {
	assert (data.length == numPos);
	for (int i=0; i<numPos; i++) {
		encoding.write(out, data[i] + 1);
	}
}
 
Example #7
Source File: LockDescSerializer.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull LockDesc value) throws IOException {
  out.writeUTF(value.getPath());

  if (value.getBranch() != null) {
    out.writeBoolean(true);
    out.writeUTF(value.getBranch());
  } else {
    out.writeBoolean(false);
  }

  if (value.getHash() != null) {
    out.writeBoolean(true);
    out.writeUTF(value.getHash());
  } else {
    out.writeBoolean(false);
  }

  out.writeUTF(value.getToken());

  if (value.getOwner() != null) {
    out.writeBoolean(true);
    out.writeUTF(value.getOwner());
  } else {
    out.writeBoolean(false);
  }

  if (value.getComment() != null) {
    out.writeBoolean(true);
    out.writeUTF(value.getComment());
  } else {
    out.writeBoolean(false);
  }

  out.writeLong(value.getCreated());
}
 
Example #8
Source File: PartitionedEventGroupSerializer.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Override
public void valueArraySerialize(DataOutput2 out, Object vals) throws IOException {
    delegate.valueArraySerialize(out, vals);
}
 
Example #9
Source File: PartitionedEventGroupSerializer.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull PartitionedEvent[] value) throws IOException {
    delegate.serialize(out, serialize(value));
}
 
Example #10
Source File: MapDBTools.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull Sequence sequence)
	throws IOException {
	out.writeUTF(getSequenceId(sequence));
}
 
Example #11
Source File: MapDBTools.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull BigDecimal data)
	throws IOException {
	io.write(out, data);
}
 
Example #12
Source File: MapDBTools.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull MathTools.BigDecimalBounds data)
	throws IOException {
	s.serialize(out, data.lower);
	s.serialize(out, data.upper);
}
 
Example #13
Source File: ObjectIdSerializer.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(@NotNull DataOutput2 out, @NotNull ObjectId value) throws IOException {
  value.copyRawTo(out);
}