【问题标题】:How to parse octet-stream files using Apache Tika?如何使用 Apache Tika 解析八位字节流文件?
【发布时间】:2015-09-09 18:03:39
【问题描述】:

我在 Azure Blob 存储中存储了所有不同类型的文件,文件有 txt、doc、pdf 等。但是,所有文件都在那里存储为“八位字节流”,当我打开文件以使用 Tika 从中提取文本时,Tika 无法检测到字符编码。我怎样才能解决这个问题?

FileSystem fs = FileSystem.get(new Configuration());            
Path pt = new Path(Configs.BLOBSTORAGEPREFIX+fileAdd);          
InputStream stream = fs.open(pt);           


AutoDetectParser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();   

parser.parse(stream, handler, metadata);       


spaceContentBuffer.append(handler.toString());

【问题讨论】:

    标签: java azure-blob-storage apache-tika


    【解决方案1】:

    如果您直接调用 Azure Storage REST API,您可以通过 API Set Blob Properties 设置标头“x-ms-blob-content-type”。

    如果您使用的是 Azure 存储客户端库,您可以编写如下类似的代码:

    blockBlob.Properties.ContentType = "text/xml";
    blockBlob.SetProperties();
    

    【讨论】:

    • 我正在使用 Azure 存储客户端。我编辑了我的帖子,所以你可以看到我的代码。考虑到我的代码,您能给我提供更多解释吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多