【发布时间】:2019-06-12 06:47:58
【问题描述】:
我正在使用https://github.com/allegro/json-avro-converter 将我的 json 消息转换为 avro 文件。调用 convertToAvro 方法后,我得到一个字节数组:byte[] byteArrayJson。然后我使用 Apache 的 commons 库:
FileUtils.writeByteArrayToFile(myFile.avro, byteArrayJson);
文件已创建。当我尝试将其重新转换为 json 时,使用:
java -jar avro-tools-1.8.1.jar tojson myFile.avro > testCheck.json
Exception in thread "main" java.io.IOException: Not a data file.
at
org.apache.avro.file.DataFileStream.initialize(DataFileStream.java:105)
at org.apache.avro.file.DataFileStream.<init>(DataFileStream.java:84)
at org.apache.avro.tool.DataFileReadTool.run(DataFileReadTool.java:71)
at org.apache.avro.tool.Main.run(Main.java:87)
at org.apache.avro.tool.Main.main(Main.java:76)
我创建了一个 Junit 测试并使用 convertToJson 方法(来自上一个链接)并断言字符串,一切正常。但是对于罐子它不起作用。难道我做错了什么?我使用的是 cmd,而不是 powerShell,因为我在 SO 帖子中看到这可以更改编码。我认为问题出在编码上,但我不知道在哪里看。 (我使用 windows 作为操作系统)
【问题讨论】:
-
我不懂 avro,但请检查一下并告诉我您是否遵循相同的步骤? community.hortonworks.com/questions/32034/…
-
我在发布之前查看了这两个链接,我使用的是来自 github 的库,因为它真的很容易玩。您可以很容易地 convertToJson 或 convertToAvro,但唯一的想法是我想将字节数组存储到 avro 文件中。当我存储它并尝试使用 avro-tools 转换它时不起作用。我想我有一些错误的字节,因为它在这里:stackoverflow.com/questions/51148486/…
-
Windows 10 PowerShell 将二进制流转换为 UTF8 流。更改编码会更改魔术字节,这(正确)会导致引发异常。旁注:PowerShell应用程序可以通过使用管道而不是大于这样来强制不更改编码:你可以从powershell java -jar .\avro-tools-1.7.7.jar fromjson -模式文件 .\data.avsc .\data.json | .\data.avro
-
是的,这是我发布的链接的答案。但正如我在帖子中提到的,我使用的是 cmd,所以不应该发生任何变化。但是我认为创建文件时出了点问题,但是 IDK 什么
标签: java spring-boot gradle avro avro-tools