Skip to content

Commit

Permalink
Regenerate client from commit 113773d of spec repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ci.datadog-api-spec committed Feb 3, 2021
1 parent 36931c2 commit d53b200
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 136 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.4.1.dev2",
"regenerated": "2021-02-03 08:38:29.208682",
"spec_repo_commit": "f02c467"
"regenerated": "2021-02-03 16:24:07.623332",
"spec_repo_commit": "113773d"
},
"v2": {
"apigentools_version": "1.4.1.dev2",
"regenerated": "2021-02-03 08:38:39.829272",
"spec_repo_commit": "f02c467"
"regenerated": "2021-02-03 16:24:15.926643",
"spec_repo_commit": "113773d"
}
}
}
66 changes: 0 additions & 66 deletions src/main/java/com/datadog/api/v1/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,6 @@ public ApiClient setDebugging(boolean debugging) {
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.
*
* @return Temp folder path
*/
public String getTempFolderPath() {
return tempFolderPath;
}

/**
* Set temp folder path
* @param tempFolderPath Temp folder path
Expand Down Expand Up @@ -1108,10 +1097,6 @@ public <T> T deserialize(Response response, GenericType<T> returnType) throws Ap
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.getRawType() == File.class) {
// Handle file downloading.
T file = (T) downloadFileFromResponse(response);
return file;
}

String contentType = null;
Expand All @@ -1125,57 +1110,6 @@ public <T> T deserialize(Response response, GenericType<T> returnType) throws Ap
return response.readEntity(returnType);
}

/**
* Download file from the given response.
* @param response Response
* @return File
* @throws ApiException If fail to read file content from response and write to disk
*/
public File downloadFileFromResponse(Response response) throws ApiException {
try {
File file = prepareDownloadFile(response);
Files.copy(response.readEntity(InputStream.class), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
return file;
} catch (IOException e) {
throw new ApiException(e);
}
}

public File prepareDownloadFile(Response response) throws IOException {
String filename = null;
String contentDisposition = (String) response.getHeaders().getFirst("Content-Disposition");
if (contentDisposition != null && !"".equals(contentDisposition)) {
// Get filename from the Content-Disposition header.
Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
Matcher matcher = pattern.matcher(contentDisposition);
if (matcher.find())
filename = matcher.group(1);
}

String prefix;
String suffix = null;
if (filename == null) {
prefix = "download-";
suffix = "";
} else {
int pos = filename.lastIndexOf('.');
if (pos == -1) {
prefix = filename + "-";
} else {
prefix = filename.substring(0, pos) + "-";
suffix = filename.substring(pos);
}
// File.createTempFile requires the prefix to be at least three characters long
if (prefix.length() < 3)
prefix = "download-";
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
}

/**
* Invoke API by sending HTTP request with the given options.
*
Expand Down
66 changes: 0 additions & 66 deletions src/main/java/com/datadog/api/v2/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,6 @@ public ApiClient setDebugging(boolean debugging) {
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.
*
* @return Temp folder path
*/
public String getTempFolderPath() {
return tempFolderPath;
}

/**
* Set temp folder path
* @param tempFolderPath Temp folder path
Expand Down Expand Up @@ -925,10 +914,6 @@ public <T> T deserialize(Response response, GenericType<T> returnType) throws Ap
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.getRawType() == File.class) {
// Handle file downloading.
T file = (T) downloadFileFromResponse(response);
return file;
}

String contentType = null;
Expand All @@ -942,57 +927,6 @@ public <T> T deserialize(Response response, GenericType<T> returnType) throws Ap
return response.readEntity(returnType);
}

/**
* Download file from the given response.
* @param response Response
* @return File
* @throws ApiException If fail to read file content from response and write to disk
*/
public File downloadFileFromResponse(Response response) throws ApiException {
try {
File file = prepareDownloadFile(response);
Files.copy(response.readEntity(InputStream.class), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
return file;
} catch (IOException e) {
throw new ApiException(e);
}
}

public File prepareDownloadFile(Response response) throws IOException {
String filename = null;
String contentDisposition = (String) response.getHeaders().getFirst("Content-Disposition");
if (contentDisposition != null && !"".equals(contentDisposition)) {
// Get filename from the Content-Disposition header.
Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
Matcher matcher = pattern.matcher(contentDisposition);
if (matcher.find())
filename = matcher.group(1);
}

String prefix;
String suffix = null;
if (filename == null) {
prefix = "download-";
suffix = "";
} else {
int pos = filename.lastIndexOf('.');
if (pos == -1) {
prefix = filename + "-";
} else {
prefix = filename.substring(0, pos) + "-";
suffix = filename.substring(pos);
}
// File.createTempFile requires the prefix to be at least three characters long
if (prefix.length() < 3)
prefix = "download-";
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
}

/**
* Invoke API by sending HTTP request with the given options.
*
Expand Down

0 comments on commit d53b200

Please sign in to comment.