forked from locationtech/geotrellis
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made a few changes to StreamBytes and ByteReader Renamed and a few changes to the files in S3 util
- Loading branch information
Showing
5 changed files
with
146 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
s3/src/main/scala/geotrellis/spark/io/s3/util/S3InputStreamReader.scala
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
s3/src/main/scala/geotrellis/spark/io/s3/util/S3StreamBytes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package geotrellis.spark.io.s3.util | ||
|
||
import geotrellis.util.StreamBytes | ||
import geotrellis.spark.io.s3._ | ||
|
||
import scala.collection.mutable.Queue | ||
import com.amazonaws.services.s3.model._ | ||
|
||
trait S3StreamBytes extends StreamBytes { | ||
def client: AmazonS3Client | ||
def request: GetObjectRequest | ||
|
||
def metadata = | ||
client.getObjectMetadata(request.getBucketName, request.getKey) | ||
|
||
def objectLength = metadata.getContentLength | ||
|
||
def readStream(start: Int, end: Int): S3ObjectInputStream = { | ||
val obj = client.readRange(start, end, request) | ||
obj.getObjectContent | ||
} | ||
} | ||
|
||
|
||
object S3Queue { | ||
private val mapQueue = Queue[Map[Long, Array[Byte]]]() | ||
|
||
def size: Int = mapQueue.length | ||
|
||
def isEmpty: Boolean = mapQueue.isEmpty | ||
|
||
def saveChunk(chunk: Map[Long, Array[Byte]]): Unit = | ||
mapQueue.enqueue(chunk) | ||
|
||
def getChunk: Map[Long, Array[Byte]] = mapQueue.dequeue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package geotrellis.util | ||
|
||
import java.io.InputStream | ||
import java.nio.ByteBuffer | ||
|
||
trait StreamBytes { | ||
private val chunkSize = 256000 | ||
var streamPosition = 0 | ||
|
||
def objectLength: Long | ||
|
||
def readStream(start: Int, end: Int): InputStream | ||
|
||
def pastLength(size: Int): Boolean = | ||
if (size > objectLength) true else false | ||
|
||
def getArray: Array[Byte] = | ||
getArray(streamPosition) | ||
|
||
def getArray(start: Int): Array[Byte] = | ||
getArray(start, chunkSize) | ||
|
||
def getArray(start: Int, length: Int): Array[Byte] = { | ||
val chunk = | ||
if (!pastLength(length + start)) | ||
length | ||
else | ||
(objectLength - start).toInt | ||
|
||
val arr = Array.ofDim[Byte](chunk) | ||
val stream = readStream(start, chunk) | ||
|
||
stream.read(arr, 0, chunk) | ||
streamPosition = start + length | ||
|
||
arr | ||
} | ||
|
||
def getMappedArray: Map[Long, Array[Byte]] = | ||
getMappedArray(streamPosition, chunkSize) | ||
|
||
def getMappedArray(start: Int): Map[Long, Array[Byte]] = | ||
getMappedArray(start, chunkSize) | ||
|
||
def getMappedArray(start: Int, length: Int): Map[Long, Array[Byte]] = | ||
Map(start.toLong -> getArray(start, length)) | ||
} |