summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTobias Roeser <le.petit.fou@web.de>2019-02-19 17:14:49 +0100
committerTobias Roeser <le.petit.fou@web.de>2019-02-19 17:30:11 +0100
commita9543ea9f841b75c55f0cbcd385d40901ce85b89 (patch)
treebe6c1eb558d2136bdce9fee2602d549852d5b5da /main
parentcbe92711ffb1b89445f4e2653a6197e494542fae (diff)
downloadmill-a9543ea9f841b75c55f0cbcd385d40901ce85b89.tar.gz
mill-a9543ea9f841b75c55f0cbcd385d40901ce85b89.tar.bz2
mill-a9543ea9f841b75c55f0cbcd385d40901ce85b89.zip
Splitted IO.scala to avoid cyclic references
Diffstat (limited to 'main')
-rw-r--r--main/api/src/mill/api/IO.scala33
-rw-r--r--main/api/src/mill/api/PathRef.scala2
-rw-r--r--main/api/src/mill/api/StreamSupport.scala38
3 files changed, 40 insertions, 33 deletions
diff --git a/main/api/src/mill/api/IO.scala b/main/api/src/mill/api/IO.scala
index 8fa5003d..135a26b0 100644
--- a/main/api/src/mill/api/IO.scala
+++ b/main/api/src/mill/api/IO.scala
@@ -6,22 +6,7 @@ import java.io.{InputStream, OutputStream}
* Misc IO utilities, eventually probably should be pushed upstream into
* ammonite-ops
*/
-object IO {
-
- /**
- * Pump the data from the `src` stream into the `dest` stream.
- */
- def stream(src: InputStream, dest: OutputStream): Unit = {
- val buffer = new Array[Byte](4096)
- while ({
- src.read(buffer) match {
- case -1 => false
- case n =>
- dest.write(buffer, 0, n)
- true
- }
- }) ()
- }
+object IO extends StreamSupport {
/**
* Unpacks the given `src` path into the context specific destination directory.
@@ -52,19 +37,3 @@ object IO {
PathRef(ctx.dest / dest)
}
}
-
-import java.io.ByteArrayInputStream
-
-/**
- * A dummy input stream containing an empty byte array.
- */
-object DummyInputStream extends ByteArrayInputStream(Array())
-
-/**
- * A dummy output stream that does nothing with what it consumes (think of it as `/dev/null`).
- */
-object DummyOutputStream extends java.io.OutputStream {
- override def write(b: Int): Unit = ()
- override def write(b: Array[Byte]): Unit = ()
- override def write(b: Array[Byte], off: Int, len: Int): Unit = ()
-}
diff --git a/main/api/src/mill/api/PathRef.scala b/main/api/src/mill/api/PathRef.scala
index 29b2ee3c..f2312ba8 100644
--- a/main/api/src/mill/api/PathRef.scala
+++ b/main/api/src/mill/api/PathRef.scala
@@ -38,7 +38,7 @@ object PathRef {
digest.update(value.toByte)
} else if (jnio.Files.isReadable(path.toNIO)) {
val is = os.read.inputStream(path)
- IO.stream(is, digestOut)
+ StreamSupport.stream(is, digestOut)
is.close()
}
}
diff --git a/main/api/src/mill/api/StreamSupport.scala b/main/api/src/mill/api/StreamSupport.scala
new file mode 100644
index 00000000..82c845a2
--- /dev/null
+++ b/main/api/src/mill/api/StreamSupport.scala
@@ -0,0 +1,38 @@
+package mill.api
+
+import java.io.{ByteArrayInputStream, InputStream, OutputStream}
+
+/**
+ * A dummy input stream containing an empty byte array.
+ */
+object DummyInputStream extends ByteArrayInputStream(Array())
+
+/**
+ * A dummy output stream that does nothing with what it consumes (think of it as `/dev/null`).
+ */
+object DummyOutputStream extends OutputStream {
+ override def write(b: Int): Unit = ()
+ override def write(b: Array[Byte]): Unit = ()
+ override def write(b: Array[Byte], off: Int, len: Int): Unit = ()
+}
+
+trait StreamSupport {
+
+ /**
+ * Pump the data from the `src` stream into the `dest` stream.
+ */
+ def stream(src: InputStream, dest: OutputStream): Unit = {
+ val buffer = new Array[Byte](4096)
+ while ({
+ src.read(buffer) match {
+ case -1 => false
+ case n =>
+ dest.write(buffer, 0, n)
+ true
+ }
+ }) ()
+ }
+
+}
+
+private[api] object StreamSupport extends StreamSupport \ No newline at end of file