Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ManifestEntryBuilder.java @ 538:dd4f6311af52
Commit: first working version
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 05 Feb 2013 22:30:21 +0100 |
parents | test/org/tmatesoft/hg/tools/ManifestEntryBuilder.java@4b97847d0b2d |
children | 7c0d2ce340b8 |
comparison
equal
deleted
inserted
replaced
537:5a455624be4f | 538:dd4f6311af52 |
---|---|
1 /* | |
2 * Copyright (c) 2012 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.io.ByteArrayOutputStream; | |
20 | |
21 import org.tmatesoft.hg.core.Nodeid; | |
22 | |
23 /** | |
24 * Create binary manifest entry ready to write down into 00manifest.i | |
25 * <p>Usage: | |
26 * <pre> | |
27 * ManifestEntryBuilder mb = new ManifestEntryBuilder(); | |
28 * mb.reset().add("file1", file1.getRevision(r1)); | |
29 * mb.add("file2", file2.getRevision(r2)); | |
30 * byte[] manifestRecordData = mb.build(); | |
31 * byte[] manifestRevlogHeader = buildRevlogHeader(..., sha1(parents, manifestRecordData), manifestRecordData.length); | |
32 * manifestIndexOutputStream.write(manifestRevlogHeader); | |
33 * manifestIndexOutputStream.write(manifestRecordData); | |
34 * </pre> | |
35 * | |
36 * @author Artem Tikhomirov | |
37 * @author TMate Software Ltd. | |
38 */ | |
39 public class ManifestEntryBuilder { | |
40 private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | |
41 | |
42 | |
43 public ManifestEntryBuilder reset() { | |
44 buffer.reset(); | |
45 return this; | |
46 } | |
47 public ManifestEntryBuilder add(String fname, Nodeid revision) { | |
48 byte[] b = fname.getBytes(); | |
49 buffer.write(b, 0, b.length); | |
50 buffer.write('\0'); | |
51 b = revision.toString().getBytes(); | |
52 buffer.write(b, 0, b.length); | |
53 buffer.write('\n'); | |
54 return this; | |
55 } | |
56 | |
57 public byte[] build() { | |
58 return buffer.toByteArray(); | |
59 } | |
60 | |
61 } |