View Javadoc
1   package ca.uhn.hl7v2.hoh.util;
2   
3   public class ByteUtils {
4   
5   	// non instantiable
6   	private ByteUtils() {}
7   	
8   	/**
9   	 * Formats a byte array for logging
10  	 */
11  	public static String formatBytesForLogging(int numBytes, int theOffset, byte... theBytes) {
12  		StringBuilder b = new StringBuilder();
13  		int end = numBytes + theOffset;
14  		for (int i = theOffset; i < end; i++) {
15  			byte nextByte = theBytes[i];
16  			if (nextByte < ' ' || nextByte > 126) {
17  				b.append('[');
18  				b.append(nextByte);
19  				b.append(']');
20  			} else {
21  				b.append((char) nextByte);
22  			}
23  		}
24  
25  		return (b.toString());
26  	}
27  	
28  }