List of usage examples for org.apache.commons.io HexDump dump
public static void dump(byte[] data, long offset, OutputStream stream, int index) throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException
From source file:net.pot8os.heartbleedchecker.HexUtil.java
public static void dump(byte[] input) throws IOException { HexDump.dump(input, 0, System.out, 0); }
From source file:de.griffel.confluence.plugins.plantuml.HexDumpTest.java
@Test public void testHexDump() throws Exception { final String foo = "@plantuml\nclass Test\n\n"; byte[] bytes = foo.getBytes("UTF-8"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); HexDump.dump(bytes, 0, baos, 0); final String expected = new StringBuilder() .append("00000000 40 70 6C 61 6E 74 75 6D 6C 0A 63 6C 61 73 73 20 @plantuml.class ").append(EOL) .append("00000010 54 65 73 74 0A 0A Test..").append(EOL).toString(); assertEquals(expected, baos.toString("UTF-8")); }
From source file:com.googlecode.mp4parser.boxes.microsoft.XtraBox.java
private static void dumpByteBuffer(ByteBuffer input) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, IOException { input = input.slice();/* www . j a va2 s . c om*/ byte bytes[] = new byte[input.remaining()]; input.get(bytes); HexDump.dump(bytes, 0, System.out, 0); }
From source file:com.thelastcheck.commons.buffer.ByteArrayDumpFormatter.java
/** * Will print a hexdump output of a byte array to defined output stream. If * the stream parameter is null, then the output will be to the log. * /*from w w w .j a va 2 s . c o m*/ * @param title * @param byteArray * @param out */ private static void dumpByteArray(String title, byte[] byteArray, OutputStream out) { int estimatedSizeOfHexdump = byteArray.length * 75; ByteArrayOutputStream dumpOut = new ByteArrayOutputStream(estimatedSizeOfHexdump); try { HexDump.dump(byteArray, 0, dumpOut, 0); if (out == null) { logDump.debug(title + NEWLINE + dumpOut.toString()); } else { out.write(new Date().toString().getBytes()); out.write((byte) NEWLINE); out.write(title.getBytes()); out.write((byte) NEWLINE); out.write(dumpOut.toByteArray()); out.write((byte) NEWLINE); } } catch (ArrayIndexOutOfBoundsException e) { logDump.error("ArrayIndexOutOfBoundsException", e); } catch (IllegalArgumentException e) { logDump.error("IllegalArgumentException", e); } catch (IOException e) { logDump.error("IOException", e); } }
From source file:com.yahoo.pulsar.client.cli.CmdConsume.java
/** * Interprets the message to create a string representation * * @param message// ww w. j av a2 s . co m * The message to interpret * @param displayHex * Whether to display BytesMessages in hexdump style, ignored for simple text messages * @return String representation of the message */ private String interpretMessage(Message message, boolean displayHex) throws IOException { byte[] msgData = message.getData(); ByteArrayOutputStream out = new ByteArrayOutputStream(); if (!displayHex) { return new String(msgData); } else { HexDump.dump(msgData, 0, out, 0); return new String(out.toByteArray()); } }
From source file:com.kixeye.chassis.scala.transport.serde.ScalaCaseClassTest.java
private static void dumpToLog(MessageSerDe serDe, byte[] data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HexDump.dump(data, 0, baos, 0); logger.info("Serialized object using [{}] to: \n{}", serDe.getMessageFormatName(), baos.toString(Charsets.UTF_8.name()).trim()); }
From source file:info.fetter.logstashforwarder.protocol.LumberjackClient.java
public int sendCompressedFrame(List<Map<String, byte[]>> keyValuesList) throws IOException { output.writeByte(PROTOCOL_VERSION);// w ww .j a v a2 s. c o m output.writeByte(FRAME_COMPRESSED); ByteArrayOutputStream uncompressedBytes = new ByteArrayOutputStream(); DataOutputStream uncompressedOutput = new DataOutputStream(uncompressedBytes); for (Map<String, byte[]> keyValues : keyValuesList) { logger.trace("Adding data frame"); sendDataFrame(uncompressedOutput, keyValues); } uncompressedOutput.close(); Deflater compressor = new Deflater(); byte[] uncompressedData = uncompressedBytes.toByteArray(); if (logger.isDebugEnabled()) { logger.debug("Deflating data : " + uncompressedData.length + " bytes"); } if (logger.isTraceEnabled()) { HexDump.dump(uncompressedData, 0, System.out, 0); } compressor.setInput(uncompressedData); compressor.finish(); ByteArrayOutputStream compressedBytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buffer); compressedBytes.write(buffer, 0, count); } compressedBytes.close(); byte[] compressedData = compressedBytes.toByteArray(); if (logger.isDebugEnabled()) { logger.debug("Deflated data : " + compressor.getTotalOut() + " bytes"); } if (logger.isTraceEnabled()) { HexDump.dump(compressedData, 0, System.out, 0); } output.writeInt(compressor.getTotalOut()); output.write(compressedData); output.flush(); if (logger.isDebugEnabled()) { logger.debug("Sending compressed frame : " + keyValuesList.size() + " frames"); } return 6 + compressor.getTotalOut(); }
From source file:com.comphenix.protocol.PacketLogging.java
private static String hexDump(byte[] bytes) throws IOException { try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { HexDump.dump(bytes, 0, output, 0); return new String(output.toByteArray(), Charsets.UTF_8); }/* w ww . j ava2 s . c o m*/ }
From source file:com.antsdb.saltedfish.util.UberUtil.java
public static String hexDump(byte[] bytes) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try {/*from www . j a v a 2 s . com*/ HexDump.dump(bytes, 0, buf, 0); return buf.toString(); } catch (Exception x) { } return ""; }
From source file:com.kixeye.chassis.transport.serde.SerDeTest.java
private static void dumpBytes(byte[] bytes) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HexDump.dump(bytes, 0, baos, 0); logger.info("Serialized object to: \n{}", baos.toString(Charsets.UTF_8.name()).trim()); }