@@ -57,9 +57,7 @@ class GCSInputFile private (
5757 val ranges = copyRanges.asScala.map { r =>
5858 IntRangeWithOffset (r.getInputOffset, r.getLength, r.getOutputOffset)
5959 }.toSeq
60- require(
61- PerfIO .readToHostMemory(hadoopConf, output, fileUri, ranges).isDefined,
62- " expected to use PerfIO to read" )
60+ readWithPerfIO(output, ranges)
6361 }
6462
6563 /**
@@ -69,16 +67,18 @@ class GCSInputFile private (
6967 */
7068 @ throws[IOException ]
7169 override def readTail (length : Long , output : HostMemoryBuffer ): Unit = {
72- if (length == 0 ) {
73- return
70+ require(length >= 0 , s " length must be non-negative, actual: $length" )
71+ if (length > 0 ) {
72+ val ranges = Seq [RangeWithOffset ](SuffixRangeWithOffset (length, /* destOffset*/ 0L ))
73+ readWithPerfIO(output, ranges)
7474 }
75- if (length < 0 ) {
76- throw new IllegalArgumentException (" length must be non-negative" )
75+ }
76+
77+ @ throws[IOException ]
78+ private def readWithPerfIO (output : HostMemoryBuffer , ranges : Seq [RangeWithOffset ]): Unit = {
79+ if (PerfIO .readToHostMemory(hadoopConf, output, fileUri, ranges).isEmpty) {
80+ throw new IOException (s " expected PerfIO to read GCS file ${fileUri.toString}" )
7781 }
78- val ranges = Seq [RangeWithOffset ](SuffixRangeWithOffset (length, /* destOffset*/ 0L ))
79- require(
80- PerfIO .readToHostMemory(hadoopConf, output, fileUri, ranges).isDefined,
81- " expected to use PerfIO to read" )
8282 }
8383}
8484
0 commit comments