-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateHashes.java
More file actions
40 lines (33 loc) · 1.33 KB
/
Copy pathCreateHashes.java
File metadata and controls
40 lines (33 loc) · 1.33 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
import com.api2convert.Api2Convert;
import com.api2convert.ConversionResult;
import com.api2convert.ConvertOptions;
import com.api2convert.http.Config;
import java.nio.charset.StandardCharsets;
/**
* Guide: Create Hashes — compute a checksum (SHA-256) of a file.
*
* <p>Run (SDK + Jackson on the classpath):
* <pre>
* API2CONVERT_API_KEY=your-key java -cp "target/classes:libs/*" CreateHashes
* </pre>
*/
public final class CreateHashes {
private static final String REMOTE_ZIP =
"https://example-files.online-convert.com/archive/zip/example.zip";
public static void main(String[] args) {
Api2Convert client = newClient();
ConversionResult result = client.convert(REMOTE_ZIP, "sha256", null,
new ConvertOptions().category("hash"));
// The output holds the computed digest — save it, and print it.
System.out.println("Saved: " + result.save("./"));
System.out.println("Digest: " + new String(result.contents(), StandardCharsets.UTF_8).trim());
}
private static Api2Convert newClient() {
String base = System.getenv("API2CONVERT_BASE_URL");
return base != null && !base.isEmpty()
? new Api2Convert("", Config.builder().baseUrl(base).build())
: new Api2Convert("");
}
private CreateHashes() {
}
}