Mercurial > jhg
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ByteVector.java Mon Oct 07 01:56:05 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/ByteVector.java Fri Oct 11 21:35:41 2013 +0200 @@ -19,7 +19,7 @@ import java.io.ByteArrayOutputStream; /** - * Alternative to {@link ByteArrayOutputStream}, with extra operation that prevent extra byte[] instances + * Alternative to {@link ByteArrayOutputStream}, with extra operation that prevent superfluous byte[] instances * * @author Artem Tikhomirov * @author TMate Software Ltd. @@ -44,6 +44,26 @@ data[count++] = (byte) b; } + public int indexOf(int b) { + for (int i = 0; i < count; i++) { + if (data[i] == b) { + return i; + } + } + return -1; + } + + public byte get(int i) { + if (i < 0 || i >= count) { + throw new IllegalArgumentException(String.valueOf(i)); + } + return data[i]; + } + + public boolean isEmpty() { + return count == 0; + } + public int size() { return count; } @@ -80,4 +100,16 @@ copyTo(rv); return rv; } + + public byte[] toByteArray(int from, int to) { + if (from > to) { + throw new IllegalArgumentException(); + } + if (to > count) { + throw new IllegalArgumentException(); + } + byte[] rv = new byte[to-from]; + System.arraycopy(data, from, rv, 0, rv.length); + return rv; + } }