-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeleteFileSample.java
More file actions
63 lines (54 loc) · 2.59 KB
/
DeleteFileSample.java
File metadata and controls
63 lines (54 loc) · 2.59 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
import com.envisioniot.enos.iot_http_integration.HttpConnection;
import com.envisioniot.enos.iot_http_integration.message.IIntegrationCallback;
import com.envisioniot.enos.iot_http_integration.message.IntegrationResponse;
import com.envisioniot.enos.iot_mqtt_sdk.core.exception.EnvisionException;
import com.envisioniot.enos.sdk.data.DeviceInfo;
import com.google.gson.GsonBuilder;
/**
* @author :charlescai
* @date :2020-03-16
*/
public class DeleteFileSample {
// EnOS API Gateway URL and HTTP Integration Channel URL, which can be obtained from Environment Information page in EnOS Console
static final String API_GW_URL = "http://api_gw_url";
static final String INTEGRATION_CHANNEL_URL = "http://integration_channel_url";
// EnOS Application AccessKey and SecretKey, which can be obtain in Application Registration page in EnOS Console
static final String APP_KEY = "appKey";
static final String APP_SECRET = "appSecret";
// Device credentials, which can be obtained from Device Details page in EnOS Console
static final String ORG_ID = "orgId";
static final String ASSET_ID = "assetId";
static final String PRODUCT_KEY = "productKey";
static final String DEVICE_KEY = "deviceKey";
public static void main(String[] args) {
// Construct a http connection
HttpConnection connection = new HttpConnection.Builder(
INTEGRATION_CHANNEL_URL, API_GW_URL, APP_KEY, APP_SECRET, ORG_ID)
.build();
// fileUri is an enos scheme file uri
String fileUri = "enos-connect://xxx.txt";
DeviceInfo deviceInfo = new DeviceInfo().setAssetId(ASSET_ID);
try {
IntegrationResponse response = connection.deleteFile(deviceInfo, fileUri);
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(response));
} catch (EnvisionException e) {
e.printStackTrace();
}
// Asynchronously call the file delete request
try {
connection.deleteFile(deviceInfo, fileUri, new IIntegrationCallback() {
@Override
public void onResponse(IntegrationResponse response) {
System.out.println("receive response asynchronously");
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(response));
}
@Override
public void onFailure(Exception failure) {
failure.printStackTrace();
}
});
} catch (EnvisionException e) {
e.printStackTrace();
}
}
}