本文整理汇总了Java中ru.bozaro.gitlfs.common.data.Link类的典型用法代码示例。如果您正苦于以下问题:Java Link类的具体用法?Java Link怎么用?Java Link使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Link类属于ru.bozaro.gitlfs.common.data包,在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthUncached
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
protected Link getAuthUncached(@NotNull Operation operation) throws IOException, InterruptedException {
final ProcessBuilder builder = new ProcessBuilder()
.command(getCommand(operation))
.redirectError(ProcessBuilder.Redirect.PIPE)
.redirectOutput(ProcessBuilder.Redirect.PIPE);
final Process process = builder.start();
process.getOutputStream().close();
final InputStream stdoutStream = process.getInputStream();
final ByteArrayOutputStream stdoutData = new ByteArrayOutputStream();
final byte[] buffer = new byte[0x10000];
while (true) {
final int read = stdoutStream.read(buffer);
if (read <= 0) break;
stdoutData.write(buffer, 0, read);
}
final int exitValue = process.waitFor();
if (exitValue != 0) {
throw new IOException("Command returned with non-zero exit code " + exitValue + ": " + Arrays.toString(builder.command().toArray()));
}
return JsonHelper.createMapper().readValue(stdoutData.toByteArray(), Link.class);
}
示例2: BasicAuthProvider
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
public BasicAuthProvider(@NotNull URI href, @Nullable String login, @Nullable String password) {
final String authLogin;
if (isEmpty(login)) {
authLogin = extractLogin(href.getUserInfo());
} else {
authLogin = login;
}
final String authPassword;
if (isEmpty(password)) {
authPassword = extractPassword(href.getUserInfo());
} else {
authPassword = password;
}
final TreeMap<String, String> header = new TreeMap<>();
final String userInfo = authLogin + ':' + authPassword;
header.put(HEADER_AUTHORIZATION, "Basic " + new String(Base64.encodeBase64(userInfo.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
try {
final String scheme = "git".equals(href.getScheme()) ? "https" : href.getScheme();
this.auth = new Link(new URI(scheme, href.getAuthority(), href.getPath(), null, null), Collections.unmodifiableMap(header), null);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}
示例3: getAuth
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
@Override
public final Link getAuth(@NotNull Operation operation) throws IOException {
Link auth = authCache.get(operation);
if (auth == null) {
synchronized (locks.get(operation)) {
auth = authCache.get(operation);
if (auth == null) {
try {
auth = getAuthUncached(operation);
authCache.put(operation, auth);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
}
}
return auth;
}
示例4: createToken
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
public static Link createToken(
@NotNull SharedContext context,
@NotNull URI baseLfsUrl,
@NotNull User user,
int tokenExpireSec,
float tokenEnsureTime
) throws IOException {
int expireSec = tokenExpireSec <= 0 ? LfsConfig.DEFAULT_TOKEN_EXPIRE_SEC : tokenExpireSec;
int ensureSec = (int) Math.ceil(expireSec * tokenEnsureTime);
NumericDate now = NumericDate.now();
NumericDate expireAt = NumericDate.fromSeconds(now.getValue() + expireSec);
NumericDate ensureAt = NumericDate.fromSeconds(now.getValue() + ensureSec);
return new Link(
baseLfsUrl,
createTokenHeader(context, user, expireAt),
new Date(ensureAt.getValueInMillis())
);
}
示例5: createToken
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
protected void createToken(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException {
try {
final Link token = createToken(
req,
getUriParam(req, "url"),
getStringParam(req, "token"),
getStringParam(req, "username"),
getStringParam(req, "external"),
getBoolParam(req, "anonymous", false)
);
resp.setContentType("application/json");
JsonHelper.createMapper().writeValue(resp.getOutputStream(), token);
} catch (ServerError e) {
getWebServer().sendError(req, resp, e);
}
}
示例6: getTokenUncached
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
private Link getTokenUncached(@NotNull User user) throws IOException {
final HttpPost post = new HttpPost(authUrl.toString());
final List<NameValuePair> params = new ArrayList<>();
addParameter(params, "token", authToken);
if (!user.isAnonymous()) {
addParameter(params, "username", user.getUserName());
addParameter(params, "realname", user.getRealName());
addParameter(params, "external", user.getExternalId());
addParameter(params, "email", user.getEmail());
} else {
addParameter(params, "anonymous", "true");
}
post.setEntity(new UrlEncodedFormEntity(params));
try {
final HttpResponse response = httpClient.execute(post);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return mapper.readValue(response.getEntity().getContent(), Link.class);
}
throw new RequestException(post, response);
} finally {
post.abort();
}
}
示例7: getToken
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
private Link getToken(@NotNull User user) throws IOException {
try {
return tokens.get(user);
} catch (ExecutionException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
if (e.getCause() instanceof Error) {
throw (Error) e.getCause();
}
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e);
}
}
示例8: getAuthUncached
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@Override
@NotNull
protected Link getAuthUncached(
@NotNull final Operation operation) throws IOException,
InterruptedException {
return new Link(this.uri, Collections.emptyMap(), null);
}
示例9: getAuth
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
@Override
public Link getAuth(@NotNull Operation operation) throws IOException {
synchronized (lock) {
if (auth == null) {
auth = createAuth();
}
return auth;
}
}
示例10: invalidateAuth
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@Override
public void invalidateAuth(@NotNull Operation operation, @NotNull Link auth) {
synchronized (lock) {
if (this.auth == auth) {
this.auth = null;
}
}
}
示例11: getAuthProvider
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
public AuthProvider getAuthProvider(@NotNull URI href) {
return new CachedAuthProvider() {
@NotNull
@Override
protected Link getAuthUncached(@NotNull Operation operation) throws IOException, InterruptedException {
return new Link(href, ImmutableMap.of(Constants.HEADER_AUTHORIZATION, getToken()), null);
}
};
}
示例12: LfsHttpStorage
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
public LfsHttpStorage(@NotNull URL authUrl, @NotNull String authToken) {
this.authUrl = authUrl;
this.authToken = authToken;
this.mapper = WebServer.createJsonMapper();
this.tokens = CacheBuilder.newBuilder()
.maximumSize(MAX_CACHE)
.build(new CacheLoader<User, Link>() {
public Link load(@NotNull User user) throws IOException {
return getTokenUncached(user);
}
});
}
示例13: getAuth
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
@Override
public Link getAuth(@NotNull Operation operation) throws IOException {
return auth;
}
示例14: invalidateAuth
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@Override
public void invalidateAuth(@NotNull Operation operation, @NotNull Link auth) {
}
示例15: getAuthUncached
import ru.bozaro.gitlfs.common.data.Link; //导入依赖的package包/类
@NotNull
protected abstract Link getAuthUncached(@NotNull Operation operation) throws IOException, InterruptedException;