Search in sources :

Example 6 with BufferExposingByteArrayOutputStream

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

Example 7 with BufferExposingByteArrayOutputStream

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

Example 8 with BufferExposingByteArrayOutputStream

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

Example 9 with BufferExposingByteArrayOutputStream

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

Example 10 with BufferExposingByteArrayOutputStream

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

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