Search in sources :

Example 1 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.

the class RadFormLayoutManager method createSerializedCopy.

private static Object createSerializedCopy(final Object original) {
    // FormLayout may have been loaded with a different classloader, so we need to create a copy through serialization
    Object copy;
    try {
        BufferExposingByteArrayOutputStream baos = new BufferExposingByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        try {
            os.writeObject(original);
        } finally {
            os.close();
        }
        InputStream bais = new ByteArrayInputStream(baos.getInternalBuffer(), 0, baos.size());
        ObjectInputStream is = new ObjectInputStream(bais);
        try {
            copy = is.readObject();
        } finally {
            is.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return copy;
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.

the class DiffContentRevision method getContentAsBytes.

@NotNull
@Override
public byte[] getContentAsBytes() throws VcsException {
    if (myContents == null) {
        BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream(2048);
        try {
            myRepository.getFile(myPath, -1, null, bos);
            myRepository.closeSession();
        } catch (SVNException e) {
            throw new VcsException(e);
        }
        myContents = bos.toByteArray();
    }
    return myContents;
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) VcsException(com.intellij.openapi.vcs.VcsException) SVNException(org.tmatesoft.svn.core.SVNException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.

the class MavenProject method write.

public void write(@NotNull DataOutputStream out) throws IOException {
    out.writeUTF(getPath());
    BufferExposingByteArrayOutputStream bs = new BufferExposingByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(bs);
    try {
        os.writeObject(myState);
        out.writeInt(bs.size());
        out.write(bs.getInternalBuffer(), 0, bs.size());
    } finally {
        os.close();
        bs.close();
    }
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream)

Example 4 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.

the class SnapshotInputMappings method savePersistentData.

private boolean savePersistentData(Map<Key, Value> data, int id, boolean delayedReading) {
    try {
        if (delayedReading && myContents.containsMapping(id))
            return false;
        BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(ourSpareByteArray.getBuffer(4 * data.size()));
        DataOutputStream stream = new DataOutputStream(out);
        int size = data.size();
        DataInputOutputUtil.writeINT(stream, size);
        if (size > 0) {
            THashMap<Value, List<Key>> values = new THashMap<>();
            List<Key> keysForNullValue = null;
            for (Map.Entry<Key, Value> e : data.entrySet()) {
                Value value = e.getValue();
                List<Key> keys = value != null ? values.get(value) : keysForNullValue;
                if (keys == null) {
                    if (value != null)
                        values.put(value, keys = new SmartList<>());
                    else
                        keys = keysForNullValue = new SmartList<>();
                }
                keys.add(e.getKey());
            }
            if (keysForNullValue != null) {
                myValueExternalizer.save(stream, null);
                mySnapshotIndexExternalizer.save(stream, keysForNullValue);
            }
            for (Value value : values.keySet()) {
                myValueExternalizer.save(stream, value);
                mySnapshotIndexExternalizer.save(stream, values.get(value));
            }
        }
        saveContents(id, out);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    return true;
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DataOutputStream(com.intellij.util.io.DataOutputStream) THashMap(gnu.trove.THashMap) SmartList(com.intellij.util.SmartList) THashMap(gnu.trove.THashMap)

Example 5 with BufferExposingByteArrayOutputStream

use of com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream in project intellij-community by JetBrains.

the class AboutHttpService method execute.

@Nullable
@Override
public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
    @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") BufferExposingByteArrayOutputStream byteOut = new BufferExposingByteArrayOutputStream();
    getAbout(byteOut, urlDecoder);
    send(byteOut, request, context);
    return null;
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) Nullable(org.jetbrains.annotations.Nullable)

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