use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class SharedIndicesData method doAssociateData.
private static <Key, Value> void doAssociateData(int id, final ID<Key, ?> indexId, Value keys, DataExternalizer<Value> externalizer, IndexedStateMap index) throws IOException {
final BufferExposingByteArrayOutputStream savedKeysData;
if (keys != null) {
//noinspection IOResourceOpenedButNotSafelyClosed
externalizer.save(new DataOutputStream(savedKeysData = new BufferExposingByteArrayOutputStream()), keys);
} else {
savedKeysData = null;
}
FileAccessorCache.Handle<IndexedState> stateHandle = index.myStateCache.getIfCached(id);
try {
index.appendData(id, new PersistentHashMap.ValueDataAppender() {
@Override
public void append(DataOutput out) throws IOException {
byte[] internalBuffer = null;
int size = 0;
if (savedKeysData != null) {
internalBuffer = savedKeysData.getInternalBuffer();
size = savedKeysData.size();
}
long indexCreationStamp = IndexingStamp.getIndexCreationStamp(indexId);
writeIndexValue(indexId.getUniqueId(), indexCreationStamp, internalBuffer, 0, size, out);
final IndexedState indexedState = stateHandle != null ? stateHandle.get() : null;
if (indexedState != null) {
indexedState.appendIndexedState(indexId, indexCreationStamp, internalBuffer, size);
}
}
});
} finally {
if (stateHandle != null)
stateHandle.release();
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class VfsAwareMapIndexStorage method saveHashedIds.
private void saveHashedIds(@NotNull TIntHashSet hashMaskSet, int largestId, @NotNull GlobalSearchScope scope) {
File newFileWithCaches = getSavedProjectFileValueIds(largestId, scope);
assert newFileWithCaches != null;
DataOutputStream stream = null;
boolean savedSuccessfully = false;
try {
stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFileWithCaches)));
DataInputOutputUtil.writeINT(stream, hashMaskSet.size());
final DataOutputStream finalStream = stream;
savedSuccessfully = hashMaskSet.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
try {
DataInputOutputUtil.writeINT(finalStream, value);
return true;
} catch (IOException ex) {
return false;
}
}
});
} catch (IOException ignored) {
} finally {
if (stream != null) {
try {
stream.close();
if (savedSuccessfully)
myLastScannedId = largestId;
} catch (IOException ignored) {
}
}
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class FSRecords method updateList.
public static void updateList(int id, @NotNull int[] childIds) {
Arrays.sort(childIds);
w.lock();
try {
DbConnection.markDirty();
try (DataOutputStream record = writeAttribute(id, ourChildrenAttr)) {
DataInputOutputUtil.writeINT(record, childIds.length);
int prevId = id;
for (int childId : childIds) {
assert childId > 0 : childId;
if (childId == id) {
LOG.error("Cyclic parent child relations");
} else {
int delta = childId - prevId;
DataInputOutputUtil.writeINT(record, delta);
prevId = childId;
}
}
}
} catch (Throwable e) {
DbConnection.handleError(e);
} finally {
w.unlock();
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class FSRecords method deleteRootRecord.
static void deleteRootRecord(int id) {
w.lock();
try {
DbConnection.markDirty();
if (ourStoreRootsSeparately) {
java.util.List<String> rootsThatLeft = new ArrayList<>();
try {
try (LineNumberReader stream = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(DbConnection.myRootsFile))))) {
String str;
while ((str = stream.readLine()) != null) {
int index = str.indexOf(' ');
int rootId = Integer.parseInt(str.substring(0, index));
if (rootId != id) {
rootsThatLeft.add(str);
}
}
}
} catch (FileNotFoundException ignored) {
}
try (Writer stream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(DbConnection.myRootsFile)))) {
for (String line : rootsThatLeft) {
stream.write(line);
stream.write("\n");
}
}
return;
}
final DataInputStream input = readAttribute(ROOT_RECORD_ID, ourChildrenAttr);
assert input != null;
int[] names;
int[] ids;
try {
int count = DataInputOutputUtil.readINT(input);
names = ArrayUtil.newIntArray(count);
ids = ArrayUtil.newIntArray(count);
int prevId = 0;
int prevNameId = 0;
for (int i = 0; i < count; i++) {
names[i] = DataInputOutputUtil.readINT(input) + prevNameId;
ids[i] = DataInputOutputUtil.readINT(input) + prevId;
prevId = ids[i];
prevNameId = names[i];
}
} finally {
input.close();
}
final int index = ArrayUtil.find(ids, id);
assert index >= 0;
names = ArrayUtil.remove(names, index);
ids = ArrayUtil.remove(ids, index);
try (DataOutputStream output = writeAttribute(ROOT_RECORD_ID, ourChildrenAttr)) {
saveNameIdSequenceWithDeltas(names, ids, output);
}
} catch (Throwable e) {
DbConnection.handleError(e);
} finally {
w.unlock();
}
}
use of com.intellij.util.io.DataOutputStream in project intellij-community by JetBrains.
the class FSRecords method findRootRecord.
static int findRootRecord(@NotNull String rootUrl) {
w.lock();
try {
DbConnection.markDirty();
if (ourStoreRootsSeparately) {
try {
try (LineNumberReader stream = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(DbConnection.myRootsFile))))) {
String str;
while ((str = stream.readLine()) != null) {
int index = str.indexOf(' ');
if (str.substring(index + 1).equals(rootUrl)) {
return Integer.parseInt(str.substring(0, index));
}
}
}
} catch (FileNotFoundException ignored) {
}
try (Writer stream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(DbConnection.myRootsFile, true)))) {
int id = createRecord();
stream.write(id + " " + rootUrl + "\n");
return id;
}
}
final int root = getNames().enumerate(rootUrl);
final DataInputStream input = readAttribute(ROOT_RECORD_ID, ourChildrenAttr);
int[] names = ArrayUtil.EMPTY_INT_ARRAY;
int[] ids = ArrayUtil.EMPTY_INT_ARRAY;
if (input != null) {
try {
final int count = DataInputOutputUtil.readINT(input);
names = ArrayUtil.newIntArray(count);
ids = ArrayUtil.newIntArray(count);
int prevId = 0;
int prevNameId = 0;
for (int i = 0; i < count; i++) {
final int name = DataInputOutputUtil.readINT(input) + prevNameId;
final int id = DataInputOutputUtil.readINT(input) + prevId;
if (name == root) {
return id;
}
prevNameId = names[i] = name;
prevId = ids[i] = id;
}
} finally {
input.close();
}
}
int id;
try (DataOutputStream output = writeAttribute(ROOT_RECORD_ID, ourChildrenAttr)) {
id = createRecord();
int index = Arrays.binarySearch(ids, id);
ids = ArrayUtil.insert(ids, -index - 1, id);
names = ArrayUtil.insert(names, -index - 1, root);
saveNameIdSequenceWithDeltas(names, ids, output);
}
return id;
} catch (Throwable e) {
DbConnection.handleError(e);
} finally {
w.unlock();
}
return -1;
}
Aggregations