use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream 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.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class ImageLoader method load.
private static Image load(@NotNull final InputStream inputStream, final int scale) {
if (scale <= 0)
throw new IllegalArgumentException("Scale must be 1 or greater");
try {
BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
while (true) {
final int n = inputStream.read(buffer);
if (n < 0)
break;
outputStream.write(buffer, 0, n);
}
} finally {
inputStream.close();
}
Image image = Toolkit.getDefaultToolkit().createImage(outputStream.getInternalBuffer(), 0, outputStream.size());
waitForImage(image);
return image;
} catch (Exception ex) {
LOG.error(ex);
}
return null;
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class PersistentHashMap method doPut.
protected void doPut(Key key, Value value) throws IOException {
long newValueOffset = -1;
if (!myIntMapping) {
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
AppendStream appenderStream = ourFlyweightAppenderStream.getValue();
appenderStream.setOut(bytes);
myValueExternalizer.save(appenderStream, value);
appenderStream.setOut(null);
newValueOffset = myValueStorage.appendBytes(bytes.getInternalBuffer(), 0, bytes.size(), 0);
}
myEnumerator.lockStorage();
try {
myEnumerator.markDirty(true);
myAppendCache.remove(key);
long oldValueOffset;
if (myDirectlyStoreLongFileOffsetMode) {
if (myIntMapping) {
((PersistentBTreeEnumerator<Key>) myEnumerator).putNonnegativeValue(key, (Integer) value);
return;
}
oldValueOffset = ((PersistentBTreeEnumerator<Key>) myEnumerator).getNonnegativeValue(key);
((PersistentBTreeEnumerator<Key>) myEnumerator).putNonnegativeValue(key, newValueOffset);
} else {
final int id = enumerate(key);
if (myIntMapping) {
myEnumerator.myStorage.putInt(id + myParentValueRefOffset, (Integer) value);
return;
}
oldValueOffset = readValueId(id);
updateValueId(id, newValueOffset, oldValueOffset, key, 0);
}
if (oldValueOffset != NULL_ADDR) {
myLiveAndGarbageKeysCounter++;
} else {
myLiveAndGarbageKeysCounter += LIVE_KEY_MASK;
}
} finally {
myEnumerator.unlockStorage();
}
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class PersistentHashMapValueStorage method appendBytes.
public long appendBytes(byte[] data, int offset, int dataLength, long prevChunkAddress) throws IOException {
assert allowedToCompactChunks();
// volatile read
long result = mySize;
final FileAccessorCache.Handle<DataOutputStream> appender = myCompressedAppendableFile != null ? null : ourAppendersCache.get(myPath);
DataOutputStream dataOutputStream;
try {
if (myCompressedAppendableFile != null) {
BufferExposingByteArrayOutputStream stream = new BufferExposingByteArrayOutputStream(dataLength + 15);
DataOutputStream testStream = new DataOutputStream(stream);
saveData(data, offset, dataLength, prevChunkAddress, result, testStream);
myCompressedAppendableFile.append(stream.getInternalBuffer(), stream.size());
// volatile write
mySize += stream.size();
} else {
dataOutputStream = appender.get();
dataOutputStream.resetWrittenBytesCount();
saveData(data, offset, dataLength, prevChunkAddress, result, dataOutputStream);
// volatile write
mySize += dataOutputStream.resetWrittenBytesCount();
}
} finally {
if (appender != null)
appender.release();
}
return result;
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class RefCountingStorage method internalReadStream.
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
waitForPendingWriteForRecord(record);
byte[] result;
synchronized (myLock) {
result = super.readBytes(record);
}
InflaterInputStream in = new CustomInflaterInputStream(result);
try {
final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
StreamUtil.copyStreamContent(in, outputStream);
return outputStream;
} finally {
in.close();
}
}
Aggregations