use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class SnapshotInputMappings method savePersistentData.
private boolean savePersistentData(Map<Key, Value> data, int id, boolean delayedReading) {
try {
if (delayedReading && myContents.containsMapping(id))
return false;
BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(ourSpareByteArray.getBuffer(4 * data.size()));
DataOutputStream stream = new DataOutputStream(out);
int size = data.size();
DataInputOutputUtil.writeINT(stream, size);
if (size > 0) {
THashMap<Value, List<Key>> values = new THashMap<>();
List<Key> keysForNullValue = null;
for (Map.Entry<Key, Value> e : data.entrySet()) {
Value value = e.getValue();
List<Key> keys = value != null ? values.get(value) : keysForNullValue;
if (keys == null) {
if (value != null)
values.put(value, keys = new SmartList<>());
else
keys = keysForNullValue = new SmartList<>();
}
keys.add(e.getKey());
}
if (keysForNullValue != null) {
myValueExternalizer.save(stream, null);
mySnapshotIndexExternalizer.save(stream, keysForNullValue);
}
for (Value value : values.keySet()) {
myValueExternalizer.save(stream, value);
mySnapshotIndexExternalizer.save(stream, values.get(value));
}
}
saveContents(id, out);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return true;
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class BuildSession method updateFsStateOnDisk.
private static void updateFsStateOnDisk(File dataStorageRoot, DataInputStream original, final long ordinal) {
final File file = new File(dataStorageRoot, FS_STATE_FILE);
try {
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytes);
try {
out.writeInt(BuildFSState.VERSION);
out.writeLong(ordinal);
out.writeBoolean(false);
while (true) {
final int b = original.read();
if (b == -1) {
break;
}
out.write(b);
}
} finally {
out.close();
}
saveOnDisk(bytes, file);
} catch (Throwable e) {
LOG.error(e);
FileUtil.delete(file);
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class HashSerializeTest method writeToTempFile.
@NotNull
private static File writeToTempFile(@NotNull HashImpl... hashes) throws IOException {
File file = FileUtil.createTempFile("", "");
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
try {
for (HashImpl hash : hashes) {
hash.write(out);
}
} finally {
out.close();
}
return file;
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class BuildSession method saveFsState.
private void saveFsState(File dataStorageRoot, BuildFSState state) {
final ProjectDescriptor pd = myProjectDescriptor;
final File file = new File(dataStorageRoot, FS_STATE_FILE);
try {
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytes);
try {
out.writeInt(BuildFSState.VERSION);
out.writeLong(myLastEventOrdinal);
out.writeBoolean(hasWorkToDo(state, pd));
state.save(out);
} finally {
out.close();
}
saveOnDisk(bytes, file);
} catch (Throwable e) {
LOG.error(e);
FileUtil.delete(file);
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class FileBasedIndexImpl method saveRegisteredIndicesAndDropUnregisteredOnes.
private static void saveRegisteredIndicesAndDropUnregisteredOnes(@NotNull Collection<ID<?, ?>> ids) {
if (ApplicationManager.getApplication().isDisposed()) {
return;
}
final File registeredIndicesFile = new File(PathManager.getIndexRoot(), "registered");
final Set<String> indicesToDrop = new THashSet<>();
try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(registeredIndicesFile)))) {
final int size = in.readInt();
for (int idx = 0; idx < size; idx++) {
indicesToDrop.add(IOUtil.readString(in));
}
} catch (IOException ignored) {
}
for (ID<?, ?> key : ids) {
indicesToDrop.remove(key.toString());
}
if (!indicesToDrop.isEmpty()) {
LOG.info("Dropping indices:" + StringUtil.join(indicesToDrop, ","));
for (String s : indicesToDrop) {
FileUtil.deleteWithRenaming(IndexInfrastructure.getIndexRootDir(ID.create(s)));
}
}
FileUtil.createIfDoesntExist(registeredIndicesFile);
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(registeredIndicesFile)))) {
os.writeInt(ids.size());
for (ID<?, ?> id : ids) {
IOUtil.writeString(id.toString(), os);
}
} catch (IOException ignored) {
}
}
Aggregations