Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.qiniu.process.qos.PrivateUrl Maven / Gradle / Ivy
Go to download
qiniu-suits is a efficient tools for qiniu api implemented by java8.
package com.qiniu.process.qos;
import com.qiniu.interfaces.ILineProcess;
import com.qiniu.process.Base;
import com.qiniu.util.*;
import java.io.IOException;
import java.util.Map;
public class PrivateUrl extends Base> {
private Auth auth;
private String protocol;
private String domain;
private String urlIndex;
private String suffixOrQuery;
private boolean useQuery;
private long expires;
private ILineProcess> nextProcessor;
public PrivateUrl(String accessKey, String secretKey, String protocol, String domain, String urlIndex, String suffixOrQuery,
long expires) throws IOException {
super("privateurl", accessKey, secretKey, null);
this.auth = Auth.create(accessKey, secretKey);
CloudApiUtils.checkQiniu(auth);
set(protocol, domain, urlIndex, suffixOrQuery, expires);
}
public PrivateUrl(String accessKey, String secretKey, String protocol, String domain, String urlIndex, String suffixOrQuery,
long expires, String savePath, int saveIndex) throws IOException {
super("privateurl", accessKey, secretKey, null, savePath, saveIndex);
this.auth = Auth.create(accessKey, secretKey);
CloudApiUtils.checkQiniu(auth);
set(protocol, domain, urlIndex, suffixOrQuery, expires);
}
public PrivateUrl(String accessKey, String secretKey, String protocol, String domain, String urlIndex, String suffixOrQuery,
long expires, String savePath) throws IOException {
this(accessKey, secretKey, protocol, domain, urlIndex, suffixOrQuery, expires, savePath, 0);
}
private void set(String protocol, String domain, String urlIndex, String suffixOrQuery, long expires) throws IOException {
if (urlIndex == null || "".equals(urlIndex)) {
this.urlIndex = "url";
if (domain == null || "".equals(domain)) {
throw new IOException("please set one of domain and url-index.");
} else {
this.protocol = protocol == null || !protocol.matches("(http|https)") ? "http" : protocol;
RequestUtils.lookUpFirstIpFromHost(domain);
this.domain = domain;
}
} else {
this.urlIndex = urlIndex;
}
this.suffixOrQuery = suffixOrQuery == null ? "" : suffixOrQuery;
useQuery = !"".equals(this.suffixOrQuery);
this.expires = expires <= 0L ? 3600 : expires;
}
public void setNextProcessor(ILineProcess> nextProcessor) {
this.nextProcessor = nextProcessor;
if (nextProcessor != null) processName = nextProcessor.getProcessName() + "_with_" + processName;
}
public PrivateUrl clone() throws CloneNotSupportedException {
PrivateUrl privateUrl = (PrivateUrl)super.clone();
privateUrl.auth = Auth.create(accessId, secretKey);
if (nextProcessor != null) privateUrl.nextProcessor = nextProcessor.clone();
return privateUrl;
}
@Override
protected String resultInfo(Map line) {
String key = line.get("key");
return (key == null ? "\t" : key + "\t") + line.get(urlIndex);
}
@Override
protected String singleResult(Map line) throws Exception {
String url = line.get(urlIndex);
String key = line.get("key");
if (url == null || "".equals(url)) {
if (key == null) throw new IOException("key is not exists or empty in " + line);
url = protocol + "://" + domain + "/" + key.replace("\\?", "%3f") + suffixOrQuery;
line.put(urlIndex, url);
} else if (useQuery) {
url = url + suffixOrQuery;
line.put(urlIndex, url);
}
url = auth.privateDownloadUrl(url, expires);
if (nextProcessor != null) {
line.put("url", url);
return nextProcessor.processLine(line);
}
return (key == null ? "\t" : key + "\t") + url;
}
@Override
public void closeResource() {
super.closeResource();
auth = null;
protocol = null;
domain = null;
urlIndex = null;
suffixOrQuery = null;
if (nextProcessor != null) nextProcessor.closeResource();
nextProcessor = null;
}
}