forked from lob/lob-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectTests.java
More file actions
67 lines (57 loc) · 2.21 KB
/
Copy pathObjectTests.java
File metadata and controls
67 lines (57 loc) · 2.21 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
57
58
59
60
61
62
63
64
65
66
67
import java.util.HashMap;
import java.util.Map;
import com.lob.Lob;
import com.lob.exception.LobException;
import com.lob.model.Object;
import com.lob.model.DeletedStatus;
import com.lob.model.ObjectCollection;
import java.io.*;
public class ObjectTests {
public static void main(String[] args) {
Lob.apiKey = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:";
String id = "obj_4241a46e01b4f892";
try {
Object o1 = Object.retrieve(id, Lob.apiKey);
System.out.println(o1);
Map<String, java.lang.Object> ObjectMap = new HashMap<String, java.lang.Object>();
ObjectMap.put("name", "GO BLUE");
ObjectMap.put("file", "@F:/Jimmy/goblue.pdf");
ObjectMap.put("quantity", 2);
ObjectMap.put("setting_id", 100);
ObjectMap.put("double_sided", 1);
Object o2 = Object.create(ObjectMap, Lob.apiKey);
System.out.println(o2);
DeletedStatus d1 = Object.delete(o2.getId(), Lob.apiKey);
System.out.println(d1);
Map<String, java.lang.Object> listParams = new HashMap<String, java.lang.Object>();
listParams.put("count", 2);
listParams.put("offset", 3);
ObjectCollection ac = Object.all(listParams, Lob.apiKey);
System.out.println(ac);
} catch (LobException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public static byte[] readFile(File file) throws IOException {
// Open file
RandomAccessFile f = new RandomAccessFile(file, "r");
try {
// Get and check length
long longlength = f.length();
int length = (int) longlength;
if (length != longlength)
throw new IOException("File size >= 2 GB");
// Read file and return data
byte[] data = new byte[length];
f.readFully(data);
return data;
} finally {
f.close();
}
}
}