正在查看: 新暖心缘 v8.1.1 应用的 StreamingManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 新暖心缘 v8.1.1 应用的 StreamingManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.qiniu.streaming;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Client;
import com.qiniu.http.Response;
import com.qiniu.streaming.model.ActivityRecords;
import com.qiniu.streaming.model.StreamAttribute;
import com.qiniu.streaming.model.StreamListing;
import com.qiniu.streaming.model.StreamStatus;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlSafeBase64;
import java.util.Iterator;
public final class StreamingManager {
private final String apiServer;
private final Auth auth;
private final Client client;
private final String hub;
public class ListIterator implements Iterator<String[]> {
private final boolean live;
private String prefix;
private String marker = null;
private QiniuException exception = null;
public ListIterator(boolean z7, String str) {
this.live = z7;
this.prefix = str;
}
public QiniuException exception() {
return this.exception;
}
@Override
public boolean hasNext() {
return this.exception == null && !"".equals(this.marker);
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
@Override
public String[] next() {
try {
StreamListing listStreams = StreamingManager.this.listStreams(this.live, this.prefix, this.marker);
String str = listStreams.marker;
if (str == null) {
str = "";
}
this.marker = str;
return listStreams.keys();
} catch (QiniuException e8) {
this.exception = e8;
return null;
}
}
}
private static class SaveRet {
public String fname;
private SaveRet() {
}
}
public StreamingManager(Auth auth, String str) {
this(auth, str, "http://pili.qiniuapi.com");
}
private String encodeKey(String str) {
return "/" + UrlSafeBase64.encodeToString(str);
}
private <T> T get(String str, Class<T> cls) throws QiniuException {
String str2 = this.apiServer + "/v2/hubs/" + this.hub + "/streams" + str;
Response response = this.client.get(str2, this.auth.authorizationV2(str2));
if (cls != null) {
return (T) response.jsonToObject(cls);
}
return null;
}
private <T> T post(String str, String str2, Class<T> cls) throws QiniuException {
String str3 = this.apiServer + "/v2/hubs/" + this.hub + "/streams" + str;
byte[] bytes = str2.getBytes();
Response post = this.client.post(str3, bytes, this.auth.authorizationV2(str3, "POST", bytes, "application/json"), "application/json");
if (cls != null) {
return (T) post.jsonToObject(cls);
}
return null;
}
public StreamAttribute attribute(String str) throws QiniuException {
return (StreamAttribute) get(encodeKey(str), StreamAttribute.class);
}
public void create(String str) throws QiniuException {
post("", new StringMap().put("key", str).jsonString(), null);
}
public ListIterator createStreamListIterator(boolean z7, String str) {
return new ListIterator(z7, str);
}
public void disableTill(String str, long j8) throws QiniuException {
post(encodeKey(str) + "/disabled", String.format("{\"disabledTill\":%d}", Long.valueOf(j8)), null);
}
public void enable(String str) throws QiniuException {
disableTill(str, 0L);
}
public ActivityRecords history(String str, long j8, long j9) throws QiniuException {
if (j8 <= 0 || j9 < 0 || (j8 >= j9 && j9 != 0)) {
throw new QiniuException(new IllegalArgumentException("bad argument" + j8 + "," + j9));
}
String str2 = encodeKey(str) + "/historyactivity?start=" + j8;
if (j9 != 0) {
str2 = str2 + "&end=" + j9;
}
return (ActivityRecords) get(str2, ActivityRecords.class);
}
public StreamListing listStreams(boolean z7, String str, String str2) throws QiniuException {
StringMap stringMap = new StringMap();
stringMap.putWhen("liveonly", Boolean.valueOf(z7), z7);
stringMap.putNotEmpty("prefix", str);
stringMap.putNotEmpty("marker", str2);
String str3 = "";
if (stringMap.size() != 0) {
str3 = "?" + stringMap.formString();
}
return (StreamListing) get(str3, StreamListing.class);
}
public String saveAs(String str, String str2) throws QiniuException {
return saveAs(str, str2, 0L, 0L);
}
public StreamStatus status(String str) throws QiniuException {
return (StreamStatus) get(encodeKey(str) + "/live", StreamStatus.class);
}
public StreamingManager(Auth auth, String str, String str2) {
this.apiServer = str2;
this.hub = str;
this.auth = auth;
this.client = new Client();
}
public String saveAs(String str, String str2, long j8, long j9) throws QiniuException {
return saveAs(str, str2, j8, j9, null);
}
public String saveAs(String str, String str2, long j8, long j9, StringMap stringMap) throws QiniuException {
String str3 = encodeKey(str) + "/saveas";
if (stringMap == null) {
stringMap = new StringMap();
}
stringMap.putNotEmpty("fname", str2).put("start", Long.valueOf(j8)).put("end", Long.valueOf(j9));
return ((SaveRet) post(str3, stringMap.jsonString(), SaveRet.class)).fname;
}
public StreamingManager(Auth auth, String str, String str2, Client client) {
this.apiServer = str2;
this.hub = str;
this.auth = auth;
this.client = client;
}
}