Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
114:46291ec605a0 | 115:c0cc2535462c |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
20 | 20 |
21 import java.nio.ByteBuffer; | |
21 import java.util.ArrayList; | 22 import java.util.ArrayList; |
22 import java.util.Collection; | 23 import java.util.Collection; |
23 import java.util.TreeMap; | 24 import java.util.TreeMap; |
24 | 25 |
25 import org.tmatesoft.hg.core.Nodeid; | 26 import org.tmatesoft.hg.core.Nodeid; |
26 import org.tmatesoft.hg.core.Path; | 27 import org.tmatesoft.hg.core.Path; |
27 import org.tmatesoft.hg.internal.RevlogStream; | 28 import org.tmatesoft.hg.internal.RevlogStream; |
29 import org.tmatesoft.hg.util.ByteChannel; | |
28 | 30 |
29 | 31 |
30 | 32 |
31 /** | 33 /** |
32 * ? name:HgFileNode? | 34 * ? name:HgFileNode? |
40 // slashes, unix-style? | 42 // slashes, unix-style? |
41 // repo location agnostic, just to give info to user, not to access real storage | 43 // repo location agnostic, just to give info to user, not to access real storage |
42 private final Path path; | 44 private final Path path; |
43 private Metadata metadata; | 45 private Metadata metadata; |
44 | 46 |
45 /*package-local*/HgDataFile(HgRepository hgRepo, Path path, RevlogStream content) { | 47 /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath, RevlogStream content) { |
46 super(hgRepo, content); | 48 super(hgRepo, content); |
47 this.path = path; | 49 path = filePath; |
48 } | 50 } |
49 | 51 |
52 /*package-local*/HgDataFile(HgRepository hgRepo, Path filePath) { | |
53 super(hgRepo); | |
54 path = filePath; | |
55 } | |
56 | |
57 // exists is not the best name possible. now it means no file with such name was ever known to the repo. | |
58 // it might be confused with files existed before but lately removed. | |
50 public boolean exists() { | 59 public boolean exists() { |
51 return content != null; // XXX need better impl | 60 return content != null; // XXX need better impl |
52 } | 61 } |
53 | 62 |
54 // human-readable (i.e. "COPYING", not "store/data/_c_o_p_y_i_n_g.i") | 63 // human-readable (i.e. "COPYING", not "store/data/_c_o_p_y_i_n_g.i") |
60 return content.dataLength(getLocalRevision(nodeid)); | 69 return content.dataLength(getLocalRevision(nodeid)); |
61 } | 70 } |
62 | 71 |
63 public byte[] content() { | 72 public byte[] content() { |
64 return content(TIP); | 73 return content(TIP); |
74 } | |
75 | |
76 public void content(int revision, ByteChannel sink) throws /*TODO typed*/Exception { | |
77 byte[] content = content(revision); | |
78 ByteBuffer buf = ByteBuffer.allocate(512); | |
79 int left = content.length; | |
80 int offset = 0; | |
81 do { | |
82 buf.put(content, offset, Math.min(left, buf.remaining())); | |
83 buf.flip(); | |
84 int consumed = sink.write(buf); | |
85 buf.compact(); | |
86 offset += consumed; | |
87 left -= consumed; | |
88 } while (left > 0); | |
65 } | 89 } |
66 | 90 |
67 // for data files need to check heading of the file content for possible metadata | 91 // for data files need to check heading of the file content for possible metadata |
68 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8- | 92 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8- |
69 @Override | 93 @Override |