Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazySegmentBytes fix: always read bytes at the offset #2063

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ class GeoTiffReaderSpec extends FunSpec

gt3.tags.headTags.get(Tags.TIFFTAG_DATETIME) should be (Some("1988:02:18 13:59:59"))
}

it("must read tiny tiles") {
val extent = Extent(0,0,100,100)
val expected = IntArrayTile(Array(145), 1, 1)
GeoTiff(expected, extent, LatLng).write(path)
addToPurge(path)
val actual = SinglebandGeoTiff(path).tile
assertEqual(actual, expected)
}
}

describe("handling special CRS cases") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LazySegmentBytes(
val chunkEndOffset = segments.maxBy(_.endOffset).endOffset
byteReader.position(chunkStartOffset)
logger.debug(s"Fetching segments ${segments.map(_.id).mkString(", ")} at [$chunkStartOffset, $chunkEndOffset]")
val chunkBytes = byteReader.getSignedByteArray(chunkStartOffset, chunkEndOffset - chunkStartOffset + 1)
val chunkBytes = getBytes(chunkStartOffset, chunkEndOffset - chunkStartOffset + 1)
for { segment <- segments } yield {
val segmentStart = (segment.startOffset - chunkStartOffset).toInt
val segmentEnd = (segment.endOffset - chunkStartOffset).toInt
Expand All @@ -88,7 +88,7 @@ class LazySegmentBytes(
val startOffset = segmentOffsets(i)
val endOffset = segmentOffsets(i) + segmentByteCounts(i) - 1
logger.debug(s"Fetching segment $i at [$startOffset, $endOffset]")
byteReader.getSignedByteArray(startOffset, segmentByteCounts(i))
getBytes(startOffset, segmentByteCounts(i))
}

def getSegments(indices: Traversable[Int]): Iterator[(Int, Array[Byte])] = {
Expand All @@ -97,6 +97,11 @@ class LazySegmentBytes(
.flatMap( chunk => readChunk(chunk))
}

private def getBytes(offset: Long, length: Long): Array[Byte] = {
byteReader.position(offset)
byteReader.getBytes(length.toInt)
}

// Must prevent inherited `Seq.toString` from calling `foreach` method
override def toString(): String = s"StreamingSegmentBytes($byteReader, $tiffTags, $maxChunkSize)"
}
Expand All @@ -108,4 +113,4 @@ object LazySegmentBytes {
case class Segment(id: Int, startOffset: Long, endOffset: Long) {
def size: Long = endOffset - startOffset + 1
}
}
}