Search in sources :

Example 11 with DataOutputStream

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);
            }
        }
    }
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DataOutputStream(com.intellij.util.io.DataOutputStream) UnsyncByteArrayInputStream(com.intellij.util.io.UnsyncByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Map(java.util.Map)

Example 12 with DataOutputStream

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;
    }
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DataOutputStream(com.intellij.util.io.DataOutputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DataOutputStream (com.intellij.util.io.DataOutputStream)12 BufferExposingByteArrayOutputStream (com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)6 Map (java.util.Map)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 SmartList (com.intellij.util.SmartList)1 IntArrayList (com.intellij.util.containers.IntArrayList)1 UnsyncByteArrayInputStream (com.intellij.util.io.UnsyncByteArrayInputStream)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 TIntArrayList (gnu.trove.TIntArrayList)1 TIntProcedure (gnu.trove.TIntProcedure)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1