1 64 65 package com.jcorporate.expresso.core.misc; 66 67 72 73 public class ByteArrayCounter { 74 75 private byte theArray[]; 76 77 103 104 105 111 public ByteArrayCounter(int arraySize) { 112 theArray = new byte[arraySize]; 113 } 114 115 116 121 public byte[] getBytes() { 122 return (new String (theArray)).getBytes(); 123 } 124 125 126 129 public synchronized void increment() { 130 int i; 131 byte carry = 0; 132 for (i = theArray.length - 1; i >= 0; i--) { 133 if (theArray[i] == 127 || (theArray[i] == 126 && carry == 1)) { 135 if (i == 0) { 137 int j; 138 for (j = 0; j < theArray.length; j++) { 139 theArray[j] = 0; 140 } 141 break; 142 } else { 143 carry = 1; 144 theArray[i] = 0; 145 } 146 } else { 147 theArray[i]++; 149 break; 150 } 151 } 152 } 153 154 } 155 | Popular Tags |