public void serialize(final DataSerializer out) throws HgIOException, HgRuntimeException {
final HgIOException failure[] = new HgIOException[1];
try {
// TODO #workingCopy API is very limiting, CancelledException is inconvenient,
// and absence of HgIOException is very uncomfortable
file.workingCopy(new ByteChannel() {
public int write(ByteBuffer buffer) throws IOException {
try {
if (buffer.hasArray()) {
out.write(buffer.array(), buffer.position(), buffer.remaining());