Merge commit '4da9ea5dd5210674ccc3d20d470d337857182474' into develop

* commit '4da9ea5dd5210674ccc3d20d470d337857182474':
  增加临时文件目录配置
  增加忽略eclipse本地配置文件目录
  fix README
This commit is contained in:
ukid
2015-06-17 13:10:10 +08:00
9 changed files with 111 additions and 30 deletions

View File

@ -7,18 +7,25 @@ import java.io.InputStream;
public class FileUtils {
/**
* 创建临时文件
* @param inputStream
* @param name 文件名
* @param ext 扩展名
* @param tmpDirFile 临时文件夹目录
* @return
* @throws IOException
*/
public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException {
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
FileOutputStream fos = null;
try {
File tmpFile = File.createTempFile(name, '.' + ext);
File tmpFile;
if (tmpDirFile == null) {
tmpFile = File.createTempFile(name, '.' + ext);
} else {
tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile);
}
tmpFile.deleteOnExit();
fos = new FileOutputStream(tmpFile);
int read = 0;
@ -43,5 +50,17 @@ public class FileUtils {
}
}
}
/**
* 创建临时文件
* @param inputStream
* @param name 文件名
* @param ext 扩展名
* @return
* @throws IOException
*/
public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException {
return createTmpFile(inputStream, name, ext, null);
}
}

View File

@ -25,6 +25,18 @@ import java.util.regex.Pattern;
*
*/
public class MediaDownloadRequestExecutor implements RequestExecutor<File, String> {
private File tmpDirFile;
public MediaDownloadRequestExecutor() {
super();
}
public MediaDownloadRequestExecutor(File tmpDirFile) {
super();
this.tmpDirFile = tmpDirFile;
}
@Override
public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException {
@ -59,7 +71,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin
return null;
}
String[] name_ext = fileName.split("\\.");
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1]);
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
return localFile;
}