Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
617:65c01508f002 | 618:7c0d2ce340b8 |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.io.ByteArrayOutputStream; | 19 import java.io.ByteArrayOutputStream; |
20 | 20 |
21 import org.tmatesoft.hg.core.HgIOException; | |
21 import org.tmatesoft.hg.core.Nodeid; | 22 import org.tmatesoft.hg.core.Nodeid; |
23 import org.tmatesoft.hg.internal.DataSerializer.DataSource; | |
22 | 24 |
23 /** | 25 /** |
24 * Create binary manifest entry ready to write down into 00manifest.i | 26 * Create binary manifest entry ready to write down into 00manifest.i |
25 * <p>Usage: | 27 * <p>Usage: |
26 * <pre> | 28 * <pre> |
34 * </pre> | 36 * </pre> |
35 * | 37 * |
36 * @author Artem Tikhomirov | 38 * @author Artem Tikhomirov |
37 * @author TMate Software Ltd. | 39 * @author TMate Software Ltd. |
38 */ | 40 */ |
39 public class ManifestEntryBuilder { | 41 public class ManifestEntryBuilder implements DataSource { |
40 private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | 42 private final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
43 private final EncodingHelper encHelper; | |
41 | 44 |
45 public ManifestEntryBuilder(EncodingHelper encodingHelper) { | |
46 encHelper = encodingHelper; | |
47 } | |
42 | 48 |
43 public ManifestEntryBuilder reset() { | 49 public ManifestEntryBuilder reset() { |
44 buffer.reset(); | 50 buffer.reset(); |
45 return this; | 51 return this; |
46 } | 52 } |
47 public ManifestEntryBuilder add(String fname, Nodeid revision) { | 53 public ManifestEntryBuilder add(String fname, Nodeid revision) { |
48 byte[] b = fname.getBytes(); | 54 byte[] b = encHelper.toManifest(fname); |
49 buffer.write(b, 0, b.length); | 55 buffer.write(b, 0, b.length); |
50 buffer.write('\0'); | 56 buffer.write('\0'); |
51 b = revision.toString().getBytes(); | 57 b = revision.toString().getBytes(); |
52 buffer.write(b, 0, b.length); | 58 buffer.write(b, 0, b.length); |
53 buffer.write('\n'); | 59 buffer.write('\n'); |
56 | 62 |
57 public byte[] build() { | 63 public byte[] build() { |
58 return buffer.toByteArray(); | 64 return buffer.toByteArray(); |
59 } | 65 } |
60 | 66 |
67 public void serialize(DataSerializer out) throws HgIOException { | |
68 byte[] r = build(); | |
69 out.write(r, 0 , r.length); | |
70 } | |
71 | |
72 public int serializeLength() { | |
73 return buffer.size(); | |
74 } | |
75 | |
61 } | 76 } |