use of lombok.SneakyThrows in project selenium_java by sergueik.
the class ScraperVkClient method fetchUserId.
@Override
@SneakyThrows
public Long fetchUserId() {
Connection.Response response = Jsoup.connect(PATH_BASE).userAgent(USER_AGENT).cookies(cookies).method(Connection.Method.GET).execute();
Matcher matcher = Pattern.compile("id: (\\d+)").matcher(response.body());
if (!matcher.find() || "0".equals(matcher.group(1).trim())) {
throw new VkException("Не удалось получить ID пользователя.");
}
Long id = Long.valueOf(matcher.group(1));
log.info("User ID: {}", id);
return id;
}
use of lombok.SneakyThrows in project commons-utils-core by jiayongming.
the class WriteExcel method writeNIO.
@SneakyThrows
public void writeNIO(String content) {
@Cleanup FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(filePath));
FileChannel channel = fos.getChannel();
ByteBuffer src = Charset.forName(encode).encode(content);
// 字节缓冲的容量和limit会随着数据长度变化,不是固定不变的
log.info("初始化容量和limit:{},{}", src.capacity(), src.limit());
int length = 0;
while ((length = channel.write(src)) != 0) {
/*
* 注意,这里不需要clear,将缓冲中的数据写入到通道中后 第二次接着上一次的顺序往下读
*/
log.info("写入长度:{}", length);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of lombok.SneakyThrows in project Java8 by huhuhuHR.
the class Test method testCaseOne.
@org.junit.Test
@SneakyThrows
public void testCaseOne() {
File f = new File(IoUtils.getClassPathResource("text.txt"));
@Cleanup InputStream inputStream = new FileInputStream(f);
int read = -1;
StringBuffer sb = new StringBuffer();
while ((read = inputStream.read()) != -1) {
char c = (char) read;
sb.append(c);
}
System.out.println(sb);
Pattern p = Pattern.compile("mobnet");
Matcher matcher = p.matcher(sb);
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println(count);
}
use of lombok.SneakyThrows in project modesti by jlsalmon.
the class EditableDeserializerTest method deserialise.
/**
* @param stream the input stream containing JSON
* @return map of the deserialised JSON
* @see <a href="https://stackoverflow.com/a/37001410/379565">this Stack Overflow post</a>
*/
@SneakyThrows({ JsonParseException.class, IOException.class })
private Map<String, Object> deserialise(final InputStream stream) {
JsonParser parser = mapper.getFactory().createParser(stream);
DeserializationContext ctxt = mapper.getDeserializationContext();
parser.nextToken();
parser.nextToken();
parser.nextToken();
return deserializer.deserialize(parser, ctxt);
}
use of lombok.SneakyThrows in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method createUpdatePullRequestStatuses.
@Override
@SneakyThrows
public List<PullRequestStatus> createUpdatePullRequestStatuses(MigratePullRequestStatusRequest request) {
GitHubClient client = createClient(request.getAccessToken());
PullRequestService pullRequestService = new PullRequestService(client);
String commitStatusUrl = request.getCommitStatusUrl();
String accessToken = request.getAccessToken();
List<PullRequestStatus> results = new ArrayList<>();
for (String repositoryId : request.getRepositoryIds()) {
RepositoryId repository = RepositoryId.createFromId(repositoryId);
List<PullRequest> repositoryPullRequests = pullRequestService.getPullRequests(repository, "open");
for (PullRequest pullRequest : repositoryPullRequests) {
PullRequestStatus status = new PullRequestStatus();
String sha = pullRequest.getHead().getSha();
String syncUrl = UriComponentsBuilder.fromHttpUrl(request.getBaseSyncUrl()).queryParam("repositoryId", repositoryId).queryParam("pullRequestId", pullRequest.getNumber()).build().toUriString();
status.setPullRequestId(pullRequest.getNumber());
status.setRepoId(repositoryId);
status.setSha(sha);
status.setGitHubUsername(pullRequest.getUser().getLogin());
status.setUrl(commitStatusUrl);
status.setAccessToken(accessToken);
status.setFaqUrl(request.getFaqUrl());
status.setSyncUrl(syncUrl);
status.setPullRequestState(pullRequest.getState());
results.add(status);
}
}
return results;
}
Aggregations