本文整理汇总了Java中org.apache.commons.io.HexDump类的典型用法代码示例。如果您正苦于以下问题:Java HexDump类的具体用法?Java HexDump怎么用?Java HexDump使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HexDump类属于org.apache.commons.io包,在下文中一共展示了HexDump类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traceBeforeNegotiate
import org.apache.commons.io.HexDump; //导入依赖的package包/类
private int traceBeforeNegotiate() {
int beforeNumSubjectCreds = 0;
// Traces all credentials too.
if (subject != null) {
log.debug("[" + getName() + "] AUTH_NEGOTIATE as subject " + subject.toString());
beforeNumSubjectCreds = subject.getPrivateCredentials().size();
}
if (negotiationToken != null && negotiationToken.length > 0) {
try {
OutputStream os = new ByteArrayOutputStream();
HexDump.dump(negotiationToken, 0, os, 0);
log.debug("[" + getName() + "] AUTH_NEGOTIATE Process token from acceptor==>\n"
+ os.toString());
} catch (IOException e) {}
}
return beforeNumSubjectCreds;
}
示例2: traceAfterNegotiate
import org.apache.commons.io.HexDump; //导入依赖的package包/类
private void traceAfterNegotiate( int beforeNumSubjectCreds ) {
if (subject != null) {
int afterNumSubjectCreds = subject.getPrivateCredentials().size();
if (afterNumSubjectCreds > beforeNumSubjectCreds) {
log.debug("[" + getName() + "] AUTH_NEGOTIATE have extra credentials.");
// Traces all credentials too.
log.debug("[" + getName() + "] AUTH_NEGOTIATE updated subject=" + subject.toString());
}
}
if (negotiationToken != null && negotiationToken.length > 0) {
try {
OutputStream os = new ByteArrayOutputStream();
HexDump.dump(negotiationToken, 0, os, 0);
log.debug("[" + getName() + "] AUTH_NEGOTIATE Send token to acceptor==>\n"
+ os.toString());
} catch (IOException e) {}
}
}
示例3: unmarshal
import org.apache.commons.io.HexDump; //导入依赖的package包/类
private static <T> T unmarshal(Class<T> clazz, byte[] in) throws IOException {
if (LOGGER.isLoggable(Level.FINEST)) {
System.out.println(clazz.toString() + ";");
HexDump.dump(in, 0, System.out, 0);
}
Codec<T> codec = Codecs.create(clazz);
T gs = null;
byte[] readback = null;
try {
gs = Codecs.decode(codec, in);
} catch (DecodingException ex) {
ex.printStackTrace();
}
//try {
// readback = Codecs.encode(gs, codec);
// HexDump.dump(readback, 0, System.out, 0);
//} catch (Exception ex) {
// ex.printStackTrace();
//}
return gs;
}
示例4: testGetLong
import org.apache.commons.io.HexDump; //导入依赖的package包/类
@Test
public void testGetLong() throws IOException {
byte[] array = new byte[] { (byte)0x91, (byte)0xE9, 0x1D, (byte)0x98, 0x39, 0x01, 0x00, 0x00 };
HexDump.dump(array, 0, System.out, 0);
int offset = 0;
// System.out.println(((long) (array[offset + 7] & 0xff) << 56));
// System.out.println(((long) (array[offset + 6] & 0xff) << 48));
// System.out.println(((long) (array[offset + 5] & 0xff) << 40));
// System.out.println(((long) (array[offset + 4] & 0xff) << 32));
// System.out.println(((long) (array[offset + 3] & 0xff) << 24));
// System.out.println(((long) (array[offset + 2] & 0xff) << 16));
// System.out.println(((long) (array[offset + 1] & 0xff) << 8));
// System.out.println(((long) (array[offset + 0] & 0xff) << 0));
// System.out.println(((long) (array[offset + 5] & 0xff) << 40) |
// ((long) (array[offset + 4] & 0xff) << 32));
// System.out.println(BlockHeader.getLong(array, offset));
assertEquals(1346876860817L, LittleEndian.getLong(array, offset));
}
示例5: printJavaSerializeBinarySize
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static void printJavaSerializeBinarySize(Object target) throws Exception{
try {
byte[] bytes = MinimumMarshaller.marshal(target);
System.out.println(target.getClass().getSimpleName() + " binaly size is " + bytes.length);
ByteArrayOutputStream os = new ByteArrayOutputStream();
HexDump.dump(bytes, 0, os, 0);
System.out.println(os.toString());
Object o = MinimumMarshaller.unmarshal(bytes);
// Verify correct unmarshalling among before and after
if( ! o.equals(target) ) {
throw new RuntimeException("Different! " + target );
}
} finally {
}
}
示例6: testAndPrintHex
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static <T> T testAndPrintHex(T target) throws Exception{
try {
byte[] bytes = MinimumMarshaller.marshal(target);
System.out.println(target.getClass().getSimpleName() + " binary size is " + bytes.length);
ByteArrayOutputStream os = new ByteArrayOutputStream();
HexDump.dump(bytes, 0, os, 0);
System.out.println(os.toString());
System.out.println("");
return (T) MinimumMarshaller.unmarshal(bytes);
} finally {
}
}
示例7: intercept
import org.apache.commons.io.HexDump; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
logger.info("Sending headers: " + request.getHeaders());
if (body.length > 0) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
HexDump.dump(body, 0, baos, 0);
logger.info("Sending to [{}]: \n{}", request.getURI(), baos.toString(Charsets.UTF_8.name()).trim());
} else {
logger.info("Sending empty body to [{}]!", request.getURI());
}
return execution.execute(request, body);
}
示例8: dumpEvent
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static String dumpEvent(Event event, int maxBytes) {
StringBuilder buffer = new StringBuilder();
if (event == null || event.getBody() == null) {
buffer.append("null");
} else if (event.getBody().length == 0) {
// do nothing... in this case, HexDump.dump() will throw an exception
} else {
byte[] body = event.getBody();
byte[] data = Arrays.copyOf(body, Math.min(body.length, maxBytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
HexDump.dump(data, 0, out, 0);
String hexDump = new String(out.toByteArray());
// remove offset since it's not relevant for such a small dataset
if (hexDump.startsWith(HEXDUMP_OFFSET)) {
hexDump = hexDump.substring(HEXDUMP_OFFSET.length());
}
buffer.append(hexDump);
} catch (Exception e) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Exception while dumping event", e);
}
buffer.append("...Exception while dumping: ").append(e.getMessage());
}
String result = buffer.toString();
if (result.endsWith(EOL) && buffer.length() > EOL.length()) {
buffer.delete(buffer.length() - EOL.length(), buffer.length()).toString();
}
}
return "{ headers:" + event.getHeaders() + " body:" + buffer + " }";
}
示例9: dump
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static <T extends TLObject> void dump(T object, byte[] serialized) {
try {
String path = getFilePath(object.getClass());
FileUtils.writeStringToFile(new File(dumpDir + path + ".json"), toJson(object), Charset.forName("UTF-8"));
FileUtils.writeStringToFile(new File(dumpDir + path + ".dump"), StreamUtils.toHexString(serialized), Charset.forName("UTF-8"));
HexDump.dump(serialized, 0, new FileOutputStream(dumpDir + path + ".dump2"), 0); // More friendly dump
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: interpretMessage
import org.apache.commons.io.HexDump; //导入依赖的package包/类
/**
* Interprets the message to create a string representation
*
* @param message
* 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());
}
}
示例11: hexDump
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static String hexDump(byte[] bytes) {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try {
HexDump.dump(bytes, 0, buf, 0);
return buf.toString();
}
catch (Exception x) {
}
return "";
}
示例12: dump
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static final void dump(byte[] packet) {
Logger logger = Logger.getLogger("MySQL.Packet");
if (!logger.isTraceEnabled())
return;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
HexDump.dump(packet, 0, out, 0);
logger.trace("Dumping packet\n"+out.toString());
}
catch (IOException e) {
return;
}
}
示例13: dump_stderr
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static final void dump_stderr(byte[] packet) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
HexDump.dump(packet, 0, out, 0);
System.err.println("Dumping packet\n"+out.toString());
}
catch (IOException e) {
return;
}
}
示例14: readStartPos
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static Pair<Long, Long> readStartPos(CloseableHttpClient client) throws IOException {
log.info("Reading header from " + INDEX_URL);
HttpGet httpGet = new HttpGet(INDEX_URL);
try (CloseableHttpResponse response = client.execute(httpGet)) {
HttpEntity entity = Utils.checkAndFetch(response, INDEX_URL);
try (InputStream stream = entity.getContent()) {
try {
// try with the first few bytes initially
byte[] header = new byte[HEADER_BLOCK_SIZE];
IOUtils.read(stream, header);
HexDump.dump(header, 0, System.out, 0);
long blockSize = LittleEndian.getUInt(header, 0);
long indexBlockCount = LittleEndian.getUInt(header, 4);
log.info("Header: blockSize " + blockSize + ", indexBlockCount: " + indexBlockCount);
return ImmutablePair.of(blockSize, HEADER_BLOCK_SIZE + (blockSize * indexBlockCount));
} finally {
// always abort reading here inside the finally block of the InputStream as
// otherwise HttpClient tries to read the stream fully, which is at least 270GB...
httpGet.abort();
}
}
}
}
示例15: main
import org.apache.commons.io.HexDump; //导入依赖的package包/类
public static void main(String... args) throws Exception {
try (final ZMQ.Context context = ZMQ.context(1)) {
try (final ZMQ.Socket socket = context.socket(ZMQ.REP)) {
socket.bind("tcp://127.0.0.1:5555");
while (!Thread.currentThread ().isInterrupted()) {
byte[] request = socket.recv(0);
HexDump.dump(request, 0, System.out, 0);
String response = "World";
socket.send(response.getBytes(), 0);
Thread.sleep(1000); // Do some 'work'
}
}
}
}