Ascii-DocMaven插件如何通过https包含资源?
创始人
2024-11-11 06:30:11
0

在Ascii-Doc Maven插件中,可以使用include指令来包含外部资源,但默认情况下仅支持使用filehttp协议来引用资源。若要通过https协议引用资源,可以使用Apache HTTPComponents库的HttpClient组件。

  1. 首先,在POM文件中导入HttpClient和相关依赖项:

    org.apache.httpcomponents
    httpclient
    4.5.12


    org.apache.httpcomponents
    httpcore
    4.4.13

  1. 接下来,创建一个自定义的AsciiDocResolver类,继承org.asciidoctor.extension.IncludeResolver类,覆盖resolve方法:
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.asciidoctor.ast.DocumentRuby;
import org.asciidoctor.extension.IncludeResolver;
import org.asciidoctor.extension.IncludeResolveResult;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class AsciiDocHttpsIncludeResolver extends IncludeResolver {

    @Override
    public IncludeResolveResult resolve(String target, DocumentRuby document) {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpGet httpGet = new HttpGet(target);
            CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
            InputStream inputStream = httpResponse.getEntity().getContent();
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[1024];
            while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, nRead);
            }
            buffer.flush();
            byte[] byteArray = buffer.toByteArray();

            return new IncludeResolveResult(new ByteArrayInputStream(byteArray));
        } catch

相关内容

热门资讯

第6分钟了解(德州ai)外挂智... 第6分钟了解(德州ai)外挂智能ai辅助代打(透视)攻略教程(2023已更新)(哔哩哔哩);相信小伙...
第2分钟了解(tritonpo... 第2分钟了解(tritonpoker)外挂辅助插件安装代打(透视)黑科技教程(2024已更新)(哔哩...
第9分钟了解(WPK技巧)黑科... 第9分钟了解(WPK技巧)黑科技透明挂辅助软件(透视)教你攻略(2024已更新)(哔哩哔哩)是一款可...
七分钟了解(aapoker德州... 七分钟了解(aapoker德州俱乐部)软件透明挂辅助科技(透视)线上教程(2022已更新)(哔哩哔哩...
1分钟了解(Wepoke开发)... 1分钟了解(Wepoke开发)黑科技透明挂辅助黑科技(透视)扑克教程(2021已更新)(哔哩哔哩);...
第六分钟了解(wpk德州ai机... 第六分钟了解(wpk德州ai机器人)外挂辅助插件安装科技(透视)规律教程(2024已更新)(哔哩哔哩...
第1分钟了解(Wepoke技术... 第1分钟了解(Wepoke技术)外挂透明挂辅助下载(透视)实用技巧(2023已更新)(哔哩哔哩);1...
第十分钟了解(新版Wepoke... 第十分钟了解(新版Wepoke)软件透明挂辅助app(透视)曝光教程(2020已更新)(哔哩哔哩);...
第3分钟了解(wepOke)外... 第3分钟了解(wepOke)外挂辅助插件安装app(透视)第三方教程(2021已更新)(哔哩哔哩),...
八分钟了解(德扑之星设置)外挂... 八分钟了解(德扑之星设置)外挂辅助插件安装黑科技(透视)AI教程(2021已更新)(哔哩哔哩);人气...