當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtil類代碼示例

本文整理匯總了Java中net.dv8tion.jda.core.utils.IOUtil的典型用法代碼示例。如果您正苦於以下問題:Java IOUtil類的具體用法?Java IOUtil怎麽用?Java IOUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IOUtil類屬於net.dv8tion.jda.core.utils包,在下文中一共展示了IOUtil類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update0

import net.dv8tion.jda.core.utils.IOUtil; //導入依賴的package包/類
private synchronized void update0(Response response) throws IOException
{
    final long current = System.currentTimeMillis();
    final boolean is429 = response.code() == RATE_LIMIT_CODE;
    if (is429)
    {
        handleRatelimit(response, current);
    }
    else if (!response.isSuccessful())
    {
        LOG.debug("Failed to update buckets due to unsuccessful response with code: {} and body: \n{}",
            response.code(), JDALogger.getLazyString(() -> new String(IOUtil.readFully(Requester.getBody(response)))));
        return;
    }
    remainingUses = Integer.parseInt(response.header("X-RateLimit-Remaining"));
    limit = Integer.parseInt(response.header("X-RateLimit-Limit"));
    final String date = response.header("Date");

    if (date != null && !is429)
    {
        final long reset = Long.parseLong(response.header("X-RateLimit-Reset")); //epoch seconds
        OffsetDateTime tDate = OffsetDateTime.parse(date, DateTimeFormatter.RFC_1123_DATE_TIME);
        final long delay = tDate.toInstant().until(Instant.ofEpochSecond(reset), ChronoUnit.MILLIS);
        resetTime = current + delay;
    }
}
 
開發者ID:DV8FromTheWorld,項目名稱:JDA,代碼行數:27,代碼來源:WebhookClient.java

示例2: load

import net.dv8tion.jda.core.utils.IOUtil; //導入依賴的package包/類
private void load(File file)
{
    try
    {
        config = new JsonParser().parse(new String(IOUtil.readFully(file))).getAsJsonObject();
    }
    catch (IOException e)
    {
        throw new RuntimeException("Can't read config", e);
    }
}
 
開發者ID:krobot-framework,項目名稱:krobot,代碼行數:12,代碼來源:JSONConfig.java

示例3: failure

import net.dv8tion.jda.core.utils.IOUtil; //導入依賴的package包/類
protected static HttpException failure(Response response) throws IOException
{
    final InputStream stream = Requester.getBody(response);
    final String responseBody = new String(IOUtil.readFully(stream));
    return new HttpException("Request returned failure " + response.code() + ": " + responseBody);
}
 
開發者ID:DV8FromTheWorld,項目名稱:JDA,代碼行數:7,代碼來源:WebhookClient.java

示例4: getInputStream

import net.dv8tion.jda.core.utils.IOUtil; //導入依賴的package包/類
/**
 * Creates a copy of the {@link java.io.InputStream InputStream} that is created using an {@link okhttp3.OkHttpClient OkHttpClient}.
 *
 * <p>You can access the input stream directly using {@link #withInputStream(net.dv8tion.jda.core.utils.IOConsumer) withInputStream(IOConsumer)}
 * which will have an open input stream available within the consumer scope. The stream will be closed once that method returns.
 *
 * @throws java.io.IOException
 *         If an IO error occurs trying to read from the opened HTTP channel
 *
 * @return InputStream copy of the response body for this Attachment
 *
 * @since  3.4.0
 */
public InputStream getInputStream() throws IOException
{
    try (Response response = openConnection())
    {
        // creates a copy in order to properly close the response
        InputStream in = Requester.getBody(response);
        return new ByteArrayInputStream(IOUtil.readFully(in));
    }
}
 
開發者ID:DV8FromTheWorld,項目名稱:JDA,代碼行數:23,代碼來源:Message.java

示例5: from

import net.dv8tion.jda.core.utils.IOUtil; //導入依賴的package包/類
/**
 * Creates an {@link Icon Icon} with the specified {@link java.io.File File}.
 * <br>We here read the specified File and forward the retrieved byte data to {@link #from(byte[])}.
 *
 * @param  file
 *         An existing, not-null file.
 *
 * @throws IllegalArgumentException
 *         if the provided file is either null or does not exist
 * @throws IOException
 *         if there is a problem while reading the file.
 *
 * @return An Icon instance representing the specified File
 *
 * @see    net.dv8tion.jda.core.utils.IOUtil#readFully(File)
 */
public static Icon from(File file) throws IOException
{
    Checks.notNull(file, "Provided File");
    Checks.check(file.exists(), "Provided file does not exist!");

    return from(IOUtil.readFully(file));
}
 
開發者ID:DV8FromTheWorld,項目名稱:JDA,代碼行數:24,代碼來源:Icon.java


注:本文中的net.dv8tion.jda.core.utils.IOUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。