use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class MapReduceIndex method checkValuesHaveProperEqualsAndHashCode.
public static <Key, Value> void checkValuesHaveProperEqualsAndHashCode(@NotNull Map<Key, Value> data, @NotNull ID<Key, Value> indexId, @NotNull DataExternalizer<Value> valueExternalizer) {
if (DebugAssertions.DEBUG) {
for (Map.Entry<Key, Value> e : data.entrySet()) {
final Value value = e.getValue();
if (!(Comparing.equal(value, value) && (value == null || value.hashCode() == value.hashCode()))) {
LOG.error("Index " + indexId + " violates equals / hashCode contract for Value parameter");
}
try {
final BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(out);
valueExternalizer.save(outputStream, value);
outputStream.close();
final Value deserializedValue = valueExternalizer.read(new DataInputStream(new UnsyncByteArrayInputStream(out.getInternalBuffer(), 0, out.size())));
if (!(Comparing.equal(value, deserializedValue) && (value == null || value.hashCode() == deserializedValue.hashCode()))) {
LOG.error("Index " + indexId + " deserialization violates equals / hashCode contract for Value parameter");
}
} catch (IOException ex) {
LOG.error(ex);
}
}
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class SmallMapSerializer method force.
@Override
public void force() {
if (!myDirty)
return;
try {
final BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream();
final DataOutput out = new DataOutputStream(bos);
out.writeInt(myMap.size());
for (Map.Entry<KeyWrapper<K>, V> entry : myMap.entrySet()) {
myKeyDescriptor.save(out, entry.getKey().myKey);
myValueExternalizer.save(out, entry.getValue());
}
FileUtil.writeToFile(myFile, bos.getInternalBuffer(), 0, bos.size());
} catch (IOException e) {
LOG.error(e);
} finally {
myDirty = false;
}
}
Aggregations