@@ -11,35 +11,33 @@ import com.google.cloud.storage.BlobId
1111import java .io .ByteArrayInputStream
1212import java .nio .channels .Channels
1313import com .google .cloud .storage .BlobInfo
14+ import java .io .FileInputStream
15+ import java .io .File
16+ import java .io .FileOutputStream
1417
1518
1619object FileUtils {
1720 val storage = StorageOptions .getDefaultInstance().getService()
1821
1922 def getInputStream (stringPath : String ): InputStream = {
2023 val isGS = stringPath.size > 5 && stringPath.indexOf(" gs://" ) == 0
21- if (isGS) {
22- val content = storage.readAllBytes(getBlobIdFromPath(stringPath))
23- new ByteArrayInputStream (content)
24- } else {
25- val path = Paths .get(URI .create(stringPath))
26- Files .newInputStream(path)
27- }
24+ if (isGS)
25+ new ByteArrayInputStream (storage.readAllBytes(getBlobIdFromPath(stringPath)))
26+ else
27+ new FileInputStream (new File (stringPath))
2828 }
2929
3030 def getOutputStream (stringPath : String ): OutputStream = {
3131 val isGS = stringPath.size > 5 && stringPath.indexOf(" gs://" ) == 0
3232 if (isGS) {
3333 val blobId = getBlobIdFromPath(stringPath)
34- // val blob = storage.get(blobId)
3534 val blobInfo = BlobInfo .newBuilder(blobId).build()
3635 val blob = storage.create(blobInfo)
3736 Channels .newOutputStream(blob.writer())
3837 } else {
39- val path = Paths .get(URI .create(stringPath))
40- if (! Files .exists(path))
41- Files .createFile(path)
42- Files .newOutputStream(path)
38+ val file = new File (stringPath)
39+ file.createNewFile()
40+ new FileOutputStream (file, false )
4341 }
4442 }
4543
0 commit comments