代码拉取完成,页面将自动刷新
package cn.angs;
import java.io.*;
import java.util.Arrays;
/**
* ClassName: FileInfoExecutor.java
* Description:
*
* @author wangshun@cloudwalk.cn
* @version 1.0.0
* @date 2021/07/23 18:26
*/
public class FileInfoExecutor {
private static final byte[] MPG_4 = new byte[]{0x66, 0x74, 0x79, 0x70, 0x4D, 0x53, 0x4E, 0x56};
private static final byte[] MPG_4_V1 = new byte[]{0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6F, 0x6D};
private static final byte[] AVI_HEAD = new byte[]{0x52, 0x49, 0x46, 0x46};
private static final byte[] AVI_TAIL = new byte[]{0x41, 0x56, 0x49, 0x20, 0x4C, 0x49, 0x53, 0x54};
public static boolean isMp4(String path) {
byte[] read = read(path, 4, 11);
return Arrays.equals(read, MPG_4) || Arrays.equals(read, MPG_4_V1);
}
public static boolean isAvi(String path) {
byte[] head = read(path, 0, 3);
if (Arrays.equals(head, AVI_HEAD)) {
byte[] tail = read(path, 8, 15);
return Arrays.equals(tail, AVI_TAIL);
}
return false;
}
private static byte[] read(String path, int from, int to) {
byte[] result = new byte[to - from + 1];
try {
FileInputStream fis = new FileInputStream(path);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.skip(from);
bis.read(result, 0, to - from + 1);
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
System.out.println(isAvi("C:\\Users\\YCKJ2817\\Desktop\\测试\\1.avi"));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。