use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class PersistentHashMap method doAppendData.
protected void doAppendData(Key key, @NotNull ValueDataAppender appender) throws IOException {
assert !myIntMapping;
myEnumerator.markDirty(true);
AppendStream appenderStream = ourFlyweightAppenderStream.getValue();
BufferExposingByteArrayOutputStream stream = myAppendCache.get(key);
appenderStream.setOut(stream);
appender.append(appenderStream);
appenderStream.setOut(null);
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class PersistentHashMapValueStorage method compactChunks.
long compactChunks(PersistentHashMap.ValueDataAppender appender, ReadResult result) throws IOException {
checkCancellation();
long startedTime = ourDumpChunkRemovalTime ? System.nanoTime() : 0;
long newValueOffset;
if (myCompactChunksWithValueDeserialization) {
final BufferExposingByteArrayOutputStream stream = new BufferExposingByteArrayOutputStream(result.buffer.length);
DataOutputStream testStream = new DataOutputStream(stream);
appender.append(testStream);
newValueOffset = appendBytes(stream.getInternalBuffer(), 0, stream.size(), 0);
myChunksBytesAfterRemoval += stream.size();
} else {
newValueOffset = appendBytes(new ByteSequence(result.buffer), 0);
myChunksBytesAfterRemoval += result.buffer.length;
}
if (ourDumpChunkRemovalTime) {
myChunksRemovalTime += System.nanoTime() - startedTime;
if (myChunks - myLastReportedChunksCount > 1000) {
myLastReportedChunksCount = myChunks;
System.out.println(myChunks + " chunks were read " + (myChunksReadingTime / 1000000) + "ms, bytes: " + myChunksOriginalBytes + (myChunksOriginalBytes != myChunksBytesAfterRemoval ? "->" + myChunksBytesAfterRemoval : "") + " compaction:" + (myChunksRemovalTime / 1000000) + "ms in " + myPath);
}
}
return newValueOffset;
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class JBZipOutputStream method putNextEntryBytes.
public void putNextEntryBytes(JBZipEntry entry, byte[] bytes) throws IOException {
entry.setSize(bytes.length);
crc.reset();
crc.update(bytes);
entry.setCrc(crc.getValue());
if (entry.getMethod() == -1) {
entry.setMethod(method);
}
if (entry.getTime() == -1) {
entry.setTime(System.currentTimeMillis());
}
final byte[] outputBytes;
final int outputBytesLength;
if (entry.getMethod() == ZipEntry.DEFLATED) {
def.setLevel(level);
final BufferExposingByteArrayOutputStream compressedBytesStream = new BufferExposingByteArrayOutputStream();
final DeflaterOutputStream stream = new DeflaterOutputStream(compressedBytesStream, def);
try {
stream.write(bytes);
} finally {
stream.close();
}
outputBytesLength = compressedBytesStream.size();
outputBytes = compressedBytesStream.getInternalBuffer();
} else {
outputBytesLength = bytes.length;
outputBytes = bytes;
}
entry.setCompressedSize(outputBytesLength);
writeLocalFileHeader(entry);
writeOut(outputBytes, 0, outputBytesLength);
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.
the class SmallMapSerializer method force.
@Override
public void force() {
if (!myDirty)
return;
try {
final BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream();
final DataOutput out = new DataOutputStream(bos);
out.writeInt(myMap.size());
for (Map.Entry<KeyWrapper<K>, V> entry : myMap.entrySet()) {
myKeyDescriptor.save(out, entry.getKey().myKey);
myValueExternalizer.save(out, entry.getValue());
}
FileUtil.writeToFile(myFile, bos.getInternalBuffer(), 0, bos.size());
} catch (IOException e) {
LOG.error(e);
} finally {
myDirty = false;
}
}
use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-plugins by JetBrains.
the class SwfPolicyFileConnection method run.
protected void run(InputStream inputStream) throws IOException {
InputStreamReader reader = new InputStreamReader(inputStream);
BufferExposingByteArrayOutputStream buffer = new BufferExposingByteArrayOutputStream(100);
while (!isStopped()) {
int i = reader.read();
if (i == -1)
return;
if (i == 0)
break;
buffer.write(i);
}
final String request = new String(buffer.getInternalBuffer(), 0, buffer.size());
LOG.debug("Policy file request: " + request);
if (POLICY_FILE_REQUEST.equals(request)) {
write(myContent);
}
}
Aggregations