Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 解压缩Azure ADLS Gen2中存储的.Z文件_Scala_Azure_Compression - Fatal编程技术网

Scala 解压缩Azure ADLS Gen2中存储的.Z文件

Scala 解压缩Azure ADLS Gen2中存储的.Z文件,scala,azure,compression,Scala,Azure,Compression,我有一个.Z文件存储在Azure ADLS Gen2中。我想在ADL中解压文件,我尝试使用ADF和C解压,但发现不支持.Z。我还尝试使用apachecommoncompresslib进行解压缩,但无法读取InputStream中的文件 有人知道如何在Scala中使用ApacheLib解压文件吗?.Z文件是.gzip文件,因此您可以尝试这种方法 import java.io.{BufferedReader, File, FileInputStream, InputStreamReader} imp

我有一个.Z文件存储在Azure ADLS Gen2中。我想在ADL中解压文件,我尝试使用ADF和C解压,但发现不支持.Z。我还尝试使用apachecommoncompresslib进行解压缩,但无法读取InputStream中的文件


有人知道如何在Scala中使用ApacheLib解压文件吗?

.Z
文件是
.gzip
文件,因此您可以尝试这种方法

import java.io.{BufferedReader, File, FileInputStream, InputStreamReader}
import java.util.zip.GZIPInputStream
object UnzipFiles {

  def decompressGzipOrZFiles(file: File, encode: String): BufferedReader = {
    val fis = new FileInputStream(file)
    val gzis = new GZIPInputStream(fis)
    val isr = new InputStreamReader(gzis, encode)
    new BufferedReader(isr)
  }

  def main(args: Array[String]): Unit = {
    val path = new File("/home/cloudera/files/my_file.Z")
    // print to the console
    decompressGzipOrZFiles(path,"UTF-8").lines().toArray.foreach(println)
  }
}
或者你也可以跟着这个

    def uncompressGzip(myFileDotZorGzip: String): Unit = {
      import java.io.FileInputStream
      import java.util.zip.GZIPInputStream
      try {
        val gzipInputStream = new GZIPInputStream(new FileInputStream(myFileDotZorGzip))
        try {
          val tam = 128
          val buffer = new Array[Byte](tam)
          do {
            gzipInputStream.read(buffer)
            gzipInputStream.skip(tam)
            //do something with data
            print(buffer.foreach(b => print(b.toChar)))
          } while(gzipInputStream.read() != -1)
        } finally {
          if (gzipInputStream != null) gzipInputStream.close()
        }
      }
    }
我希望这有帮助