System.out.println("Running report job.");
// Run report job.
long reportJobId = reportService.runReportJob(reportJob).getId();
final ReportUtils reportUtils = new ReportUtils(reportService, reportJobId);
// Change to your file location.
final String gzCsvPath = "/path/to/filename.csv.gz";
// Change to use synchronous or asynchronous downloading.
boolean useSynchronous = true;
if (useSynchronous) {
// Download gzipped CSV synchronously.
try {
System.out.println("Waiting for report to finish.");
if (reportUtils.waitForReportReady()) {
System.out.print("Downloading report to " + gzCsvPath + "...");
reportUtils.downloadReport(ExportFormat.CSV_DUMP, gzCsvPath);
System.out.println("done.");
} else {
System.out.println("The report failed to schedule.");
}
} catch (IOException e) {
System.out.println("Report did not download for reason: " + e.getMessage());
e.printStackTrace();
}
} else {
// Download gzipped CSV asynchronously.
Thread reportThread = reportUtils.whenReportReady(new ReportCallback() {
public void onSuccess() {
try {
System.out.print("Downloading report to " + gzCsvPath + "...");
reportUtils.downloadReport(ExportFormat.CSV_DUMP, gzCsvPath);
System.out.println("done.");
} catch (IOException e) {
System.out.println("Report did not download for reason: " + e.getMessage());
e.printStackTrace();
}