Repository: intellij-rust/intellij-rust
Issue: Save settings failed

## Environment

* **IntelliJ Rust plugin version:** 0.2.122.3104-201
* **Rust toolchain version:** rustc 1.43.1 (8d69840ab 2020-05-04)
* **IDE name and version:** 
PhpStorm 2020.1.1
Build #PS-201.7223.96, built on April 30, 2020
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.3.0-46-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1937M
Cores: 16
Registry: run.processes.with.pty=TRUE, editor.distraction.free.mode=true
Non-Bundled Plugins: com.alayouni.ansiHighlight, com.intellij.ideolog, mobi.hsz.idea.gitignore, org.jetbrains.plugins.go-template, BashSupport, com.intellij.kubernetes, com.intellij.plugins.html.instantEditing, ru.adelf.idea.dotenv, intellij.prettierJS, org.toml.lang, org.rust.lang
Current Desktop: ubuntu:GNOME

## Problem description
Everytime I enable the Rust Plugin and try save a I get the error shown below. It will disable the Rust plugin. I reboot the IDE then the Rust plugin is disabled, when I reenable it the error comes again.

> 15:23	Unable to save plugin settings: The plugin org.rust.lang failed to save settings and has been disabled. Please restart PhpStorm

The logs are showing 
```
2020-05-19 15:23:23,810 [  39550]   WARN - mponents.impl.stores.StoreUtil - Save settings failed 
java.lang.NoClassDefFoundError: org/apache/commons/io/output/ByteArrayOutputStream
	at org.rust.lang.core.macros.MacroExpansionServiceImplInner$save$2$invokeSuspend$$inlined$runReadAction$1.compute(actions.kt:79)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:884)
	at org.rust.lang.core.macros.MacroExpansionServiceImplInner$save$2.invokeSuspend(MacroExpansionManager.kt:1064)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
```

I have tried uninstalling and reinstalling PHPStorm and the Rust Plugin as well as deleting the .idea file. Same issue




Changed files:
src/main/kotlin/org/rust/stdext/io.kt, src/main/kotlin/org/rust/lang/core/macros/MacroExpansionManager.kt

diff --git a/src/main/kotlin/org/rust/lang/core/macros/MacroExpansionManager.kt b/src/main/kotlin/org/rust/lang/core/macros/MacroExpansionManager.kt
index e2d53df0d..df5e1e2bd 100644
--- a/src/main/kotlin/org/rust/lang/core/macros/MacroExpansionManager.kt
+++ b/src/main/kotlin/org/rust/lang/core/macros/MacroExpansionManager.kt
@@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project
 import com.intellij.openapi.roots.ContentIterator
 import com.intellij.openapi.roots.ex.ProjectRootManagerEx
 import com.intellij.openapi.util.*
+import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream
 import com.intellij.openapi.vfs.*
 import com.intellij.openapi.vfs.newvfs.RefreshQueue
 import com.intellij.openapiext.Testmark
@@ -439,7 +440,7 @@ private class MacroExpansionServiceImplInner(
             // Using a buffer to avoid IO in the read action
             // BACKCOMPAT: 2020.1 use async read action and extract `runReadAction` from `withContext`
             val (buffer, modCount) = runReadAction {
-                val buffer = ChunkedByteArrayOutputStream(1024*1024) // average stdlib storage size
+                val buffer = BufferExposingByteArrayOutputStream(1024*1024) // average stdlib storage size
                 DataOutputStream(buffer).use { data ->
                     ExpandedMacroStorage.saveStorage(storage, data)
                     val dirToSave = MacroExpansionFileSystem.getInstance().getDirectory(dirs.expansionDirPath) ?: run {
@@ -452,7 +453,7 @@ private class MacroExpansionServiceImplInner(
             }
 
             Files.createDirectories(dataFile.parent)
-            dataFile.newDeflaterDataOutputStream().use { it.writeStream(buffer.toInputStream()) }
+            dataFile.newDeflaterDataOutputStream().use { it.write(buffer.internalBuffer) }
             MacroExpansionFileSystemRootsLoader.saveProjectDirs()
             lastSavedStorageModCount = modCount
         }
diff --git a/src/main/kotlin/org/rust/stdext/io.kt b/src/main/kotlin/org/rust/stdext/io.kt
index 0e388e820..ae6fb8433 100644
--- a/src/main/kotlin/org/rust/stdext/io.kt
+++ b/src/main/kotlin/org/rust/stdext/io.kt
@@ -9,8 +9,6 @@ import com.intellij.openapi.util.io.FileUtil
 import com.intellij.util.io.DataInputOutputUtil
 import java.io.*
 
-typealias ChunkedByteArrayOutputStream = org.apache.commons.io.output.ByteArrayOutputStream
-
 @Throws(IOException::class)
 fun DataInput.readVarInt(): Int =
     DataInputOutputUtil.readINT(this)