Search in sources :

Example 11 with BufferExposingByteArrayOutputStream

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

the class CompressedAppendableFile method append.

public synchronized <Data> void append(Data value, KeyDescriptor<Data> descriptor) throws IOException {
    final BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream();
    DataOutput out = new DataOutputStream(bos);
    descriptor.save(out, value);
    final int size = bos.size();
    final byte[] buffer = bos.getInternalBuffer();
    append(buffer, size);
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)

Example 12 with BufferExposingByteArrayOutputStream

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

the class GroovyTraitMethodsFileIndex method save.

@Override
public void save(@NotNull DataOutput out, PsiJavaFileStub value) throws IOException {
    BufferExposingByteArrayOutputStream buffer = new BufferExposingByteArrayOutputStream();
    SerializationManagerEx.getInstanceEx().serialize(value, buffer);
    out.writeInt(buffer.size());
    out.write(buffer.getInternalBuffer(), 0, buffer.size());
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)

Example 13 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream 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 14 with BufferExposingByteArrayOutputStream

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

Example 15 with BufferExposingByteArrayOutputStream

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

the class StubSerializationHelper method serialize.

public void serialize(@NotNull Stub rootStub, @NotNull OutputStream stream) throws IOException {
    BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
    FileLocalStringEnumerator storage = new FileLocalStringEnumerator(true);
    StubOutputStream stubOutputStream = new StubOutputStream(out, storage);
    boolean doDefaultSerialization = true;
    if (rootStub instanceof PsiFileStub) {
        final PsiFileStub[] roots = ((PsiFileStub) rootStub).getStubRoots();
        if (roots.length == 0) {
            Logger.getInstance(getClass()).error("Incorrect stub files count during serialization:" + rootStub + "," + rootStub.getStubType());
        } else {
            doDefaultSerialization = false;
            DataInputOutputUtil.writeINT(stubOutputStream, roots.length);
            for (PsiFileStub root : roots) {
                doSerialize(root, stubOutputStream);
            }
        }
    }
    if (doDefaultSerialization) {
        DataInputOutputUtil.writeINT(stubOutputStream, 1);
        doSerialize(rootStub, stubOutputStream);
    }
    DataOutputStream resultStream = new DataOutputStream(stream);
    DataInputOutputUtil.writeINT(resultStream, storage.myStrings.size());
    byte[] buffer = IOUtil.allocReadWriteUTFBuffer();
    for (String s : storage.myStrings) {
        IOUtil.writeUTFFast(buffer, resultStream, s);
    }
    resultStream.write(out.getInternalBuffer(), 0, out.size());
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream)

Aggregations

BufferExposingByteArrayOutputStream (com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)25 DataOutputStream (com.intellij.util.io.DataOutputStream)6 THashMap (gnu.trove.THashMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ByteSequence (com.intellij.openapi.util.io.ByteSequence)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 SmartList (com.intellij.util.SmartList)1 UnsyncByteArrayInputStream (com.intellij.util.io.UnsyncByteArrayInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1