You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/01/04 21:59:15 UTC

[GitHub] ankuriitg commented on a change in pull request #23453: [SPARK-26089][CORE] Handle corruption in large shuffle blocks

ankuriitg commented on a change in pull request #23453: [SPARK-26089][CORE] Handle corruption in large shuffle blocks
URL: https://github.com/apache/spark/pull/23453#discussion_r245432380
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/util/Utils.scala
 ##########
 @@ -332,6 +332,41 @@ private[spark] object Utils extends Logging {
     }
   }
 
+  /**
+   * Copy all data from an InputStream to an OutputStream upto maxSize and
+   * closes the input stream if closeStreams is true and all data is read.
+   */
+  def copyStreamUpto(
+      in: InputStream,
+      out: OutputStream,
+      maxSize: Long,
+      closeStreams: Boolean = false): Boolean = {
+    var count = 0L
+    tryWithSafeFinally {
+      val bufSize = 8192
+      val buf = new Array[Byte](bufSize)
+      var n = 0
+      while (n != -1 && count < maxSize) {
+        n = in.read(buf, 0, Math.min(maxSize - count, bufSize.toLong).toInt)
+        if (n != -1) {
+          out.write(buf, 0, n)
+          count += n
+        }
+      }
+      count < maxSize
+    } {
+      if (closeStreams) {
+        try {
+          if (count < maxSize) {
+            in.close()
 
 Review comment:
   Right, I left that edge case, as it will be handled by the concatenated stream later

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org