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