Skip to content

Commit 39c5806

Browse files
JeffLi1993liqiangqiang
authored and
liqiangqiang
committed
String to Binary String
1 parent 82f90e4 commit 39c5806

File tree

4 files changed

+146
-63
lines changed

4 files changed

+146
-63
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.javacore.collection.hash;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Created by bysocket on 16/9/26.
8+
*/
9+
public class HashList {
10+
public static void main(String[] args) {
11+
// init data list
12+
List<SkuObj> reqSkuObjList = new ArrayList<>();
13+
List<SkuObj> existSkuObjList = new ArrayList<>();
14+
for (int i = 0 ; i < 5000; i++) {
15+
SkuObj skuObj = new SkuObj();
16+
skuObj.setId(i);
17+
skuObj.setName("name" + i);
18+
skuObj.setAge(i + 666);
19+
skuObj.setDesc("desc" + i);
20+
reqSkuObjList.add(skuObj);
21+
}
22+
23+
for (int i = 0 ; i < 5000; i++) {
24+
SkuObj skuObj = new SkuObj();
25+
skuObj.setId(i);
26+
skuObj.setName("nameexist" + i);
27+
skuObj.setAge(i + 888);
28+
skuObj.setDesc("descexist" + i);
29+
existSkuObjList.add(skuObj);
30+
}
31+
32+
33+
34+
}
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.javacore.collection.hash;
2+
3+
/**
4+
* Created by bysocket on 16/9/26.
5+
*/
6+
public class SkuObj {
7+
8+
Integer id;
9+
10+
String name;
11+
12+
Integer age;
13+
14+
String desc;
15+
16+
public Integer getId() {
17+
return id;
18+
}
19+
20+
public void setId(Integer id) {
21+
this.id = id;
22+
}
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
public Integer getAge() {
33+
return age;
34+
}
35+
36+
public void setAge(Integer age) {
37+
this.age = age;
38+
}
39+
40+
public String getDesc() {
41+
return desc;
42+
}
43+
44+
public void setDesc(String desc) {
45+
this.desc = desc;
46+
}
47+
}

src/main/java/org/javacore/io/byteoper/StringConvertT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,11 +23,12 @@
2323
public class StringConvertT {
2424

2525
public static void main(String[] args){
26-
String str = "李强强";
26+
String str = "HOME";
2727
byte[] bytes = str.getBytes();
2828
// 打印字节数组
29-
System.out.println("UTF-8编码'李强强'的字节数组为:");
30-
for (int i = 0; i < bytes.length; i++)
31-
System.out.print("\t" + bytes[i]);
29+
System.out.println("UTF-8编码'HOME'的字节数组为:");
30+
for (int i = 0; i < bytes.length; i++) {
31+
System.out.println("\t" + bytes[i] + "|" + Integer.toBinaryString(bytes[i]));
32+
}
3233
}
3334
}
Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
package org.javacore.io.serializable;
22

33

4-
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
5-
6-
import java.io.*;
7-
8-
/**
9-
* 描述:Java序列化和反序列化的小例子
10-
* Created by 子木 on 2016/2/15.
11-
*/
12-
public class SerializableT {
13-
public static void main(String[] args) throws IOException, ClassNotFoundException {
14-
for (int i = 0;i < 10;i++) {
15-
AObjcet aObjcet = new AObjcet();
16-
long beginTime = System.currentTimeMillis();
17-
18-
ByteOutputStream byteOutput = new ByteOutputStream();
19-
ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput);
20-
objectOutput.writeObject(aObjcet);
21-
objectOutput.close();
22-
byteOutput.close();
23-
byte[] bytes = byteOutput.toByteArray();
24-
System.out.println("Java序列化耗时:" + (System.currentTimeMillis() - beginTime) + "ms");
25-
System.out.println("Java序列化后的字节大小为:" + bytes.length);
26-
27-
beginTime = System.currentTimeMillis();
28-
ByteArrayInputStream byteInput = new ByteArrayInputStream(bytes);
29-
ObjectInputStream objectInput = new ObjectInputStream(byteInput);
30-
objectInput.readObject();
31-
objectInput.close();
32-
byteInput.close();
33-
System.out.println("Java反序列化耗时:" + (System.currentTimeMillis() - beginTime) + "ms");
34-
35-
}
36-
}
37-
}
38-
class AObjcet implements Serializable {
39-
private String a = "bysocket";
40-
private String b = "likes";
41-
private String c = "java";
42-
private String d = "world";
43-
44-
private int i = 100;
45-
private int j = 10;
46-
private long m = 100L;
47-
48-
private boolean isA = true;
49-
private boolean isB = false;
50-
private boolean isC = false;
51-
52-
private BObject aObject = new BObject();
53-
private BObject bObject = new BObject();
54-
private BObject cObject = new BObject();
55-
private BObject dObject = new BObject();
56-
57-
}
58-
class BObject implements Serializable {
59-
60-
}
4+
//import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
5+
//
6+
//import java.io.*;
7+
//
8+
///**
9+
// * 描述:Java序列化和反序列化的小例子
10+
// * Created by 子木 on 2016/2/15.
11+
// */
12+
//public class SerializableT {
13+
// public static void main(String[] args) throws IOException, ClassNotFoundException {
14+
// for (int i = 0;i < 10;i++) {
15+
// AObjcet aObjcet = new AObjcet();
16+
// long beginTime = System.currentTimeMillis();
17+
//
18+
// ByteOutputStream byteOutput = new ByteOutputStream();
19+
// ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput);
20+
// objectOutput.writeObject(aObjcet);
21+
// objectOutput.close();
22+
// byteOutput.close();
23+
// byte[] bytes = byteOutput.toByteArray();
24+
// System.out.println("Java序列化耗时:" + (System.currentTimeMillis() - beginTime) + "ms");
25+
// System.out.println("Java序列化后的字节大小为:" + bytes.length);
26+
//
27+
// beginTime = System.currentTimeMillis();
28+
// ByteArrayInputStream byteInput = new ByteArrayInputStream(bytes);
29+
// ObjectInputStream objectInput = new ObjectInputStream(byteInput);
30+
// objectInput.readObject();
31+
// objectInput.close();
32+
// byteInput.close();
33+
// System.out.println("Java反序列化耗时:" + (System.currentTimeMillis() - beginTime) + "ms");
34+
//
35+
// }
36+
// }
37+
//}
38+
//class AObjcet implements Serializable {
39+
// private String a = "bysocket";
40+
// private String b = "likes";
41+
// private String c = "java";
42+
// private String d = "world";
43+
//
44+
// private int i = 100;
45+
// private int j = 10;
46+
// private long m = 100L;
47+
//
48+
// private boolean isA = true;
49+
// private boolean isB = false;
50+
// private boolean isC = false;
51+
//
52+
// private BObject aObject = new BObject();
53+
// private BObject bObject = new BObject();
54+
// private BObject cObject = new BObject();
55+
// private BObject dObject = new BObject();
56+
//
57+
//}
58+
//class BObject implements Serializable {
59+
//
60+
//}

0 commit comments

Comments
 (0)