初始化代码
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
12321321
|
||||
3213
|
||||
|
||||
3213213
|
||||
321321
|
||||
321321
|
||||
3
|
||||
|
||||
32132131
|
||||
321321321
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
@@ -0,0 +1,30 @@
|
||||
package util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUtilTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FileUtil.isFile("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest\\1\\11.txt"));
|
||||
System.out.println(FileUtil.isDir("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest"));
|
||||
// for(File file:FileUtil.findAllDirFromDir("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest")){
|
||||
// System.out.println(file.getName());
|
||||
// }
|
||||
|
||||
System.out.println("===================================");
|
||||
for(File file:FileUtil.findAllEmptyDirFromDir("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest")){
|
||||
System.out.println(file.getName());
|
||||
}
|
||||
//
|
||||
// System.out.println("===================================");
|
||||
// for(File file:FileUtil.findAllFile(new File("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest"))){
|
||||
// System.out.println(file.getName());
|
||||
// }
|
||||
//
|
||||
//
|
||||
System.out.println("===================================");
|
||||
for(File file:FileUtil.findAllNotEmptyDirFromDir("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\emptyDirTest")){
|
||||
System.out.println(file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import entity.OriginTimeValue;
|
||||
import entity.TargetTimeValue;
|
||||
import util.time.FillFullTimeValueUtil;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class FullFillTimeValueTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<OriginTimeValue> originTimeValueList = Lists.newArrayList();
|
||||
originTimeValueList.add(new OriginTimeValue(1542995383, 109991));
|
||||
|
||||
List<TargetTimeValue> targetTimeValues1 = FillFullTimeValueUtil.MINUTE.fullFillTimeValue(LocalDateTime.now(), LocalDateTime.now()
|
||||
.plusDays(1), 1, originTimeValueList,
|
||||
TimeZone.getDefault());
|
||||
|
||||
|
||||
List<TargetTimeValue> targetTimeValues2 = FillFullTimeValueUtil.HOUR.fullFillTimeValue(LocalDateTime.now(), LocalDateTime.now()
|
||||
.plusDays(1), 2, originTimeValueList,
|
||||
TimeZone.getDefault());
|
||||
|
||||
List<TargetTimeValue> targetTimeValues3 = FillFullTimeValueUtil.DAY.fullFillTimeValue(LocalDateTime.now(), LocalDateTime.now()
|
||||
.plusDays(100), 10, originTimeValueList,
|
||||
TimeZone.getDefault());
|
||||
|
||||
List<TargetTimeValue> targetTimeValues4 = FillFullTimeValueUtil.MINUTE.fullFillTimeValue(LocalDateTime.now(), LocalDateTime.now()
|
||||
.plusDays(1), 1, null,
|
||||
TimeZone.getDefault());
|
||||
|
||||
|
||||
targetTimeValues1.forEach(targetTimeValue -> System.out.println(targetTimeValue.getTime() + " , " + targetTimeValue.getValue()));
|
||||
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
|
||||
targetTimeValues2.forEach(targetTimeValue -> System.out.println(targetTimeValue.getTime() + " , " + targetTimeValue.getValue()));
|
||||
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
|
||||
targetTimeValues3.forEach(targetTimeValue -> System.out.println(targetTimeValue.getTime() + " , " + targetTimeValue.getValue()));
|
||||
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
|
||||
targetTimeValues4.forEach(targetTimeValue -> System.out.println(targetTimeValue.getTime() + " , " + targetTimeValue.getValue()));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package util;
|
||||
|
||||
public class MessageUtilsTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String pattern = "{0}----{1}======={2}_______{3}";
|
||||
System.out.println(MessageUtils.format(pattern,"我是零","我是一","我是2","我是三"));
|
||||
System.out.println(MessageUtils.format(pattern,"我是零","我是一"));
|
||||
System.out.println(MessageUtils.format(pattern,"我是零","我是一","我是2","我是三","我是多的","我又多了"));
|
||||
xxx[] a = new xxx[] {new xxx("123",222),new xxx("123",555),new xxx("999",222)};
|
||||
System.out.println(MessageUtils.format(pattern,a));
|
||||
|
||||
String i = "{ --},{}";
|
||||
System.out.println(MessageUtils.format(i,"我是零","我是一"));
|
||||
System.out.println(MessageUtils.format(i,a));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class xxx{
|
||||
String a;
|
||||
int b;
|
||||
|
||||
public xxx(String a, int b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package util;
|
||||
|
||||
|
||||
import entity.CommonPageResp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PageUtilTest {
|
||||
|
||||
|
||||
private static List<String> valueList = new ArrayList<>();
|
||||
private static List<String> emptyList = new ArrayList<>();
|
||||
private static List<String> nullList =null;
|
||||
|
||||
public static void dataMake(){
|
||||
valueList.add("1");
|
||||
valueList.add("2");
|
||||
valueList.add("3");
|
||||
valueList.add("4");
|
||||
valueList.add("5");
|
||||
valueList.add("6");
|
||||
valueList.add("7");
|
||||
valueList.add("8");
|
||||
valueList.add("9");
|
||||
valueList.add("10");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
dataMake();
|
||||
|
||||
// CommonPageResp<String> result = PageUtil.pagingListFromZero(valueList,-1,100);
|
||||
CommonPageResp<String> result1 = PageUtil.pagingListFromZero(valueList,1,2);
|
||||
CommonPageResp<String> result2 = PageUtil.pagingListFromZero(valueList,0,2);
|
||||
CommonPageResp<String> result3 = PageUtil.pagingListFromZero(valueList,100,2);
|
||||
CommonPageResp<String> result5 = PageUtil.pagingListFromZero(emptyList,100,3);
|
||||
CommonPageResp<String> result6 = PageUtil.pagingListFromZero(nullList,100,2);
|
||||
|
||||
|
||||
// CommonPageResp<String> result = PageUtil.pagingListFromOne(valueList,-1,100);
|
||||
CommonPageResp<String> result7 = PageUtil.pagingListFromOne(valueList,1,2);
|
||||
CommonPageResp<String> result8 = PageUtil.pagingListFromOne(valueList,2,2);
|
||||
CommonPageResp<String> result9 = PageUtil.pagingListFromOne(valueList,100,2);
|
||||
CommonPageResp<String> result10 = PageUtil.pagingListFromOne(emptyList,100,3);
|
||||
CommonPageResp<String> result11 = PageUtil.pagingListFromOne(nullList,100,2);
|
||||
System.out.println("直接断点查看结果");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package util;
|
||||
|
||||
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||
|
||||
public class StringUtilsTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws BadHanyuPinyinOutputFormatCombination {
|
||||
System.out.println( StringUtils.upperFirstLetter("abx123"));
|
||||
System.out.println( StringUtils.upperFirstLetter("123abx123"));
|
||||
System.out.println( StringUtils.upperFirstLetter("%%#@abx123"));
|
||||
|
||||
|
||||
System.out.println( StringUtils.lowerFirstLetter("Abx123"));
|
||||
System.out.println( StringUtils.lowerFirstLetter("123abx123"));
|
||||
System.out.println( StringUtils.lowerFirstLetter("%%#@abx123"));
|
||||
|
||||
System.out.println( StringUtils.upperAllLetter("Abx123"));
|
||||
System.out.println( StringUtils.upperAllLetter("123abx123"));
|
||||
System.out.println( StringUtils.upperAllLetter("%%#@abx123"));
|
||||
|
||||
|
||||
System.out.println( StringUtils.lowerAllLetter("Abx123"));
|
||||
System.out.println( StringUtils.lowerAllLetter("123abx123"));
|
||||
System.out.println( StringUtils.lowerAllLetter("%%#@abx123"));
|
||||
|
||||
|
||||
System.out.println( StringUtils.appendAll("%%#@abx123","dsadasdsad"));
|
||||
System.out.println( StringUtils.appendAll("%%#@abx123"));
|
||||
System.out.println( StringUtils.appendAll());
|
||||
System.out.println( StringUtils.appendAll("%%#@abx123","dasde2weqwewq","d dasdsa dasdas da dsa"));
|
||||
|
||||
|
||||
System.out.println( StringUtils.isContainChinese("%%#@abx123"));
|
||||
System.out.println( StringUtils.isContainChinese("%%#@哈哈哈哈的撒娇低价十九大uiyhuids"));
|
||||
System.out.println( StringUtils.isContainChinese(""));
|
||||
System.out.println( StringUtils.isContainChinese("大数99092jkjj大声道"));
|
||||
System.out.println( StringUtils.isContainChinese("大数99092jkjj"));
|
||||
|
||||
System.out.println( StringUtils.isChineseChar('1'));
|
||||
System.out.println( StringUtils.isChineseChar('我'));
|
||||
|
||||
System.out.println( StringUtils.toPinyinUpper("我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinUpper("%%#@我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinUpper(""));
|
||||
System.out.println( StringUtils.toPinyinUpper("我爱中国12321dsad"));
|
||||
System.out.println( StringUtils.toPinyinUpper("12321dsad"));
|
||||
|
||||
|
||||
System.out.println( StringUtils.toPinyinLower("我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinLower("%%#@我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinLower(""));
|
||||
System.out.println( StringUtils.toPinyinLower("我爱中国12321dsad"));
|
||||
System.out.println( StringUtils.toPinyinLower("12321dsad"));
|
||||
|
||||
|
||||
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignUpper("我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignUpper("%%#@我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignUpper(""));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignUpper("我爱中国12321dsad"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignUpper("12321dsad"));
|
||||
|
||||
|
||||
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignLower("我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignLower("%%#@我爱中国"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignLower(""));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignLower("我爱中国12321dsad"));
|
||||
System.out.println( StringUtils.toPinyinPhoneticSignLower("12321dsad"));
|
||||
|
||||
System.out.println(StringUtils.replacePattern("ABCDEFG","[A-C]"));
|
||||
System.out.println(StringUtils.replacePattern("ABCDEFG12333","[A-C1-3]"));
|
||||
System.out.println(StringUtils.replacePattern("X432432^&*(DSAD","[A-C1-2]"));
|
||||
|
||||
System.out.println(StringUtils.replacePattern("ABCDEFG","XYZ","[A-C]"));
|
||||
System.out.println(StringUtils.replacePattern("ABCDEFG12333","YYYM","[A-C1-3]"));
|
||||
System.out.println(StringUtils.replacePattern("X432432^&*(DSAD","中文,213321sdadsa","[A-C1-2]"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package util.image;
|
||||
|
||||
public class CaptchaUtilTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
CaptchaUtil captchaUtil = new CaptchaUtil();
|
||||
System.out.println(captchaUtil.generalCode());
|
||||
captchaUtil.generateCaptchaImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\captcha\\test.jpg");
|
||||
//自定义code的处理
|
||||
captchaUtil.generateCaptchaImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\captcha\\test1.jpg","xy2312sa");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 829 KiB |
@@ -0,0 +1,17 @@
|
||||
package util.image;
|
||||
|
||||
import util.FileUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JpegImagerUtilTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
PicturesCompressUtil picturesCompressUtil = new PicturesCompressUtil();
|
||||
picturesCompressUtil.compress("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\JpegImager\\2002013.jpg","F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\JpegImager\\2002013_copy.jpg");
|
||||
System.out.println("压缩之后的大小差别为");
|
||||
byte[] b1 = FileUtil.fileToByte("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\JpegImager\\2002013.jpg");
|
||||
byte[] b2 = FileUtil.fileToByte("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\JpegImager\\2002013_copy.jpg");
|
||||
System.out.println("压缩前后字节差:" + (b1.length - b2.length+ " byte"));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 388 KiB |
@@ -0,0 +1,32 @@
|
||||
package util.image;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class QRCodeUtilTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
QRCodeUtil qrCodeUtil = new QRCodeUtil();
|
||||
qrCodeUtil.getQrCodeItem().setContent("我测试一下");
|
||||
qrCodeUtil.getQrCodeItem().setContentFont(new Font("宋体",Font.BOLD, 12));
|
||||
qrCodeUtil.getQrCodeItem().setContentColor(Color.RED);
|
||||
BufferedImage bufferedImage = qrCodeUtil.createQrCodeImage();
|
||||
qrCodeUtil.createQrCodeWithImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\QRCode\\default.jpg",bufferedImage);
|
||||
|
||||
BufferedImage bufferedImage1 = qrCodeUtil.createQrCodeImage();
|
||||
bufferedImage1 = qrCodeUtil.drawContent(bufferedImage1);
|
||||
qrCodeUtil.createQrCodeWithImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\QRCode\\content.jpg",bufferedImage1);
|
||||
|
||||
BufferedImage bufferedImage2 = qrCodeUtil.createQrCodeImage();
|
||||
bufferedImage2 = qrCodeUtil.drawLogo(bufferedImage2);
|
||||
qrCodeUtil.createQrCodeWithImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\QRCode\\logo1.jpg",bufferedImage2);
|
||||
|
||||
BufferedImage bufferedImage3 = qrCodeUtil.createQrCodeImage();
|
||||
bufferedImage3 = qrCodeUtil.drawLogo(bufferedImage3);
|
||||
bufferedImage3 = qrCodeUtil.drawContent(bufferedImage3);
|
||||
qrCodeUtil.createQrCodeWithImage("F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\image\\QRCode\\logoContent.jpg",bufferedImage3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package util.transform;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
public class TransformTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("测试JsonBinder");
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.setX1(123);
|
||||
jsonObject.setX2("123");
|
||||
jsonObject.setX3(new JsonObject());
|
||||
String jsonString = JsonBinder.toJson(jsonObject);
|
||||
System.out.println(jsonString);
|
||||
System.out.println(JsonBinder.fromJson(jsonString, JsonObject.class).getX2());
|
||||
|
||||
System.out.println("测试XmlBinder");
|
||||
String xmlString = XmlBinder.convertToXml(jsonObject);
|
||||
System.out.println(xmlString);
|
||||
|
||||
System.out.println(XmlBinder.convertXmlStrToObject(xmlString,JsonObject.class).getX2());
|
||||
XmlBinder.convertToXml(jsonObject,"F:\\Java个人代码\\Java_Utils\\src\\main\\test\\util\\transform\\transform.xml");
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "xml")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
static class JsonObject {
|
||||
@XmlElement(name = "x1")
|
||||
int x1;
|
||||
@XmlElement(name = "x2")
|
||||
String x2;
|
||||
@XmlElement(name = "x3")
|
||||
JsonObject x3;
|
||||
|
||||
public int getX1() {
|
||||
return x1;
|
||||
}
|
||||
|
||||
public void setX1(int x1) {
|
||||
this.x1 = x1;
|
||||
}
|
||||
|
||||
public String getX2() {
|
||||
return x2;
|
||||
}
|
||||
|
||||
public void setX2(String x2) {
|
||||
this.x2 = x2;
|
||||
}
|
||||
|
||||
public JsonObject getX3() {
|
||||
return x3;
|
||||
}
|
||||
|
||||
public void setX3(JsonObject x3) {
|
||||
this.x3 = x3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package util.tree;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
public class TreeUtilTest {
|
||||
public static void main(String[] args) {
|
||||
String treeNodeString = "[{\"code\":\"aa\",\"parentCode\":\"a\"},{\"code\":\"aaa\",\"parentCode\":\"aa\"},{\"code\":\"aaaa\","
|
||||
+ "\"parentCode\":\"aaa\"},{\"code\":\"bbbb\",\"parentCode\":\"aaa\"},{\"code\":\"XXX\",\"parentCode\":\"aaaa\"},"
|
||||
+ "{\"code\":\"22121\",\"parentCode\":\"XXX\"},{\"code\":\"a\",\"parentCode\":\"0\"},{\"code\":\"222\",\"parentCode\":\"a\"},"
|
||||
+ "{\"code\":\"AXMW\",\"parentCode\":\"222\"}]";
|
||||
System.out.println(TreeUtils.getCodePath(JSON.parseArray(treeNodeString, TreeNode.class),"aa"));
|
||||
System.out.println(TreeUtils.getCodePath(JSON.parseArray(treeNodeString, TreeNode.class),"mmmm"));
|
||||
|
||||
TreeNode2 t2 = TreeUtils.getTreeWithChildNodeList(JSON.parseArray(treeNodeString, TreeNode2.class),"a");
|
||||
TreeNode2 t3 = TreeUtils.getTreeWithChildNodeList(JSON.parseArray(treeNodeString, TreeNode2.class),"mmmm");
|
||||
TreeNode2 t4 = TreeUtils.getTreeWithChildNodeList(JSON.parseArray(treeNodeString, TreeNode2.class),"AXMW");
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* @(#) TestGzip
|
||||
* 版权声明 网宿科技, 版权所有 违者必究
|
||||
*
|
||||
* <br> Copyright: Copyright (c) 2018
|
||||
* <br> Company:网宿科技
|
||||
* <br> @author Administrator
|
||||
* <br> @description 功能描述
|
||||
* <br> 2018-11-09 20:30:59
|
||||
*/
|
||||
|
||||
package util.zip;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import entity.FileItem;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import util.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* 关联WS业务--日志下载
|
||||
* 参考地址:https://www.cnblogs.com/guochunyi/p/5311261.html
|
||||
*/
|
||||
public class ZipTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
//这边的测试我没有放入对应的文件,因为太大了,所以如果想要测试,需要在相应的目录放入对应带下的文件才能进行测试...
|
||||
testGzip();
|
||||
}
|
||||
|
||||
public static void testGzip() throws IOException {
|
||||
String Path1M = ZipTest.class.getClassLoader().getResource("/test/testDownload").getPath();
|
||||
String path10M = ZipTest.class.getClassLoader().getResource("/test/test10M").getPath();
|
||||
String path100M = ZipTest.class.getClassLoader().getResource("/test/test100M").getPath();
|
||||
String path1000M = ZipTest.class.getClassLoader().getResource("/test/test1000M").getPath();
|
||||
System.out.println("测试1M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testGzipOnce(Path1M);
|
||||
}
|
||||
System.out.println("测试10M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testGzipOnce(path10M);
|
||||
}
|
||||
System.out.println("测试100M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testGzipOnce(path100M);
|
||||
}
|
||||
System.out.println("测试1000M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testGzipOnce(path1000M);
|
||||
}
|
||||
|
||||
System.out.println("测试1M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testZipOnce(Path1M);
|
||||
}
|
||||
System.out.println("测试10M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testZipOnce(path10M);
|
||||
}
|
||||
System.out.println("测试100M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testZipOnce(path100M);
|
||||
}
|
||||
System.out.println("测试1000M数据的压缩时间");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
testZipOnce(path1000M);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void testZipOnce(String path) throws IOException {
|
||||
String filePath = ZipTest.class.getClassLoader().getResource("/test").getPath();
|
||||
File packageFile = new File(filePath + UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
packageFile.mkdir();
|
||||
String zPath = packageFile.getPath() + File.separator + UUID.randomUUID().toString().replaceAll("-", "") + ".zip";
|
||||
new File(zPath).createNewFile();
|
||||
|
||||
File file = ZipOutputUtil.compress(path, zPath);
|
||||
System.out.println(file.getName());
|
||||
}
|
||||
|
||||
private static void testGzipOnce(String path) throws IOException {
|
||||
String filePath = ZipTest.class.getClassLoader().getResource("/test").getPath();
|
||||
File packageFile = new File(filePath + UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
packageFile.mkdir();
|
||||
String tarPath = packageFile.getPath() + File.separator + UUID.randomUUID().toString().replaceAll("-", "") + ".tar";
|
||||
String gzPath = packageFile.getPath() + File.separator + UUID.randomUUID().toString().replaceAll("-", "") + ".gz";
|
||||
new File(gzPath).createNewFile();
|
||||
List<File> files = Lists.newArrayList();
|
||||
File file = new File(path);
|
||||
File[] file1 = file.listFiles();
|
||||
for (File file2 : file1) {
|
||||
files.add(file2);
|
||||
}
|
||||
File filex = TarArchiveGZIPOutputUtil.compress(files, tarPath);
|
||||
System.out.println(filex.getName());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/testFile1", method = RequestMethod.POST)
|
||||
public void testFile1() throws FileNotFoundException {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
String filePath = ZipTest.class.getClassLoader().getResource("/test").getPath();
|
||||
File packageFile = new File(filePath + UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
packageFile.mkdir();
|
||||
|
||||
String path = ZipTest.class.getClassLoader().getResource("/test/testgzip").getPath();
|
||||
File file = new File(path);
|
||||
File[] files = file.listFiles();
|
||||
List<FileItem> fileItems = Lists.newArrayList();
|
||||
|
||||
for (File file1 : files) {
|
||||
FileItem fileItem = new FileItem();
|
||||
fileItem.setInputStream(new FileInputStream(file1));
|
||||
fileItem.setFileName(file1.getName());
|
||||
fileItems.add(fileItem);
|
||||
}
|
||||
|
||||
FileUtil.storeFiles(fileItems, packageFile.getPath());
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.getTotalTimeMillis() / 1000.0000 + " s");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user