Skip to content

Commit d290c5d

Browse files
committed
sample update
1 parent 975f350 commit d290c5d

33 files changed

+396
-792
lines changed

sample/src/main/java/com/compdfkit/AddWatermark.java

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,18 @@ public static void addWatermarkText() throws FileNotFoundException {
6565
String fileKey = uploadFileResult.getFileKey();
6666
// perform tasks
6767
client.executeTask(taskId);
68-
// create a ScheduledExecutorService with a fixed thread pool
69-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
70-
// create an AtomicReference to hold the future
71-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
72-
// schedule a task to check the task status at a fixed rate
73-
futureRef.set(executor.scheduleAtFixedRate(() -> {
74-
// get task processing information
75-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
76-
// determine whether the task status is "TaskFinish"
77-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
78-
System.out.println(taskInfo);
79-
// get the final file processing information
80-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
81-
System.out.println(fileInfo);
82-
// if the task is finished, cancel the scheduled task
83-
futureRef.get().cancel(false);
84-
}
85-
}, 0, 5, TimeUnit.SECONDS));
86-
// schedule a task to cancel the scheduled task after 15 minutes
87-
executor.schedule(() -> {
88-
futureRef.get().cancel(false);
89-
}, 15, TimeUnit.MINUTES);
90-
// shutdown the executor
91-
executor.shutdown();
68+
// get task processing information
69+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
70+
// determine whether the task status is "TaskFinish"
71+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
72+
System.out.println(taskInfo);
73+
// get the final file processing information
74+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
75+
System.out.println(fileInfo);
76+
// if the task is finished, cancel the scheduled task
77+
}else {
78+
System.out.println("Task incomplete processing");
79+
}
9280
}
9381

9482
public static void addWatermarkImage() throws IOException {
@@ -116,30 +104,18 @@ public static void addWatermarkImage() throws IOException {
116104
String fileKey = uploadFileResult.getFileKey();
117105
// perform tasks
118106
client.executeTask(taskId);
119-
// create a ScheduledExecutorService with a fixed thread pool
120-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
121-
// create an AtomicReference to hold the future
122-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
123-
// schedule a task to check the task status at a fixed rate
124-
futureRef.set(executor.scheduleAtFixedRate(() -> {
125-
// get task processing information
126-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
127-
// determine whether the task status is "TaskFinish"
128-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
129-
System.out.println(taskInfo);
130-
// get the final file processing information
131-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
132-
System.out.println(fileInfo);
133-
// if the task is finished, cancel the scheduled task
134-
futureRef.get().cancel(false);
135-
}
136-
}, 0, 5, TimeUnit.SECONDS));
137-
// schedule a task to cancel the scheduled task after 15 minutes
138-
executor.schedule(() -> {
139-
futureRef.get().cancel(false);
140-
}, 15, TimeUnit.MINUTES);
141-
// shutdown the executor
142-
executor.shutdown();
107+
// get task processing information
108+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
109+
// determine whether the task status is "TaskFinish"
110+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
111+
System.out.println(taskInfo);
112+
// get the final file processing information
113+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
114+
System.out.println(fileInfo);
115+
// if the task is finished, cancel the scheduled task
116+
}else {
117+
System.out.println("Task incomplete processing");
118+
}
143119
}
144120

145121
}

sample/src/main/java/com/compdfkit/CSVToPDF.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void csvToPDF() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

sample/src/main/java/com/compdfkit/DeleteWatermark.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void deleteWatermark() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

sample/src/main/java/com/compdfkit/ExcelToPDF.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void excelToPDF() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

sample/src/main/java/com/compdfkit/FormRecognizer.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,18 @@ public static void formRecognizer() throws FileNotFoundException {
5050
String fileKey = uploadFileResult.getFileKey();
5151
// perform tasks
5252
client.executeTask(taskId);
53-
// create a ScheduledExecutorService with a fixed thread pool
54-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
55-
// create an AtomicReference to hold the future
56-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
57-
// schedule a task to check the task status at a fixed rate
58-
futureRef.set(executor.scheduleAtFixedRate(() -> {
59-
// get task processing information
60-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
61-
// determine whether the task status is "TaskFinish"
62-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
63-
System.out.println(taskInfo);
64-
// get the final file processing information
65-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
66-
System.out.println(fileInfo);
67-
// if the task is finished, cancel the scheduled task
68-
futureRef.get().cancel(false);
69-
}
70-
}, 0, 5, TimeUnit.SECONDS));
71-
// schedule a task to cancel the scheduled task after 15 minutes
72-
executor.schedule(() -> {
73-
futureRef.get().cancel(false);
74-
}, 15, TimeUnit.MINUTES);
75-
// shutdown the executor
76-
executor.shutdown();
53+
// get task processing information
54+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
55+
// determine whether the task status is "TaskFinish"
56+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
57+
System.out.println(taskInfo);
58+
// get the final file processing information
59+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
60+
System.out.println(fileInfo);
61+
// if the task is finished, cancel the scheduled task
62+
}else {
63+
System.out.println("Task incomplete processing");
64+
}
7765
}
7866

7967
}

sample/src/main/java/com/compdfkit/HtmlToPDF.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void htmlToPDF() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

sample/src/main/java/com/compdfkit/ImageSharpeningEnhancement.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void imageSharpeningEnhancement() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

sample/src/main/java/com/compdfkit/LayoutAnalysis.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,18 @@ public static void layoutAnalysis() throws FileNotFoundException {
4949
String fileKey = uploadFileResult.getFileKey();
5050
// perform tasks
5151
client.executeTask(taskId);
52-
// create a ScheduledExecutorService with a fixed thread pool
53-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
54-
// create an AtomicReference to hold the future
55-
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
56-
// schedule a task to check the task status at a fixed rate
57-
futureRef.set(executor.scheduleAtFixedRate(() -> {
58-
// get task processing information
59-
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
60-
// determine whether the task status is "TaskFinish"
61-
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
62-
System.out.println(taskInfo);
63-
// get the final file processing information
64-
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
65-
System.out.println(fileInfo);
66-
// if the task is finished, cancel the scheduled task
67-
futureRef.get().cancel(false);
68-
}
69-
}, 0, 5, TimeUnit.SECONDS));
70-
// schedule a task to cancel the scheduled task after 15 minutes
71-
executor.schedule(() -> {
72-
futureRef.get().cancel(false);
73-
}, 15, TimeUnit.MINUTES);
74-
// shutdown the executor
75-
executor.shutdown();
52+
// get task processing information
53+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
54+
// determine whether the task status is "TaskFinish"
55+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
56+
System.out.println(taskInfo);
57+
// get the final file processing information
58+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
59+
System.out.println(fileInfo);
60+
// if the task is finished, cancel the scheduled task
61+
}else {
62+
System.out.println("Task incomplete processing");
63+
}
7664
}
7765

7866
}

0 commit comments

Comments
 (0)