Mercurial > jhg
comparison src/org/tmatesoft/hg/core/CatCommand.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 | 7ec89d637f50 |
| children | b1d6208fb517 |
comparison
equal
deleted
inserted
replaced
| 114:46291ec605a0 | 115:c0cc2535462c |
|---|---|
| 18 | 18 |
| 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
| 20 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
| 21 | 21 |
| 22 import java.io.FileNotFoundException; | 22 import java.io.FileNotFoundException; |
| 23 import java.io.IOException; | |
| 24 import java.io.OutputStream; | |
| 25 | 23 |
| 26 import org.tmatesoft.hg.repo.HgDataFile; | 24 import org.tmatesoft.hg.repo.HgDataFile; |
| 27 import org.tmatesoft.hg.repo.HgRepository; | 25 import org.tmatesoft.hg.repo.HgRepository; |
| 26 import org.tmatesoft.hg.util.ByteChannel; | |
| 28 | 27 |
| 29 /** | 28 /** |
| 30 * Command to obtain content of a | 29 * Command to obtain content of a |
| 31 * | 30 * |
| 32 * @author Artem Tikhomirov | 31 * @author Artem Tikhomirov |
| 59 revision = nodeid; | 58 revision = nodeid; |
| 60 localRevision = BAD_REVISION; | 59 localRevision = BAD_REVISION; |
| 61 return this; | 60 return this; |
| 62 } | 61 } |
| 63 | 62 |
| 64 public void execute(OutputStream os) throws IOException /*TODO own exception type*/ { | 63 public void execute(ByteChannel sink) throws Exception /*TODO own exception type*/ { |
| 65 if (localRevision == BAD_REVISION && revision == null) { | 64 if (localRevision == BAD_REVISION && revision == null) { |
| 66 throw new IllegalArgumentException("Either local file revision number or nodeid shall be specified"); | 65 throw new IllegalArgumentException("Either local file revision number or nodeid shall be specified"); |
| 67 } | 66 } |
| 68 if (file == null) { | 67 if (file == null) { |
| 69 throw new IllegalArgumentException("Name of the file is missing"); | 68 throw new IllegalArgumentException("Name of the file is missing"); |
| 70 } | 69 } |
| 71 if (os == null) { | 70 if (sink == null) { |
| 72 throw new IllegalArgumentException(); | 71 throw new IllegalArgumentException(); |
| 73 } | 72 } |
| 74 HgDataFile dataFile = repo.getFileNode(file); | 73 HgDataFile dataFile = repo.getFileNode(file); |
| 75 if (!dataFile.exists()) { | 74 if (!dataFile.exists()) { |
| 76 throw new FileNotFoundException(); | 75 throw new FileNotFoundException(); |
| 77 } | 76 } |
| 78 byte[] content; | 77 int revToExtract; |
| 79 if (revision != null) { | 78 if (revision != null) { |
| 80 content = dataFile.content(revision); | 79 revToExtract = dataFile.getLocalRevision(revision); |
| 81 } else { | 80 } else { |
| 82 content = dataFile.content(localRevision); | 81 revToExtract = localRevision; |
| 83 } | 82 } |
| 84 os.write(content); | 83 dataFile.content(revToExtract, sink); |
| 85 } | 84 } |
| 86 } | 85 } |
