throw new IllegalArgumentException();
}
}
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());
}
int rv = buffer.remaining();
buffer.position(buffer.limit()); // pretend we've consumed the data
return rv;
} catch (HgIOException ex) {
failure[0] = ex;
IOException e = new IOException();
ex.initCause(ex); // XXX Java 1.5
throw e;
}
}
});
} catch (HgInvalidFileException ex) {
if (failure[0] != null) {
throw failure[0];
}
throw new HgIOException("Write failure", ex, new File(file.getRepo().getWorkingDir(), file.getPath().toString()));
} catch (CancelledException ex) {
throw new HgInvalidStateException("Our channel doesn't cancel here");
}
}