Beispiel #1
0
  @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);
  }
Beispiel #2
0
  @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);
  }
Beispiel #3
0
  @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);
  }
Beispiel #4
0
  @Before
  public void setUp() throws Exception {
    TestMessageProto.Builder builder = TestMessageProto.newBuilder();
    builder.setName("TestFileUtils");
    builder.setAge(30);
    builder.setAddr(TestFileUtils.class.getName());

    proto = builder.build();

    File testDir = new File(TEST_PATH);
    if (testDir.exists()) {
      testDir.delete();
    }
    testDir.mkdirs();
  }