Mercurial > jhg
diff src/org/tmatesoft/hg/repo/HgDataFile.java @ 115:c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 03 Feb 2011 23:32:08 +0100 |
parents | a3a2e5deb320 |
children | b1d6208fb517 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgDataFile.java Thu Feb 03 22:13:55 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Thu Feb 03 23:32:08 2011 +0100 @@ -18,6 +18,7 @@ import static org.tmatesoft.hg.repo.HgRepository.TIP; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.TreeMap; @@ -25,6 +26,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.internal.RevlogStream; +import org.tmatesoft.hg.util.ByteChannel; @@ -42,11 +44,18 @@ private final Path path; private Metadata metadata; - /*package-local*/HgDataFile(HgRepository hgRepo, Path path, RevlogStream content) { + /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath, RevlogStream content) { super(hgRepo, content); - this.path = path; + path = filePath; } - + + /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath) { + super(hgRepo); + path = filePath; + } + + // exists is not the best name possible. now it means no file with such name was ever known to the repo. + // it might be confused with files existed before but lately removed. public boolean exists() { return content != null; // XXX need better impl } @@ -63,6 +72,21 @@ public byte[] content() { return content(TIP); } + + public void content(int revision, ByteChannel sink) throws /*TODO typed*/Exception { + byte[] content = content(revision); + ByteBuffer buf = ByteBuffer.allocate(512); + int left = content.length; + int offset = 0; + do { + buf.put(content, offset, Math.min(left, buf.remaining())); + buf.flip(); + int consumed = sink.write(buf); + buf.compact(); + offset += consumed; + left -= consumed; + } while (left > 0); + } // for data files need to check heading of the file content for possible metadata // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8-