Search in sources :

Example 91 with SneakyThrows

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;
}
Also used : VkException(me.ruslanys.vkmusic.exception.VkException) Matcher(java.util.regex.Matcher) Connection(org.jsoup.Connection) SneakyThrows(lombok.SneakyThrows)

Example 92 with SneakyThrows

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);
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) Cleanup(lombok.Cleanup) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) SneakyThrows(lombok.SneakyThrows)

Example 93 with SneakyThrows

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);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Cleanup(lombok.Cleanup) SneakyThrows(lombok.SneakyThrows)

Example 94 with SneakyThrows

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);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) SneakyThrows(lombok.SneakyThrows)

Example 95 with SneakyThrows

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;
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) PullRequest(org.eclipse.egit.github.core.PullRequest) RepositoryId(org.eclipse.egit.github.core.RepositoryId) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)706 lombok.val (lombok.val)314 Test (org.junit.Test)91 ArrayList (java.util.ArrayList)75 HashMap (java.util.HashMap)63 List (java.util.List)53 Cleanup (lombok.Cleanup)38 Map (java.util.Map)35 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)34 Collectors (java.util.stream.Collectors)34 LinkedHashMap (java.util.LinkedHashMap)30 File (java.io.File)28 Path (java.nio.file.Path)28 IOException (java.io.IOException)26 InputStream (java.io.InputStream)24 Slf4j (lombok.extern.slf4j.Slf4j)24 URL (java.net.URL)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Collection (java.util.Collection)18 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)17