- Added HexUtils.toHexString method
- Wrapped output of byte[] objects with a call to HexUtils.toHexString
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@
1049263 13f79535-47bb-0310-9956-
ffa450edef68
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.buf.HexUtils;
/**
* This factory is used to read files and write files by splitting them up into
throw new IllegalArgumentException(
"Can't write message, this factory is reading.");
if (log.isDebugEnabled())
- log.debug("Message " + msg + " data " + msg.getData()
+ log.debug("Message " + msg + " data " + HexUtils.toHexString(msg.getData())
+ " data length " + msg.getDataLength() + " out " + out);
if (msg.getMessageNumber() <= lastMessageProcessed.get()) {
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.CharChunk;
+import org.apache.tomcat.util.buf.HexUtils;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.res.StringManager;
*/
public void dump(String msg) {
if (log.isDebugEnabled()) {
- log.debug(msg + ": " + buf + " " + pos +"/" + (len + 4));
+ log.debug(msg + ": " + HexUtils.toHexString(buf) + " " + pos +"/" + (len + 4));
}
int max = pos;
if (len + 4 > pos)
(byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' };
+ /**
+ * Table for byte to hex string translation.
+ */
+ private static final char[] hex = "0123456789abcdef".toCharArray();
+
// --------------------------------------------------------- Static Methods
public static byte getHex(int index){
return HEX[index];
}
-}
\ No newline at end of file
+
+ public static String toHexString(byte[] bytes)
+ {
+ if(null == bytes) return null;
+
+ StringBuilder sb = new StringBuilder(bytes.length << 1);
+
+ for(int i=0; i<bytes.length; ++i)
+ sb.append(hex[(bytes[i] & 0xf0) >> 4])
+ .append(hex[(bytes[i] & 0x0f)])
+ ;
+
+ return sb.toString();
+ }
+}