Mercurial > hg4j
diff src/org/tmatesoft/hg/internal/ManifestEntryBuilder.java @ 618:7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 16 May 2013 19:46:13 +0200 |
parents | dd4f6311af52 |
children |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ManifestEntryBuilder.java Wed May 15 20:10:09 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/ManifestEntryBuilder.java Thu May 16 19:46:13 2013 +0200 @@ -18,7 +18,9 @@ import java.io.ByteArrayOutputStream; +import org.tmatesoft.hg.core.HgIOException; import org.tmatesoft.hg.core.Nodeid; +import org.tmatesoft.hg.internal.DataSerializer.DataSource; /** * Create binary manifest entry ready to write down into 00manifest.i @@ -36,16 +38,20 @@ * @author Artem Tikhomirov * @author TMate Software Ltd. */ -public class ManifestEntryBuilder { - private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); +public class ManifestEntryBuilder implements DataSource { + private final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + private final EncodingHelper encHelper; + public ManifestEntryBuilder(EncodingHelper encodingHelper) { + encHelper = encodingHelper; + } public ManifestEntryBuilder reset() { buffer.reset(); return this; } public ManifestEntryBuilder add(String fname, Nodeid revision) { - byte[] b = fname.getBytes(); + byte[] b = encHelper.toManifest(fname); buffer.write(b, 0, b.length); buffer.write('\0'); b = revision.toString().getBytes(); @@ -58,4 +64,13 @@ return buffer.toByteArray(); } + public void serialize(DataSerializer out) throws HgIOException { + byte[] r = build(); + out.write(r, 0 , r.length); + } + + public int serializeLength() { + return buffer.size(); + } + }