/** * Returns a string representation of the current buffer. This converts * any internal stored bytes directly to chars and appends them to a String. * @return A byte-to-char string representation of the current buffer. */ @Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < size(); i++) { sb.append((char)getUnchecked(i)); } return sb.toString(); }
/** * Returns a string representation of the current buffer. This converts * any internal stored bytes directly to chars and appends them to a String. * @return A byte-to-char string representation of the current buffer. */ @Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < size(); i++) { sb.append((char)getUnchecked(i)); } return sb.toString(); }
/** * Gets a hash code for this ByteBuffer object based on actual sequence * of bytes stored in this buffer. That means this object is safe to * store in Hashtables or Hashmaps since the same sequence of bytes in * different instances will generate the same hashCode, regardless of * capacity, internal read position, write position, etc. * <br> * This method is implemented using logic from Jakarta Commons Lang * library in the HashCodeBuilder class. * @return A hash code for this ByteBuffer object for the sequence of bytes * stored in this buffer. */ @Override public int hashCode() { // use two hard-coded constant -- any value would do final int hashingConstant = 37; int hashCode = 17 * hashingConstant; int size = size(); // adding entire array of bytes in sequence for (int i = 0; i < size; i++) { hashCode = hashCode * hashingConstant + getUnchecked(i); } return hashCode; }
/** * Gets a hash code for this ByteBuffer object based on actual sequence * of bytes stored in this buffer. That means this object is safe to * store in Hashtables or Hashmaps since the same sequence of bytes in * different instances will generate the same hashCode, regardless of * capacity, internal read position, write position, etc. * <br> * This method is implemented using logic from Jakarta Commons Lang * library in the HashCodeBuilder class. * @return A hash code for this ByteBuffer object for the sequence of bytes * stored in this buffer. */ @Override public int hashCode() { // use two hard-coded constant -- any value would do final int hashingConstant = 37; int hashCode = 17 * hashingConstant; int size = size(); // adding entire array of bytes in sequence for (int i = 0; i < size; i++) { hashCode = hashCode * hashingConstant + getUnchecked(i); } return hashCode; }
/** * Return a hexidecimal String representation of the current buffer with each byte * displayed in a 2 character hexidecimal format. Useful for debugging. * Convert a ByteBuffer to a String with a hexidecimal format. * @param offset * @param length * @return The string in hex representation */ public String toHexString(int offset, int length) { // is offset, length valid for the current size() of our internal byte[] checkOffsetLength(size(), offset, length); // if length is 0, return an empty string if (length == 0 || size() == 0) { return ""; } StringBuilder s = new StringBuilder(length * 2); int end = offset + length; for (int i = offset; i < end; i++) { HexUtil.appendHexString(s, getUnchecked(i)); } return s.toString(); } }
/** * Return a hexidecimal String representation of the current buffer with each byte * displayed in a 2 character hexidecimal format. Useful for debugging. * Convert a ByteBuffer to a String with a hexidecimal format. * @param offset * @param length * @return The string in hex representation */ public String toHexString(int offset, int length) { // is offset, length valid for the current size() of our internal byte[] checkOffsetLength(size(), offset, length); // if length is 0, return an empty string if (length == 0 || size() == 0) { return ""; } StringBuilder s = new StringBuilder(length * 2); int end = offset + length; for (int i = offset; i < end; i++) { HexUtil.appendHexString(s, getUnchecked(i)); } return s.toString(); } }
int j = 0; while (j < bytes.length && getUnchecked(i+j) == bytes[j]) { j++;
int j = 0; while (j < bytes.length && getUnchecked(i+j) == bytes[j]) { j++;