Copyright (c) 2012 CloudMine LLC, http://cloudmine.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software")...
If you think the Android project cloudmine-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.cloudmine.api.rest;
//fromwww.java2s.comimport com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.cloudmine.api.CMApiCredentials;
import com.cloudmine.api.CMFile;
import com.cloudmine.api.CMSessionToken;
import com.cloudmine.api.rest.options.CMServerFunction;
import com.cloudmine.api.rest.response.FileLoadResponse;
import me.cloudmine.annotations.Expand;
import me.cloudmine.annotations.Optional;
import java.util.Map;
/**
* A Request for loading a CMFile, based on its id
* <br>
* Copyright CloudMine LLC. All rights reserved<br>
* See LICENSE file included with SDK for details.
*/publicclass BaseFileLoadRequest extends CloudMineRequest<FileLoadResponse> {
publicstaticfinalint REQUEST_TYPE = 401;
staticfinal String BASE_ENDPOINT = "/binary";
staticfinal CMURLBuilder BASE_URL = new CMURLBuilder(BASE_ENDPOINT, true);
privatefinal String fileId;
/**
* Create a new BaseFileLoadRequest for loading a file based on its id
* @param fileId the id of the file to load
* @param sessionToken optional; if specified, it is assumed the file is user level
* @param serverFunction
* @param successListener
* @param errorListener
*/
@Expand
public BaseFileLoadRequest(String fileId, @Optional CMSessionToken sessionToken, @Optional CMApiCredentials apiCredentials, @Optional CMServerFunction serverFunction, Response.Listener<FileLoadResponse> successListener, @Optional Response.ErrorListener errorListener) {
super(Method.GET, BASE_URL.copy().user(sessionToken).addKey(fileId).serverFunction(serverFunction).asUrlString(), null, sessionToken, apiCredentials, successListener, errorListener);
this.fileId = fileId;
}
@Override
protected Response<FileLoadResponse> parseNetworkResponse(NetworkResponse networkResponse) {
Map<String, String> headers = networkResponse.headers;
String fileType = (headers == null) ?
null :
headers.get("Content-Type");
CMFile file = new CMFile(networkResponse.data, fileId, fileType);
return Response.success(
new FileLoadResponse(
file, networkResponse.statusCode), getCacheEntry());
}
@Override
publicint getRequestType() {
return REQUEST_TYPE;
}
}