/*
* Java Bittorrent API as its name indicates is a JAVA API that implements the Bittorrent Protocol
* This project contains two packages:
* 1. jBittorrentAPI is the "client" part, i.e. it implements all classes needed to publish
* files, share them and download them.
* This package also contains example classes on how a developer could create new applications.
* 2. trackerBT is the "tracker" part, i.e. it implements a all classes needed to run
* a Bittorrent tracker that coordinates peers exchanges. *
*
* Copyright (C) 2007 Baptiste Dubuis, Artificial Intelligence Laboratory, EPFL
*
* This file is part of jbittorrentapi-v1.0.zip
*
* Java Bittorrent API is free software and a free user study set-up;
* you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Java Bittorrent API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Java Bittorrent API; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version 1.0
* @author Baptiste Dubuis
* To contact the author:
* email: baptiste.dubuis@gmail.com
*
* More information about Java Bittorrent API:
* http://sourceforge.net/projects/bitext/
*/ //package atorrentapi; class Main { /**
*
* Convert a byte[] array to readable string format. This makes the "hex"
* readable!
*
* @author Jeff Boyle
*
* @return result String buffer in String format
*
* @param in
* byte[] buffer to convert to string format
*
*/
// Taken from http://www.devx.com/tips/Tip/13540
public static String byteArrayToByteString(byte in[]) {
byte ch = 0x00;
int i = 0;
if (in == null || in.length <= 0)
return null; String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F" };
StringBuffer out = new StringBuffer(in.length * 2); while (i < in.length) {
ch = (byte) (in[i] & 0xF0); // Strip off high nibble
ch = (byte) (ch >>> 4); // shift the bits down
ch = (byte) (ch & 0x0F); // must do this is high order bit is on!
out.append(pseudo[(int) ch]); // convert the nibble to a String
// Character
ch = (byte) (in[i] & 0x0F); // Strip off low nibble
out.append(pseudo[(int) ch]); // convert the nibble to a String
// Character
i++;
} String rslt = new String(out); return rslt;
}
}

Convert a byte[] array to readable string format. This makes the "hex" readable!的更多相关文章

  1. Byte Array to Hexadecimal String

    Lookup Text: 23,879.41 (20.8X faster) Sentence: 1.15 (23.9X faster) /// <summary> /// Hex stri ...

  2. How to convert a byte to its binary string representation

    How to convert a byte to its binary string representation For example, the bits in a byte B are 1000 ...

  3. 异常-----Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-

    1.错误描述 五月 27, 2014 12:07:05 上午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  4. C# byte array 跟 string 互转

    用 System.Text.Encoding.Default.GetString() 转换时,byte array 中大于 127 的数据转 string 时会出问题. 把这里的 Default 换成 ...

  5. C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:

    public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count); 将指定数目的字 ...

  6. 【转】string.Format对C#字符串格式化

    转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...

  7. String.Format用法

    http://blog.csdn.net/yohop/article/details/2534907 1.作为参数   名称 说明   Format(String, Object) 将指定的 Stri ...

  8. JS字符串格式化函数 string.format

    原生JS写的仿C#的字符串format函数,在此基础上又增加了便于JS使用的字面量对象参数. 参照C#中的规则,调用的时候会检测字符串格式,如果字符串格式不规范,或者传入的参数为null或undefi ...

  9. string.Format之你不知道的事

    1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...

随机推荐

  1. 杭电OJ——1011 Starship Troopers(dfs + 树形dp)

    Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a ba ...

  2. java布尔值进行and和or逻辑运算原理

    先看看如下代码: public class Test { public static void test() { boolean a = true; boolean b = false; if (a ...

  3. 结构-行为-样式-requireJs实现图片轮播插件

    最近工作需要,就自己写了一个图片轮播插件,不过想到要集成到框架中,于是又用RequireJs改了一遍. 主要文件: style.css jquery-1.11.1.min.js require.js ...

  4. Android 动态监听网络 断网重连

    需求: 网络连接断开 弹出popupwindow 当前网络连接断开 网络恢复时popupwindow 消失重新请求网络. 需求描述完毕 上一张帅图 思路:广播 发送及时消息 断网flag  popup ...

  5. 三、spark入门:文本中发现5个最常用的word,排除常用停用词

    package com.yl.wordcount import java.io.File import org.apache.spark.{SparkConf, SparkContext} impor ...

  6. Flood it 游戏

    致敬HDU4127做的一个小游戏(数据结构大作业没东西写就搞这个了QAQ). 游戏截图(当然上交版本就没这么暴力拉): GUI界面选用的是Qt,由于之前没有接触过相关的东西,入门Qt花了不少时间. 大 ...

  7. python自动化开发-2

    1.python的数据类型之列表 列表是Python开发语言中最常见的数据类型之一,通过列表可以实现对数据的增删改等常用操作. 列表的定义:例子 names = ["Lucy",& ...

  8. getResourceAsStream和getResource的用法

    用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大家最经常用的,就是用JAVA的File类,如要取得 D:/test.txt文件,就会这样用File file ...

  9. find指令

    1.命令格式 find path -options [-print -exec -ok ...] 2.命令功能 查找文件,并作出相应处理 3.命令参数

  10. wpf 界面线程 添加项

    foreach (var r in sec.Records) { listView.Dispatcher.Invoke((new Action(delegate() { listView.Items. ...