This commit is contained in:
jinyu
2015-07-23 18:36:48 +08:00
parent ed4cb18c00
commit 4c8bd3dcd2
12 changed files with 123 additions and 168 deletions
@@ -26,8 +26,8 @@ import com.foxinmy.weixin4j.http.ContentType;
public enum MediaType {
image(ContentType.IMAGE_JPG), voice(ContentType.AUDIO_MP3), video(
ContentType.VIDEO_MPEG4), thumb(ContentType.IMAGE_JPG), file(
ContentType.APPLICATION_OCTET_STREAM), news(
ContentType.APPLICATION_OCTET_STREAM);
ContentType.MULTIPART_FORM_DATA), news(
ContentType.MULTIPART_FORM_DATA);
MediaType(ContentType contentType) {
this.contentType = contentType;
@@ -1,8 +1,7 @@
package com.foxinmy.weixin4j.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -93,16 +92,14 @@ public class FileUtil {
/**
* 获取文件类型
*
* @param file
* @param is
* @return
*/
public static String getFileType(File file) {
String fileType = "unknown";
FileInputStream fis = null;
public static String getFileType(InputStream is) {
String fileType = "file";
try {
fis = new FileInputStream(file);
byte[] b = new byte[10];
int t = fis.read(b, 0, b.length);
int t = is.read(b, 0, b.length);
if (t > 0) {
String fileCode = bytesToHexString(b).toLowerCase();
Iterator<String> keyIter = FILE_TYPE_MAP.keySet().iterator();
@@ -115,11 +112,11 @@ public class FileUtil {
}
}
} catch (IOException e) {
e.printStackTrace();
;
} finally {
if (fis != null) {
if (is != null) {
try {
fis.close();
is.close();
} catch (IOException ignore) {
;
}