The official Java SDK for the Zamzar API.
zamzar-java
makes it easy to convert files between different formats as part of your Java applications.
Jump to:
- Before you begin, signup for a Zamzar API Account or retrieve your existing API Key from the Zamzar Developers Homepage
- Java 8 and later.
Add this dependency to your project's POM:
<dependency>
<groupId>com.zamzar</groupId>
<artifactId>zamzar-java</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Add this dependency to your project's build file:
implementation "com.zamzar:zamzar-java:1.0.0"
Please follow the installation instructions and execute the following Java code:
import com.zamzar.api.ZamzarClient;
import com.zamzar.api.invoker.ApiException;
import java.io.File;
public class GettingStarted {
public static void main(String[] args) throws ApiException {
// Signup for a Zamzar API Account or retrieve your existing API Key from https://developers.zamzar.com
ZamzarClient zamzar = new ZamzarClient("YOUR_API_KEY_GOES_HERE");
// Converts /tmp/example.docx to /tmp/example.pdf
zamzar
.convert(new File("/tmp/example.docx"), "pdf") // uploads and converts your file
.store(new File("/tmp/")) // downloads the converted file
.deleteAllFiles(); // removes your files (example.docx and example.pdf) from Zamzar's servers
}
}
See the examples to learn more about how to use the Zamzar Java library.
Whilst developing your application, you can use the Zamzar sandbox environment to test your code without consuming production credits:
import com.zamzar.api.ZamzarClient;
import com.zamzar.api.ZamzarEnvironment;
ZamzarClient zamzar = new ZamzarClient("YOUR_API_KEY_GOES_HERE", ZamzarEnvironment.SANDBOX);
The Zamzar Java library uses the production environment by default, but you can also specify it explicitly:
import com.zamzar.api.ZamzarClient;
import com.zamzar.api.ZamzarEnvironment;
ZamzarClient zamzar = new ZamzarClient("YOUR_API_KEY_GOES_HERE", ZamzarEnvironment.PRODUCTION);
By default, the Zamzar Java library does not log HTTP requests and responses. To enable logging, configure a LoggingInterceptor; such as in this example.
The Zamzar Java library will automatically:
- time out long-running requests
- retry requests that fail or time out
The default settings are defined in ZamzarClient#getDefaultTransportBuilder().
To override these defaults, configure your
own okhttp3.OkHttpClient and pass it to
the ZamzarClient
constructor:
OkHttpClient customHttpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.addInterceptor(/* your own retry interceptor */)
.build();
ZamzarClient zamzar = new ZamzarClient("YOUR_API_KEY_GOES_HERE", customTransport);
Code Samples - Copy/Paste from examples which demonstrate all key areas of functionality.
Developer Docs - For more information about API operations, parameters, and responses. Use this if you need additional context on all areas of functionality.