123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package com.fdkankan.fusion.common.util;
- import java.io.*;
- import java.math.BigDecimal;
- import java.nio.file.Paths;
- import java.nio.file.StandardCopyOption;
- import java.util.List;
- import java.util.Objects;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import static cn.hutool.core.util.ClassUtil.getClassLoader;
- public class FileWriterUtil {
- public static void writerJson(String tagPath,String fileName,String msg){
- try {
- File file = new File(tagPath);
- if(!file.exists()){
- file.mkdirs();
- }
- FileWriter fw = new FileWriter(tagPath +File.separator +fileName);
- fw.write(msg);
- fw.flush();
- fw.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public static String readFile(String file) throws Exception {
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String line = null;
- StringBuilder stringBuilder = new StringBuilder();
- String ls = System.getProperty("line.separator");
- try {
- while((line = reader.readLine()) != null) {
- stringBuilder.append(line);
- stringBuilder.append(ls);
- }
- return stringBuilder.toString();
- } finally {
- reader.close();
- }
- }
- public static void streamToFile(String fileName,String newFilePath){
- InputStream stream = getClassLoader().getResourceAsStream(fileName);
- try {
- assert stream != null;
- java.nio.file.Files.copy(
- stream,
- Paths.get(newFilePath),
- new StandardCopyOption[]{StandardCopyOption.REPLACE_EXISTING});
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public static String setFileSize(Long length) {
- BigDecimal decimal = new BigDecimal(length);
- BigDecimal size = new BigDecimal(1024);
- if(length >= 1024 * 1024 ){
- return decimal.divide(size.multiply(size)).setScale(2,BigDecimal.ROUND_HALF_UP).toString() + "MB";
- }
- return decimal.divide(size).setScale(2,BigDecimal.ROUND_HALF_UP).toString() +"KB";
- }
- public static void getCanRunList(List<File> fileList,File objPathFile) {
- File[] files = objPathFile.listFiles();
- for (File file1 : files) {
- if(file1.isFile()){
- if(file1.getName().endsWith(".obj") || file1.getName().endsWith(".las") || file1.getName().endsWith(".ply")
- || file1.getName().endsWith(".osgb") || file1.getName().endsWith(".b3dm") || file1.getName().endsWith(".laz")){
- fileList.add(file1);
- }
- }else {
- getCanRunList(fileList,file1);
- }
- }
- }
- public static String checkB3dmTileset(File objPathFile) {
- File[] files = objPathFile.listFiles();
- if(files == null || files.length<=0){
- return null;
- }
- for (File file : files) {
- if(file.isFile()){
- if(file.getName().endsWith(".json")){
- return file.getPath();
- }
- }
- }
- return null;
- }
- public static boolean isChinese(String str) {
- String regEx = "[\\u4e00-\\u9fa5]+";
- Pattern p = Pattern.compile(regEx);
- Matcher m = p.matcher(str);
- return m.find();
- }
- }
|