forked from ConvertAPI/convertapi-library-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversionResultFile.java
More file actions
56 lines (46 loc) · 1.61 KB
/
ConversionResultFile.java
File metadata and controls
56 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.convertapi;
import com.convertapi.model.ConversionResponseFile;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.CompletableFuture;
public class ConversionResultFile {
private final ConversionResponseFile conversionResponseFile;
public ConversionResultFile(ConversionResponseFile conversionResponseFile) {
this.conversionResponseFile = conversionResponseFile;
}
@SuppressWarnings("WeakerAccess")
public String getName() {
return conversionResponseFile.FileName;
}
public int getSize() {
return conversionResponseFile.FileSize;
}
@SuppressWarnings("WeakerAccess")
public String getUrl() {
return conversionResponseFile.Url;
}
@SuppressWarnings("WeakerAccess")
public CompletableFuture<InputStream> asStream() {
return Http.requestGet(getUrl());
}
@SuppressWarnings("WeakerAccess")
public CompletableFuture<Path> saveFile(Path path) {
return asStream().thenApplyAsync(s -> {
try {
Path filePath = Files.isDirectory(path) ? Paths.get(path.toString(), getName()) : path;
Files.copy(s, filePath, StandardCopyOption.REPLACE_EXISTING);
return filePath;
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
@SuppressWarnings("WeakerAccess")
public CompletableFuture delete() {
return Http.requestDelete(getUrl());
}
}