If you think the Android project Android-SDK 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
/*
* Copyright (C) 2014. BaasBox/*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/package com.baasbox.android;
import com.baasbox.android.net.HttpRequest;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import java.io.IOException;
/**
* Created by Andrea Tortorella on 17/01/14.
*/class StreamRequest extends NetworkTask<BaasStream> {
// ------------------------------ FIELDS ------------------------------
privatefinal String id;
privatefinal HttpRequest request;
// --------------------------- CONSTRUCTORS ---------------------------
protected StreamRequest(BaasBox box, String resource, String id, String sizeSpec, int sizeId) {
super(box, RequestOptions.DEFAULT, null);
this.id = id;
String endpoint = box.requestFactory.getEndpoint("{}/{}", resource, id);
RequestFactory.Param param = null;
if (sizeSpec != null) {
param = new RequestFactory.Param("resize", sizeSpec);
} elseif (sizeId >= 0) {
param = new RequestFactory.Param("sizeId", Integer.toString(sizeId));
}
if (param != null) {
request = box.requestFactory.get(endpoint, param);
} else {
request = box.requestFactory.get(endpoint);
}
}
// -------------------------- OTHER METHODS --------------------------
@Override
protected BaasStream getFromCache(BaasBox box) throws BaasException {
return box.mCache.getStream(id);
}
@Override
protected BaasStream onOk(int status, HttpResponse response, BaasBox box) throws BaasException {
boolean close = true;
HttpEntity entity = null;
try {
entity = response.getEntity();
BaasStream stream = new BaasStream(id, entity);
close = false;
return stream;
} catch (IOException e) {
thrownew BaasException(e);
} finally {
if (close) {
try {
if (entity != null) {
entity.consumeContent();
}
} catch (IOException e) {
// ignored
}
}
}
}
@Override
protected HttpRequest request(BaasBox box) {
return request;
}
}