java多线程-06-atomic包

转载自并发编程网 – ifeve.com本文链接地址: Java中的Atomic包使用指南

本文首发于并发网,作者:方腾飞

阅读全文

java多线程-07-Lock和Condition

声明

该系列文章只是记录本人回顾java多线程编程时候记录的笔记。文中所用语言并非严谨的专业术语(太严谨的术语其实本人也不会……)。难免有理解偏差的地方,欢迎指正。
另外,大神请绕路。不喜勿喷。
毕竟好记性不如烂笔头嘛,而且许多东西只要不是你经常用的最终都会一丢丢一丢丢地给忘记。

阅读全文

java字符串和十六进制互转

java字符串和十六进制字符串互转

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class HexStringUtils {
private static final char[] DIGITS_HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F' };
protected static char[] encodeHex(byte[] data) {
int l = data.length;
char[] out = new char[l << 1];
for (int i = 0, j = 0; i < l; i++) {
out[j++] = DIGITS_HEX[(0xF0 & data[i]) >>> 4];
out[j++] = DIGITS_HEX[0x0F & data[i]];
}
return out;
}
protected static byte[] decodeHex(char[] data) {
int len = data.length;
if ((len & 0x01) != 0) {
throw new RuntimeException("字符个数应该为偶数");
}
byte[] out = new byte[len >> 1];
for (int i = 0, j = 0; j < len; i++) {
int f = toDigit(data[j], j) << 4;
j++;
f |= toDigit(data[j], j);
j++;
out[i] = (byte) (f & 0xFF);
}
return out;
}
protected static int toDigit(char ch, int index) {
int digit = Character.digit(ch, 16);
if (digit == -1) {
throw new RuntimeException("Illegal hexadecimal character " + ch + " at index " + index);
}
return digit;
}
public static String toHex(String str) {
return new String(encodeHex(str.getBytes()));
}
public static String fromHex(String hex) {
return new String(decodeHex(hex.toCharArray()));
}
public static void main(String[] args) {
String s = "abc你好";
String hex = toHex(s);
String decode = fromHex(hex);
System.out.println("原字符串:" + s);
System.out.println("十六进制字符串:" + hex);
System.out.println("还原:" + decode);
}
}

阅读全文

P014-LongestCommonPrefix

P014 Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

阅读全文

NIO系列-01-传统BIO

声明

该系列文章由书籍《Netty权威指南》第二版整理而来。只为记录学习笔记。
若认为内容侵权请及时通知本人删除相关内容。

[TOC]

时间服务器–传统的BIO

服务端代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class TimeServer {
public static void main(String[] args) throws IOException {
int port = 1234;
ServerSocket server = null;
try {
server = new ServerSocket(port);
System.out.println("The time server is listening in port : " + port);
Socket socket = null;
while (true) {
socket = server.accept();
new Thread(new TimeServerHandler(socket)).start();
}
} finally {
if (server != null) {
System.out.println("The time server close");
server.close();
server = null;
}
}
}
}

阅读全文

P012-IntegerToRoman

P012 Integer to Roman

Given an integer, convert it to a roman numeral.

阅读全文

docker筑基篇-01-docker常用命令

1 docker 基础命令

info | version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 查看docker总体信息
[root@h1 ~]# docker info
Containers: 1
Images: 42
Storage Driver: devicemapper
Pool Name: docker-253:0-395232-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 2.516 GB
Data Space Total: 107.4 GB
Data Space Available: 29.24 GB
Metadata Space Used: 3.273 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.144 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-08-15)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-642.6.1.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 1.818 GiB
Name: h1
ID: KEQG:W5MZ:K5D3:RQRU:UUCV:SMGZ:NNQZ:BKVI:SZUS:HFEV:FTA7:GAI7
# 版本信息
[root@h1 ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
# 版本信息
[root@h1 ~]# docker -v
Docker version 1.7.1, build 786b29d/1.7.1

阅读全文

java解析JT808协议

本篇文章将介绍JT808协议的解析思路。
另请大神绕路,不喜勿喷!
先写个大致的思路,有疑问可以联系本人,联系方式:

  • emial: hylexus@163.com

1 JT808协议扫盲

1.1 数据类型

阅读全文

docker筑基篇-02-镜像管理

1 镜像再探

docker镜像是由FileSystem叠加而成的。
和传统的linux一样,最底层是bootfs;之上是rootfs。

阅读全文

docker筑基篇-03-使用docker-commit构建自己的镜像

docker构建镜像,至少有两种方法:

  • docker commit 命令
  • Dockerfile

阅读全文