Skip to content

Commit 40310bc

Browse files
committed
add files
1 parent 232ed60 commit 40310bc

18 files changed

Lines changed: 9539 additions & 0 deletions

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
- [threeJs](#threeJs)
1313
+ [java](#java)
1414
- [common](#common-2)
15+
- [io](#io)
16+
- [npl](#nlp)
1517
- [Spring](#spring)
18+
- [MVC](#mvc)
1619
+ [ubuntu](#ubuntu)
1720

1821
## c
@@ -91,9 +94,23 @@
9194
## java
9295
### common
9396
* [BWTCode.java: BWT编码](java/common/BWTCode.java)
97+
* [Cpdetector.java: 使用cpdetector检查文件编码方式](java/common/Cpdetector.java)
98+
* [EnumUse.java: 枚举使用示例](java/common/EnumUse.java)
99+
* [GetIP.java: 获得主机的ip地址](java/common/GetIP.java)
100+
* [GnuGetOpt.java: 使用gnu getopt处理命令行参数](java/common/GnuGetOpt.java)
94101
* [SortFile.java: 将读入的文件一行行的进行排序, 使用TreeMap](java/common/SortFile.java)
95102

103+
104+
### io
105+
* [MultipartFileSender.java: 支持文件断点续传(WEB项目中)](java/io/MultipartFileSender.java)
106+
* [NioOp.java: NIO2 对文件操作-检查文件存在、获得文件属性、遍历文件夹、重命名、创建文件夹、删除文件](java/io/NioOp.java)
107+
108+
### nlp
109+
* [JLanguageCheck.java: 使用JLanguageTool 检测文本语法和语义错误, 可自定义规则](java/nlp/JLanguageCheck.java)
110+
* [rules-en-English.xml: JLanguageTool 自定义规则示例](java/nlp/rules-en-English.xml)
111+
96112
### Spring
113+
#### MVC
97114
* [Spring MVC HelloWolrd](java/spring/mvc/helloworld)
98115
* [Spring MVC 文件上传简单示例](java/spring/mvc/uploadfile)
99116
* [Spring MVC 文件上传简单示例--整合bootstrap-fileinput](java/spring/mvc/uploadfile-bootstrap-fileinput)

‎java/common/Cpdetector.java‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.zhangjikai.utils;
2+
3+
import info.monitorenter.cpdetector.io.*;
4+
5+
import java.io.File;
6+
import java.net.*;
7+
import java.nio.charset.Charset;
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.Enumeration;
11+
import java.util.List;
12+
13+
/**
14+
* Created by zhangjk on 2016/1/19.
15+
*/
16+
public class Cpdetector {
17+
18+
19+
/**
20+
* 使用Cpdetector检测文件编码
21+
*
22+
* @param file
23+
* @return
24+
*/
25+
public static Charset getFileEncode(File file) {
26+
try {
27+
CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
28+
detector.add(new ParsingDetector(false));
29+
detector.add(JChardetFacade.getInstance());
30+
detector.add(ASCIIDetector.getInstance());
31+
detector.add(UnicodeDetector.getInstance());
32+
java.nio.charset.Charset charset = null;
33+
charset = detector.detectCodepage(file.toURI().toURL());
34+
return charset;
35+
} catch (Exception ex) {
36+
ex.printStackTrace();
37+
return null;
38+
}
39+
}
40+
41+
}
42+

‎java/common/EnumUse.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 枚举使用示例
3+
* 使用枚举的值 EnumUse.POSITIVE.toString();
4+
*/
5+
public enum EnumUse {
6+
POSITIVE("pos"), NEGATIVE("neg"), ZERO("zero");
7+
8+
private String value;
9+
10+
private EnumUse(String value) {
11+
this.value = value;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return value;
17+
}
18+
}
19+
20+
class Test{
21+
public static void main(String[] args) {
22+
System.out.println(EnumUse.POSITIVE);
23+
}
24+
}

‎java/common/GetIP.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.zhangjikai.utils;
2+
3+
import java.net.*;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.Enumeration;
7+
import java.util.List;
8+
9+
/**
10+
* 获得电脑的ip地址, 可能获得多个
11+
* Created by zhangjk on 2016/1/19.
12+
*/
13+
public class FtUtils {
14+
15+
public static List<String> getIps() {
16+
17+
List<String> ipList = new ArrayList<>();
18+
Enumeration nets = null;
19+
try {
20+
nets = NetworkInterface.getNetworkInterfaces();
21+
for (NetworkInterface netint : (List<NetworkInterface>) Collections.list(nets)) {
22+
Enumeration inetAddresses = netint.getInetAddresses();
23+
for (InetAddress inetAddress : (List<InetAddress>) Collections.list(inetAddresses)) {
24+
if (inetAddress instanceof Inet4Address)
25+
ipList.add(inetAddress.getHostAddress());
26+
}
27+
28+
}
29+
} catch (SocketException e) {
30+
ipList.add("127.0.0.1");
31+
e.printStackTrace();
32+
}
33+
34+
for(String s : ipList) {
35+
System.out.println(s);
36+
}
37+
return ipList;
38+
}
39+
40+
41+
public static void main(String[] args) {
42+
getIps();
43+
}
44+
45+
}

‎java/common/GnuGetOpt.java‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package bitpal;
2+
3+
import gnu.getopt.Getopt;
4+
import gnu.getopt.LongOpt;
5+
6+
7+
import java.math.BigInteger;
8+
9+
/**
10+
* 使用gnu.getopt 处理命令行参数,
11+
*
12+
* <dependency>
13+
* <groupId>gnu.getopt</groupId>
14+
* <artifactId>java-getopt</artifactId>
15+
* <version>1.0.13</version>
16+
* </dependency>
17+
*
18+
* Created by zhangjikai on 16-3-14.
19+
*/
20+
public class GnuGetOpt {
21+
22+
23+
public static void printHelp() {
24+
StringBuilder builder = new StringBuilder();
25+
builder.append("Options:\n\n");
26+
builder.append(String.format("%-30s", "-M,--match <arg>:"));
27+
builder.append("Specify the match score which should be positive or zero. Default is 2.\n\n");
28+
builder.append(String.format("%-30s", "-I,--mismatch <arg>: "));
29+
builder.append("Specify the mismatch score which should be negative. Default is -3.\n\n");
30+
builder.append(String.format("%-30s", "-G,--gap <arg>: "));
31+
builder.append("Specify the gap score which should be negative. Default is -5.\n\n");
32+
builder.append(String.format("%-30s", "-d,--directory <arg>: "));
33+
builder.append("Specify the directory where to place generated source files.\n\n");
34+
builder.append(String.format("%-30s", "-h,--help: "));
35+
builder.append("Display help Information.\n\n");
36+
builder.append(String.format("%-30s", "-n,--name <arg>: "));
37+
builder.append("Set the name of generated source file.\n\n");
38+
builder.append(String.format("%-30s", "-t,--type <arg>: "));
39+
builder.append("Set the type of generated files. Valid values are: cpu, mic, avx2. Default is cpu.\n\n");
40+
System.out.println(builder.toString());
41+
}
42+
43+
public static void handleArgs(String[] args) {
44+
LongOpt longOpts[] = new LongOpt[7];
45+
longOpts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
46+
longOpts[1] = new LongOpt("directory", LongOpt.REQUIRED_ARGUMENT, null, 'd');
47+
longOpts[2] = new LongOpt("name", LongOpt.REQUIRED_ARGUMENT, null, 'n');
48+
longOpts[3] = new LongOpt("match", LongOpt.REQUIRED_ARGUMENT, null, 'M');
49+
longOpts[4] = new LongOpt("mismatch", LongOpt.REQUIRED_ARGUMENT, null, 'I');
50+
longOpts[5] = new LongOpt("gap", LongOpt.REQUIRED_ARGUMENT, null, 'G');
51+
longOpts[6] = new LongOpt("type", LongOpt.REQUIRED_ARGUMENT, null, 't');
52+
53+
int c;
54+
int num;
55+
String arg;
56+
Getopt opt = new Getopt("bitpal", args, "M:I:G:d:hn:t", longOpts);
57+
58+
while ((c = opt.getopt()) != -1) {
59+
switch (c) {
60+
case 'M':
61+
arg = opt.getOptarg();
62+
try {
63+
num = Integer.parseInt(arg);
64+
} catch (Exception e) {
65+
System.err.println("-M: You should input an integer.");
66+
System.exit(-1);
67+
}
68+
break;
69+
70+
case 'I':
71+
arg = opt.getOptarg();
72+
try {
73+
num = Integer.parseInt(arg);
74+
} catch (Exception e) {
75+
System.err.println("-I: You should input an integer.");
76+
System.exit(-1);
77+
}
78+
break;
79+
80+
case 'G':
81+
arg = opt.getOptarg();
82+
try {
83+
num = Integer.parseInt(arg);
84+
} catch (Exception e) {
85+
System.err.println("-G: You should input an integer.");
86+
System.exit(-1);
87+
}
88+
break;
89+
90+
case 'd':
91+
arg = opt.getOptarg();
92+
break;
93+
case 'h':
94+
printHelp();
95+
break;
96+
case 'n':
97+
arg = opt.getOptarg();
98+
break;
99+
case 't':
100+
arg = opt.getOptarg();
101+
if (!"cpumicavx2".contains(arg)) {
102+
System.err.println("-t: Valid values are {cpu, mic, avx2}");
103+
System.exit(-1);
104+
}
105+
break;
106+
case '?':
107+
System.err.println("The option '" + (char) opt.getOptopt() + "' is not valid");
108+
System.exit(-1);
109+
break;
110+
default:
111+
break;
112+
}
113+
}
114+
}
115+
116+
public static void main(String[] args) {
117+
118+
handleArgs(args);
119+
120+
}
121+
}

0 commit comments

Comments
 (0)