public static void write(Message message, File toFile) {
    OutputStream out = null;
    try {
      out = new BufferedOutputStream(new FileOutputStream(toFile, false));
      message.writeTo(out);
    } catch (Exception e) {
      throw ContextException.of("Unable to write message", e).addContext("file", toFile);
    } finally {
      IOUtils.closeQuietly(out);
    }
  }
@Test
  public void fail_to_write_single_message() {
    assertThatThrownBy(() -> {
      File dir = temp.newFolder();
      Protobuf.write(Fake.getDefaultInstance(), dir);
    }).isInstanceOf(ContextException.class)
      .hasMessageContaining("Unable to write message");
  }