Search in sources :

Example 1 with DataOutputStream

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;
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DataOutputStream(com.intellij.util.io.DataOutputStream) THashMap(gnu.trove.THashMap) SmartList(com.intellij.util.SmartList) THashMap(gnu.trove.THashMap)

Example 2 with DataOutputStream

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

Example 3 with DataOutputStream

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;
}
Also used : DataOutputStream(com.intellij.util.io.DataOutputStream) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DataOutputStream

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

Example 5 with DataOutputStream

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) {
    }
}
Also used : DataOutputStream(com.intellij.util.io.DataOutputStream) THashSet(gnu.trove.THashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

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