FileUtils.java
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.wondertek.util;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Title: FileUtils <br>
* Description: FileUtils <br>
*/
@Slf4j
public class FileUtils {
/**
* <p><b>Title:</b> getDatePathI</p>
* <p><b>Description:</b> 得到 年/月/日 格式字符串,如: 2020/03/30</p>
*
* @return
*/
public static String getDatePathI() {
SimpleDateFormat ymd = new SimpleDateFormat("yyyy/MM/dd");
return ymd.format(new Date());
}
/**
* 垫片文件存储规则
*
* @param id
* @param realPath
* @return
*/
public static String generateDianPianDir(String id, String realPath) {
return generateDianPianDir(id, realPath, getDatePathI());
}
public static String generateDianPianDir(String id, String realPath, String time) {
return StrUtil.concat(false, new String[] { realPath,"dianpian/", time, "/", id, "/" });
}
public static String replacePUrl(String originalUrl, String newIp, String newPort) {
// // 原始URL
// String originalUrl = "http://180.167.180.242:42085/live/flv-ShuChu_1_1.flv";
// // 新的IP和端口
// String newIp = "1.12.3.4";
// int newPort = 42333;
// 解析原始URL,获取路径部分
if(originalUrl == null){
return "";
}
String[] urlParts = originalUrl.split("://");
if (urlParts.length < 2) {
System.out.println("无效的URL格式");
return "";
}
String afterProtocol = urlParts[1];
String[] hostAndPath = afterProtocol.split("/", 2);
String path = "";
if (hostAndPath.length > 1) {
path = "/" + hostAndPath[1];
}
// 构建新的URL
String newUrl = "http://" + newIp + ":" + newPort + path;
System.out.println("替换后的URL: " + newUrl);
return newUrl;
}
}