01: package com.etymon.pj.util;
02:
03: public class ByteString {
04:
05: public static int lastIndexOf(byte[] buffer, String str) {
06: // for now, brute force
07: if (str.length() == 0) {
08: return buffer.length;
09: }
10: int length = str.length();
11: int x, y;
12: boolean match;
13: for (x = (buffer.length - length); x >= 0; x--) {
14: match = true;
15: for (y = 0; y < length; y++) {
16: if ((char) (buffer[x + y]) != str.charAt(y)) {
17: match = false;
18: break;
19: }
20: }
21: if (match) {
22: return x;
23: }
24: }
25: return -1;
26: }
27:
28: }
|