智慧城市 v1.2.1版本的 MD5 值为:d4aeacb5153a2710d0b6882be5dd2b15
以下内容为反编译后的 StcSliceCompleteRequest.java 源代码,内容仅作参考
package io.rong.imlib.filetransfer;
import android.net.Uri;
import android.os.SystemClock;
import android.util.Xml;
import io.rong.common.RLog;
import io.rong.common.fwlog.FwLog;
import io.rong.imlib.common.NetUtils;
import io.rong.imlib.filetransfer.FtConst;
import io.rong.imlib.filetransfer.upload.StcSliceUploadResult;
import io.rong.imlib.navigation.NavigationCacheHelper;
import io.rong.message.ContactNotificationMessage;
import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xmlpull.v1.XmlSerializer;
public class StcSliceCompleteRequest extends Request {
private static final String Boundary = "526f6e67436c6f756498";
private static final String TAG = ContactNotificationMessage.CONTACT_OPERATION_REQUEST;
private List<StcSliceUploadResult> mList;
private SliceRequestCallBack mSliceRequestCallBack;
private String uploadId;
@Override
protected boolean enableEndBoundary() {
return false;
}
@Override
public String getBoundary() {
return Boundary;
}
@Override
public String getContentType() {
return "application/xml";
}
@Override
public String getFormData() {
return "";
}
@Override
public String getUploadPlatformTag() {
return "SS3";
}
@Override
public String getUploadedUrl(String str) {
return null;
}
public StcSliceCompleteRequest(Configuration configuration, SliceRequestCallBack sliceRequestCallBack, List<StcSliceUploadResult> list) {
super(configuration, sliceRequestCallBack);
this.mSliceRequestCallBack = sliceRequestCallBack;
this.mList = list;
if (list == null || list.size() <= 0) {
return;
}
this.uploadId = this.mList.get(0).getUploadId();
}
@Override
public FtConst.MimeType getMimeType() {
return this.mimeType;
}
@Override
public void sendRequest() {
DataOutputStream dataOutputStream;
final int responseCode;
BufferedInputStream bufferedInputStream;
final long elapsedRealtime;
final String host;
RLog.d("upload", "completeRequest auth start");
if (!this.requestCallBack.doAuth(this)) {
this.requestCallBack.onError(this, 30002);
return;
}
RLog.d("upload", "completeRequest auth finish");
BufferedInputStream bufferedInputStream2 = null;
try {
try {
} catch (Throwable th) {
th = th;
}
} catch (Exception e) {
e = e;
dataOutputStream = null;
} catch (Throwable th2) {
th = th2;
dataOutputStream = null;
}
if (this.method.equals("POST")) {
FwLog.write(3, 1, FwLog.LogTag.L_MEDIA_UPLOAD_T.getTag(), "id|type", this.uploadId, getUploadPlatformTag());
long elapsedRealtime2 = SystemClock.elapsedRealtime();
this.conn = NetUtils.createURLConnection(this.serverIp);
this.conn.setDoOutput(true);
this.conn.setDoInput(true);
this.conn.setUseCaches(false);
this.conn.setRequestMethod(this.method);
this.conn.setConnectTimeout(120000);
headers(this.conn);
this.conn.setRequestProperty("Content-Type", getContentType());
this.conn.connect();
dataOutputStream = new DataOutputStream(this.conn.getOutputStream());
try {
setXml(this.mList, dataOutputStream);
responseCode = this.conn.getResponseCode();
io.rong.common.rlog.RLog.d("upload", "upload end finish,responseCode:" + responseCode);
bufferedInputStream = new BufferedInputStream(this.conn.getInputStream());
} catch (Exception e2) {
e = e2;
}
try {
FwLog.write(3, 1, FwLog.LogTag.L_MEDIA_UPLOAD_R.getTag(), "id|type|code", this.uploadId, getUploadPlatformTag(), Integer.valueOf(responseCode));
elapsedRealtime = SystemClock.elapsedRealtime() - elapsedRealtime2;
host = Uri.parse(this.serverIp).getHost();
} catch (Exception e3) {
e = e3;
bufferedInputStream2 = bufferedInputStream;
this.requestCallBack.onError(this, 30002);
FwLog.write(2, 1, FwLog.LogTag.L_MEDIA_S.getTag(), "stacks", FwLog.stackToString(e));
closeInputStream(bufferedInputStream2);
closeOutputStream(dataOutputStream);
disconnect(this.conn);
} catch (Throwable th3) {
th = th3;
bufferedInputStream2 = bufferedInputStream;
closeInputStream(bufferedInputStream2);
closeOutputStream(dataOutputStream);
disconnect(this.conn);
throw th;
}
if (responseCode >= 200 && responseCode < 300) {
new Thread(new Runnable() {
@Override
public void run() {
FwLog.write(-1, 1, FwLog.LogTag.L_MEDIA_STATISTICS_S.getTag(), "id|code|type|size|duration|host|ip", StcSliceCompleteRequest.this.uploadId, Integer.valueOf(responseCode), StcSliceCompleteRequest.this.getUploadPlatformTag(), Long.valueOf(StcSliceCompleteRequest.this.fileLength), Long.valueOf(elapsedRealtime), host, NavigationCacheHelper.queryRequestIP(host));
}
}).start();
RLog.d("upload", "completeRequest request finish");
this.requestCallBack.onComplete(getUrl(bufferedInputStream));
bufferedInputStream2 = bufferedInputStream;
closeInputStream(bufferedInputStream2);
closeOutputStream(dataOutputStream);
disconnect(this.conn);
}
RLog.e("upload", "completeRequest responseCode error:" + responseCode);
FwLog.write(-1, 1, FwLog.LogTag.L_MEDIA_STATISTICS_S.getTag(), "id|code|type|host", this.uploadId, Integer.valueOf(responseCode), getUploadPlatformTag(), host);
this.requestCallBack.onError(this, responseCode);
bufferedInputStream2 = bufferedInputStream;
closeInputStream(bufferedInputStream2);
closeOutputStream(dataOutputStream);
disconnect(this.conn);
}
dataOutputStream = null;
closeInputStream(bufferedInputStream2);
closeOutputStream(dataOutputStream);
disconnect(this.conn);
}
@Override
protected void headers(HttpURLConnection httpURLConnection) {
httpURLConnection.setRequestProperty("Authorization", this.stcAuthorization);
httpURLConnection.setRequestProperty("x-amz-content-sha256", this.stcContentSha256);
httpURLConnection.setRequestProperty("x-amz-date", this.stcDate);
}
private void setXml(List<StcSliceUploadResult> list, OutputStream outputStream) throws Exception {
XmlSerializer newSerializer = Xml.newSerializer();
newSerializer.setOutput(outputStream, "utf-8");
newSerializer.startDocument("utf-8", true);
newSerializer.startTag(null, "CompleteMultipartUpload");
newSerializer.attribute(null, "xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
for (StcSliceUploadResult stcSliceUploadResult : list) {
newSerializer.startTag(null, "Part");
newSerializer.startTag(null, "ETag");
newSerializer.text(stcSliceUploadResult.getETag());
newSerializer.endTag(null, "ETag");
newSerializer.startTag(null, "PartNumber");
newSerializer.text(String.valueOf(stcSliceUploadResult.getPartNumber()));
newSerializer.endTag(null, "PartNumber");
newSerializer.endTag(null, "Part");
}
newSerializer.endTag(null, "CompleteMultipartUpload");
newSerializer.endDocument();
outputStream.flush();
}
private String getUrl(InputStream inputStream) throws Exception {
SAXParser newSAXParser = SAXParserFactory.newInstance().newSAXParser();
SliceEndUploadResultParser sliceEndUploadResultParser = new SliceEndUploadResultParser();
newSAXParser.parse(inputStream, sliceEndUploadResultParser);
return sliceEndUploadResultParser.getUrl();
}
public String getUploadId() {
return this.uploadId;
}
}