Allow customizing temp folder for file downloading

This commit is contained in:
xhh 2015-09-13 21:02:22 +08:00
parent 967c574f5b
commit 1ecb8a74c1
2 changed files with 42 additions and 2 deletions

View File

@ -49,6 +49,7 @@ public class ApiClient {
private boolean lenientOnJson = false; private boolean lenientOnJson = false;
private boolean debugging = false; private boolean debugging = false;
private Map<String, String> defaultHeaderMap = new HashMap<String, String>(); private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private String tempFolderPath = null;
private Map<String, Authentication> authentications; private Map<String, Authentication> authentications;
@ -363,6 +364,22 @@ public class ApiClient {
return this; return this;
} }
/**
* The path of temporary folder used to store downloaded files from endpoints
* with file response. The default value is <code>null</code>, i.e. using
* the system's default tempopary folder.
*
* @see https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File)
*/
public String getTempFolderPath() {
return tempFolderPath;
}
public ApiClient setTempFolderPath(String tempFolderPath) {
this.tempFolderPath = tempFolderPath;
return this;
}
/** /**
* Format the given parameter object into string. * Format the given parameter object into string.
*/ */
@ -590,7 +607,10 @@ public class ApiClient {
prefix = "download-"; prefix = "download-";
} }
if (tempFolderPath == null)
return File.createTempFile(prefix, suffix); return File.createTempFile(prefix, suffix);
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
} }
/** /**

View File

@ -49,6 +49,7 @@ public class ApiClient {
private boolean lenientOnJson = false; private boolean lenientOnJson = false;
private boolean debugging = false; private boolean debugging = false;
private Map<String, String> defaultHeaderMap = new HashMap<String, String>(); private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private String tempFolderPath = null;
private Map<String, Authentication> authentications; private Map<String, Authentication> authentications;
@ -362,6 +363,22 @@ public class ApiClient {
return this; return this;
} }
/**
* The path of temporary folder used to store downloaded files from endpoints
* with file response. The default value is <code>null</code>, i.e. using
* the system's default tempopary folder.
*
* @see https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File)
*/
public String getTempFolderPath() {
return tempFolderPath;
}
public ApiClient setTempFolderPath(String tempFolderPath) {
this.tempFolderPath = tempFolderPath;
return this;
}
/** /**
* Format the given parameter object into string. * Format the given parameter object into string.
*/ */
@ -589,7 +606,10 @@ public class ApiClient {
prefix = "download-"; prefix = "download-";
} }
if (tempFolderPath == null)
return File.createTempFile(prefix, suffix); return File.createTempFile(prefix, suffix);
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
} }
/** /**