Search in sources :

Example 1 with UnsyncByteArrayInputStream

use of com.intellij.util.io.UnsyncByteArrayInputStream in project intellij-community by JetBrains.

the class SmallMapSerializer method init.

private void init() {
    try {
        final byte[] bytes = FileUtil.loadFileBytes(myFile);
        final DataInputStream dis = new DataInputStream(new UnsyncByteArrayInputStream(bytes));
        final int size = dis.readInt();
        for (int i = 0; i < size; i++) {
            final KeyWrapper<K> keyWrapper = new KeyWrapper<>(myKeyDescriptor, myKeyDescriptor.read(dis));
            final V value = myValueExternalizer.read(dis);
            myMap.put(keyWrapper, value);
        }
    } catch (FileNotFoundException ignore) {
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : UnsyncByteArrayInputStream(com.intellij.util.io.UnsyncByteArrayInputStream)

Example 2 with UnsyncByteArrayInputStream

use of com.intellij.util.io.UnsyncByteArrayInputStream in project intellij-community by JetBrains.

the class HTMLControls method loadControls.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
private static Control[] loadControls() {
    Element element;
    try {
        // use temporary bytes stream because otherwise inputStreamSkippingBOM will fail
        // on ZipFileInputStream used in jar files
        final InputStream stream = HTMLControls.class.getResourceAsStream("HtmlControls.xml");
        final byte[] bytes = FileUtilRt.loadBytes(stream);
        stream.close();
        final UnsyncByteArrayInputStream bytesStream = new UnsyncByteArrayInputStream(bytes);
        element = JDOMUtil.load(CharsetToolkit.inputStreamSkippingBOM(bytesStream));
        bytesStream.close();
    } catch (Exception e) {
        LOG.error(e);
        return new Control[0];
    }
    if (!element.getName().equals("htmlControls")) {
        LOG.error("HTMLControls storage is broken");
        return new Control[0];
    }
    return XmlSerializer.deserialize(element, Control[].class);
}
Also used : UnsyncByteArrayInputStream(com.intellij.util.io.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(org.jdom.Element) UnsyncByteArrayInputStream(com.intellij.util.io.UnsyncByteArrayInputStream)

Example 3 with UnsyncByteArrayInputStream

use of com.intellij.util.io.UnsyncByteArrayInputStream 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)

Aggregations

UnsyncByteArrayInputStream (com.intellij.util.io.UnsyncByteArrayInputStream)3 BufferExposingByteArrayOutputStream (com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)1 DataOutputStream (com.intellij.util.io.DataOutputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Element (org.jdom.Element)1