Skip to content

Commit 1ecb8a7

Browse files
committed
Allow customizing temp folder for file downloading
1 parent 967c574 commit 1ecb8a7

File tree

2 files changed

+42
-2
lines changed
  • modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson
  • samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client

2 files changed

+42
-2
lines changed

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ApiClient {
4949
private boolean lenientOnJson = false;
5050
private boolean debugging = false;
5151
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
52+
private String tempFolderPath = null;
5253
5354
private Map<String, Authentication> authentications;
5455
@@ -363,6 +364,22 @@ public class ApiClient {
363364
return this;
364365
}
365366

367+
/**
368+
* The path of temporary folder used to store downloaded files from endpoints
369+
* with file response. The default value is <code>null</code>, i.e. using
370+
* the system's default tempopary folder.
371+
*
372+
* @see https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File)
373+
*/
374+
public String getTempFolderPath() {
375+
return tempFolderPath;
376+
}
377+
378+
public ApiClient setTempFolderPath(String tempFolderPath) {
379+
this.tempFolderPath = tempFolderPath;
380+
return this;
381+
}
382+
366383
/**
367384
* Format the given parameter object into string.
368385
*/
@@ -590,7 +607,10 @@ public class ApiClient {
590607
prefix = "download-";
591608
}
592609

593-
return File.createTempFile(prefix, suffix);
610+
if (tempFolderPath == null)
611+
return File.createTempFile(prefix, suffix);
612+
else
613+
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
594614
}
595615

596616
/**

samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ApiClient {
4949
private boolean lenientOnJson = false;
5050
private boolean debugging = false;
5151
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
52+
private String tempFolderPath = null;
5253

5354
private Map<String, Authentication> authentications;
5455

@@ -362,6 +363,22 @@ public ApiClient setDebugging(boolean debugging) {
362363
return this;
363364
}
364365

366+
/**
367+
* The path of temporary folder used to store downloaded files from endpoints
368+
* with file response. The default value is <code>null</code>, i.e. using
369+
* the system's default tempopary folder.
370+
*
371+
* @see https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File)
372+
*/
373+
public String getTempFolderPath() {
374+
return tempFolderPath;
375+
}
376+
377+
public ApiClient setTempFolderPath(String tempFolderPath) {
378+
this.tempFolderPath = tempFolderPath;
379+
return this;
380+
}
381+
365382
/**
366383
* Format the given parameter object into string.
367384
*/
@@ -589,7 +606,10 @@ public File prepareDownloadFile(Response response) throws IOException {
589606
prefix = "download-";
590607
}
591608

592-
return File.createTempFile(prefix, suffix);
609+
if (tempFolderPath == null)
610+
return File.createTempFile(prefix, suffix);
611+
else
612+
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
593613
}
594614

595615
/**

0 commit comments

Comments
 (0)