Search in sources :

Example 21 with BufferExposingByteArrayOutputStream

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

Example 22 with BufferExposingByteArrayOutputStream

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

Example 23 with BufferExposingByteArrayOutputStream

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

Example 24 with BufferExposingByteArrayOutputStream

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

Example 25 with BufferExposingByteArrayOutputStream

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

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