Commit 168b544f authored by yanzg's avatar yanzg

SQL层级处理的支持

parent 62dfaa50
......@@ -2,6 +2,9 @@ package com.yanzuoguang.util.helper;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* 登录相关函数
......@@ -10,6 +13,18 @@ import java.io.*;
*/
public class FileHelper {
/**
* 获取文件类型
*
* @param file 来源文件
* @return
* @throws IOException
*/
public static String getMimeType(String file) throws IOException {
Path path = Paths.get(file);
String contentType = contentType = Files.probeContentType(path);
return contentType;
}
/**
* 创建目录
......
package com.yanzuoguang.util;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.FileHelper;
import net.coobird.thumbnailator.Thumbnails;
import javax.imageio.IIOImage;
......@@ -24,6 +26,34 @@ public class ImageHelper {
public static final float DEFAULT_SIZE = 1f;
public static final float DEFAULT_QUALITY = 1f;
public static final int MEDIA_TYPE_IMAGE = 0;
public static final int MEDIA_TYPE_VIDEO = 1;
public static final int MEDIA_TYPE_AUDIO = 2;
/**
* 获取文件媒体类型
*
* @param file
* @return
* @throws IOException
*/
public static int getMediaType(String file) throws IOException {
String mimeType = FileHelper.getMimeType(file);
if (mimeType == null) {
throw new RuntimeException("不能识别文件类型" + file);
}
// System.out.println(mimeType);
if (mimeType.startsWith("video/")) {
return MEDIA_TYPE_VIDEO;
} else if (mimeType.startsWith("audio/")) {
return MEDIA_TYPE_AUDIO;
} else if (mimeType.startsWith("image/")) {
return MEDIA_TYPE_IMAGE;
} else {
throw new RuntimeException("文件类型不为图片、音频、视频");
}
}
/**
* 压缩图片
*
......
package helper;
import com.yanzuoguang.util.ImageHelper;
import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.thread.RunnableListAuto;
import it.sauronsoftware.jave.Encoder;
......@@ -18,6 +19,14 @@ public class TestMediaHelper {
public float[] quotes = new float[]{1f, 1f, 0.5f, 0.25f, 0.5f, 0.25f};
@Test
public void testMediaType() throws EncoderException, IOException {
System.out.println("100M.mp4 " + ImageHelper.getMediaType(getFile("100M.mp4")));
System.out.println("100M.mp4.jpg " + ImageHelper.getMediaType(getFile("100M.mp4.jpg")));
System.out.println("xuziming.mp4 " + ImageHelper.getMediaType(getFile("xuziming.mp4")));
System.out.println("z001594372388232a3017ad69c82a342.MOV " + ImageHelper.getMediaType(getFile("z001594372388232a3017ad69c82a342.MOV")));
}
@Test
public void printEncoding() throws EncoderException {
Encoder encoder = new Encoder();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment