@@ -27,6 +27,8 @@ public Bits(byte[] b) {
2727 */
2828 public boolean getBit (int index ) {
2929 int byteIndex = index / 8 ;
30+ if (byteIndex > bytes .length - 1 )
31+ throw new VendorConsentParseException ("Expected consent string to contain at least " + byteIndex + "bytes, but found only " + bytes .length + " bytes" );
3032 int bitExact = index % 8 ;
3133 byte b = bytes [byteIndex ];
3234 return (b & bytePows [bitExact ]) != 0 ;
@@ -61,7 +63,7 @@ public void unsetBit(int index) {
6163 * the nth to begin interpreting from
6264 * @param size:
6365 * the number of bits to interpret
64- * @return
66+ * @return integer value
6567 * @throws VendorConsentException
6668 * when the bits cannot fit in an int sized field
6769 */
@@ -113,7 +115,7 @@ public void setInt(int startInclusive, int size, int to) throws VendorConsentExc
113115 * @throws VendorConsentException
114116 * when the bits cannot fit in an int sized field
115117 */
116- public long getLong (int startInclusive , int size ) throws VendorConsentException {
118+ private long getLong (int startInclusive , int size ) throws VendorConsentException {
117119 if (size > Long .SIZE ) {
118120 throw new VendorConsentParseException ("can't fit bit range in long: " + size );
119121 }
@@ -142,7 +144,7 @@ public long getLong(int startInclusive, int size) throws VendorConsentException
142144 * @throws VendorConsentException
143145 * when the bits cannot fit into the provided size
144146 */
145- public void setLong (int startInclusive , int size , long to ) throws VendorConsentException {
147+ private void setLong (int startInclusive , int size , long to ) throws VendorConsentException {
146148 if (size > Long .SIZE || to > maxOfSize (size ) || to < 0 ) {
147149 throw new VendorConsentCreateException ("can't fit long into bit range of size " + size );
148150 }
@@ -158,7 +160,7 @@ public void setLong(int startInclusive, int size, long to) throws VendorConsentE
158160 * the bit from which to begin interpreting
159161 * @param size:
160162 * the number of bits to interpret
161- * @return
163+ * @return instant value
162164 * @throws VendorConsentException
163165 * when the number of bits requested cannot fit in a long
164166 */
@@ -172,14 +174,6 @@ public void setInstantToEpochDeciseconds(int startInclusive, int size, Instant i
172174 setLong (startInclusive , size , instant .toEpochMilli () / 100 );
173175 }
174176
175- /**
176- * @return the number of bits in the bit string
177- *
178- */
179- public int length () {
180- return bytes .length * 8 ;
181- }
182-
183177 /**
184178 * This method interprets the given interval in the bit string as a series of six bit characters, where 0=A and 26=Z
185179 *
@@ -229,24 +223,6 @@ public void setSixBitString(int startInclusive, int size, String to) throws Vend
229223 }
230224 }
231225
232- /**
233- *
234- * @return a string representation of the byte array passed in the constructor. for example, a bit array of [4]
235- * yields a String of "0100"
236- */
237- public String getBinaryString () {
238- StringBuilder s = new StringBuilder ();
239- int size = length ();
240- for (int i = 0 ; i < size ; i ++) {
241- if (getBit (i )) {
242- s .append ("1" );
243- } else {
244- s .append ("0" );
245- }
246- }
247- return s .toString ();
248- }
249-
250226 public byte [] toByteArray () {
251227 return bytes ;
252228 }
0 commit comments