无法找到将文件从HDFS附加到电子邮件MimeBodyPart的方法。 这是我到目前为止的尝试。我试图使用FileDataSource和URLDataSource,但没有运气。
val attachmentPart = new MimeBodyPart()
val filePath = "FILE_PATH"
val fileName = s"FILE_NAME_${date}.html"
val fs = FileSystem.get(sctx.hadoopConfiguration)
val fullURL = fs.getFileStatus(new Path(filePath+fileName)).getPath.toUri.toURL
//val fullFilePath = fs.getFileStatus(new Path(filePath+fileName)).getPath.toString
val source = new URLDataSource(fullURL)
//val source = new FileDataSource(fullFilePath)
attachmentPart.setDataHandler(new DataHandler(source))
attachmentPart.setFileName("file name")
我在URLDataSource的情况下收到以下错误:
Exception in thread "main" java.net.MalformedURLException: unknown protocol: hdfs
答案 0 :(得分:1)
尝试注册hadoop的FsUrlStreamHandlerFactory来处理带有模式hdfs的URL。
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory
import java.net.URL
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory())