Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ByteVector.java @ 711:a62079bc422b
Keyword filtering that doesn't depend on input buffer size and the way input lines got split between filter() calls. KewordFilter got state to keep processed suspicious ...$ lines
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 11 Oct 2013 21:35:41 +0200 |
parents | 88afffd39899 |
children |
comparison
equal
deleted
inserted
replaced
710:cf200271439a | 711:a62079bc422b |
---|---|
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 /** | 21 /** |
22 * Alternative to {@link ByteArrayOutputStream}, with extra operation that prevent extra byte[] instances | 22 * Alternative to {@link ByteArrayOutputStream}, with extra operation that prevent superfluous byte[] instances |
23 * | 23 * |
24 * @author Artem Tikhomirov | 24 * @author Artem Tikhomirov |
25 * @author TMate Software Ltd. | 25 * @author TMate Software Ltd. |
26 */ | 26 */ |
27 public class ByteVector { | 27 public class ByteVector { |
40 byte[] newData = new byte[count + increment]; | 40 byte[] newData = new byte[count + increment]; |
41 System.arraycopy(data, 0, newData, 0, count); | 41 System.arraycopy(data, 0, newData, 0, count); |
42 data = newData; | 42 data = newData; |
43 } | 43 } |
44 data[count++] = (byte) b; | 44 data[count++] = (byte) b; |
45 } | |
46 | |
47 public int indexOf(int b) { | |
48 for (int i = 0; i < count; i++) { | |
49 if (data[i] == b) { | |
50 return i; | |
51 } | |
52 } | |
53 return -1; | |
54 } | |
55 | |
56 public byte get(int i) { | |
57 if (i < 0 || i >= count) { | |
58 throw new IllegalArgumentException(String.valueOf(i)); | |
59 } | |
60 return data[i]; | |
61 } | |
62 | |
63 public boolean isEmpty() { | |
64 return count == 0; | |
45 } | 65 } |
46 | 66 |
47 public int size() { | 67 public int size() { |
48 return count; | 68 return count; |
49 } | 69 } |
78 public byte[] toByteArray() { | 98 public byte[] toByteArray() { |
79 byte[] rv = new byte[count]; | 99 byte[] rv = new byte[count]; |
80 copyTo(rv); | 100 copyTo(rv); |
81 return rv; | 101 return rv; |
82 } | 102 } |
103 | |
104 public byte[] toByteArray(int from, int to) { | |
105 if (from > to) { | |
106 throw new IllegalArgumentException(); | |
107 } | |
108 if (to > count) { | |
109 throw new IllegalArgumentException(); | |
110 } | |
111 byte[] rv = new byte[to-from]; | |
112 System.arraycopy(data, from, rv, 0, rv.length); | |
113 return rv; | |
114 } | |
83 } | 115 } |