初次提交
This commit is contained in:
19
file-center/src/test/java/ParseTest.java
Normal file
19
file-center/src/test/java/ParseTest.java
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/12/15
|
||||
*/
|
||||
public class ParseTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int onLine = 5;
|
||||
int inverterCount = 3;
|
||||
double rate = Math.ceil((double)onLine/ inverterCount);
|
||||
System.out.println(rate);
|
||||
|
||||
int i = 1;
|
||||
int j=3;
|
||||
double d = (double) i/ j;
|
||||
System.out.println("d:"+d);
|
||||
}
|
||||
}
|
||||
65
file-center/src/test/java/com/ho/filecenter/FileRead.java
Normal file
65
file-center/src/test/java/com/ho/filecenter/FileRead.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.ho.filecenter;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/1/5
|
||||
*/
|
||||
public class FileRead {
|
||||
public static void main(String[] args) {
|
||||
String path = "d:/2.png";
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
try {
|
||||
byte[] bytes = readBlock(path, 0);
|
||||
|
||||
BufferedImage bufferedImage = ImageIO.read(new File(path));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "png", baos);
|
||||
byte[] bytes2 = baos.toByteArray();
|
||||
String encode = Base64.encode(bytes);
|
||||
String trim2 = encoder.encodeBuffer(bytes).trim();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//按位置分块读取文件内容
|
||||
public static byte[] readBlock(String path, int pointer) throws Exception {
|
||||
if (!new File(path).exists()){
|
||||
throw new BusinessException(BaseResponseCode.FILE_NOT_EXISTS) ;
|
||||
}
|
||||
RandomAccessFile raf = new RandomAccessFile(path, "r");
|
||||
long length = raf.length();
|
||||
System.out.println("文件大小:" + length);
|
||||
//设置指针的位置,每次有偏移
|
||||
raf.seek(pointer * 102400);
|
||||
//每次读取102400字节,这个应该改为参数配置
|
||||
byte[] bytes = new byte[102400];
|
||||
int readSize = raf.read(bytes);
|
||||
//如果没有读到102400个字节,需要做数组拷贝
|
||||
//读取时判断是否还有剩余字节
|
||||
if (readSize < 102400) {
|
||||
byte[] copy = new byte[readSize];
|
||||
System.arraycopy(bytes, 0, copy, 0, readSize);
|
||||
raf.close();
|
||||
return copy;
|
||||
}
|
||||
raf.close();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
31
file-center/src/test/java/com/ho/filecenter/Test2.java
Normal file
31
file-center/src/test/java/com/ho/filecenter/Test2.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.ho.filecenter;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/12/26
|
||||
*/
|
||||
public class Test2 {
|
||||
public static void main(String[] args) {
|
||||
Date now = new Date();
|
||||
//开始时间,currentMaxDay之前的那天
|
||||
String beginTime = DateUtil.format(DateUtil.offsetDay(now, -30), CommonConstant.DATE_YMD)
|
||||
+ CommonConstant.START_SUFFIX_TIMESTAMP;
|
||||
//今天的23:59:59
|
||||
String endTime = DateUtil.format(DateUtil.endOfDay(now), CommonConstant.DATE);
|
||||
System.out.println();
|
||||
|
||||
List<Integer> list =new ArrayList();
|
||||
list.add(1);
|
||||
System.out.println( list.size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user