/*
* 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;
}
}

最新文章

  1. vmware下centos7桥接模式无法上网
  2. SVN
  3. Qt动画效果展示(文艺IT男)
  4. 怎么写jq插件?
  5. Python:使用pymssql批量插入csv文件到数据库测试
  6. BZOJ 1821 部落划分
  7. javascript中false值及其常见比较运算
  8. html结构,第一节
  9. Android面向HTTP协议发送post请求
  10. TNS-00512: Address already in use-TNS-12542: TNS:address already in use
  11. AspNetPager分页实际应用
  12. weblogic11g 配置数据源
  13. HDU 1814 Peaceful Commission
  14. Java基础—标识符及命名规范
  15. [Swift]LeetCode35. 搜索插入位置 | Search Insert Position
  16. python对mysql进行简单操作
  17. 从BIRT报表文件中获取页面设置信息(页边距、纸张大小、输出方向)的方法
  18. (转)Spring Boot(十一):Spring Boot 中 MongoDB 的使用
  19. PHP标准库 SPL
  20. 2.5星|《哈佛商学院管理与MBA案例全书》:书名太唬人了,依据中文经管书汇编整理而成

热门文章

  1. Android---控制设备照相机
  2. 搭建PHP建站环境
  3. Promise初体验
  4. 关于JavaMail
  5. JavaScript进阶(四)
  6. [DP之树形DP]
  7. Mysql之CentOS初探
  8. httpclient用法
  9. react-router的基础知识
  10. Alyona and copybooks