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);
}
}
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);
}
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);
}
}
}
}
Aggregations