@Test public final void testWriteLoadProtoFromStream() throws IOException { FileOutputStream out = new FileOutputStream(new File(TEST_PATH + "/file.bin")); FileUtil.writeProto(out, proto); FileInputStream in = new FileInputStream(new File(TEST_PATH + "/file.bin")); Message defaultInstance = TestMessageProto.getDefaultInstance(); TestMessageProto message = (TestMessageProto) FileUtil.loadProto(in, defaultInstance); assertEquals(proto, message); }
@Test public final void testWriteLoadProtoFromFile() throws IOException { File file = new File(TEST_PATH + "/file.bin"); file.createNewFile(); FileUtil.writeProto(file, proto); Message defaultInstance = TestMessageProto.getDefaultInstance(); TestMessageProto message = (TestMessageProto) FileUtil.loadProto(new File(TEST_PATH + "/file.bin"), defaultInstance); assertEquals(proto, message); }
@Test public final void testWriteLoadProtoFromPath() throws IOException { Path path = new Path(TEST_PATH + "/file.bin"); Configuration conf = new Configuration(); FileUtil.writeProto(conf, path, proto); Message defaultInstance = TestMessageProto.getDefaultInstance(); TestMessageProto message = (TestMessageProto) FileUtil.loadProto(conf, new Path(TEST_PATH + "/file.bin"), defaultInstance); assertEquals(proto, message); }