Flowable源码注释(九)流来源类

Flowable源码地址:https://github.com/flowable/flowable-engine

包路径 package org.flowable.common.engine.impl.util.io

InputStreamProvider 输入流提供类

package org.flowable.common.engine.api.io;

import java.io.InputStream;

/**
 * @author Joram Barrez
 */
public interface InputStreamProvider {

    /**
     * Creates a <b>NEW</b> {@link InputStream} to the provided resource.
     * 为提供的资源创建一个新的</b>{@link InputStream}。
     */
    InputStream getInputStream();

}

StreamSource 流来源类

package org.flowable.common.engine.impl.util.io;

import java.io.InputStream;

import org.flowable.common.engine.api.io.InputStreamProvider;

/**
 * @author Tom Baeyens
 * @author Joram Barrez
 */
public interface StreamSource extends InputStreamProvider {

    /**
     * Creates a <b>NEW</b> {@link InputStream} to the provided resource.
     * 为提供的资源创建一个新的</b>{@link InputStream}。
     */
    @Override
    InputStream getInputStream();

}

BytesStreamSource 字节流来源类

package org.flowable.common.engine.impl.util.io;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @author Joram Barrez
 */
public class BytesStreamSource implements StreamSource {

    protected byte[] bytes;

    public BytesStreamSource(byte[] bytes) {
        this.bytes = bytes;
    }

    @Override
    public InputStream getInputStream() {
        return new ByteArrayInputStream(bytes);
    }

}

InputStreamSource 输入流来源来

package org.flowable.common.engine.impl.util.io;

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

import org.flowable.common.engine.api.FlowableException;

/**
 * @author Tom Baeyens
 * @author Joram Barrez
 */
public class InputStreamSource implements StreamSource {

    // This class is used for bpmn parsing.
    // The bpmn parsers needs to go over the stream at least twice:
    // Once for the schema validation and once for the parsing itself.
    // So we keep the content of the inputstream in memory so we can
    // re-read it.
    
    // 此类用于bpmn解析。
    // bpmn解析器需要至少对流进行两次检查:
    // 一次用于模式验证,一次用于解析本身。
	// 因此,我们将输入流的内容保存在内存中,以便重读一遍
    
    protected BufferedInputStream inputStream;
    protected byte[] bytes;

    public InputStreamSource(InputStream inputStream) {
        this.inputStream = new BufferedInputStream(inputStream);
    }

    @Override
    public InputStream getInputStream() {
        if (bytes == null) {
            try {
                bytes = getBytesFromInputStream(inputStream);
            } catch (IOException e) {
                throw new FlowableException("Could not read from inputstream", e);
            }
        }
        return new BufferedInputStream(new ByteArrayInputStream(bytes));
    }

    @Override
    public String toString() {
        return "InputStream";
    }

    public byte[] getBytesFromInputStream(InputStream inStream) throws IOException {
        long length = inStream.available();
        byte[] bytes = new byte[(int) length];

        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead = inStream.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        if (offset < bytes.length) {
            throw new FlowableException("Could not completely read inputstream ");
        }

        // Close the input stream and return bytes
        // 关闭输入流并返回字节
        inStream.close();
        return bytes;
    }

}

StringStreamSource 字符串流来源类

package org.flowable.common.engine.impl.util.io;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import org.flowable.common.engine.api.FlowableException;

/**
 * @author Tom Baeyens
 */
public class StringStreamSource implements StreamSource {

    String string;
    String byteArrayEncoding = "utf-8";

    public StringStreamSource(String string) {
        this.string = string;
    }

    public StringStreamSource(String string, String byteArrayEncoding) {
        this.string = string;
        this.byteArrayEncoding = byteArrayEncoding;
    }

    @Override
    public InputStream getInputStream() {
        try {
            return new ByteArrayInputStream(byteArrayEncoding == null ? string.getBytes() : string.getBytes(byteArrayEncoding));
        } catch (UnsupportedEncodingException e) {
            throw new FlowableException("Unsupported encoding for string", e);
        }
    }

    @Override
    public String toString() {
        return "String";
    }
}

UrlStreamSource 网址流来源类

package org.flowable.common.engine.impl.util.io;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;

/**
 * @author Tom Baeyens
 */
public class UrlStreamSource implements StreamSource {

    URL url;

    public UrlStreamSource(URL url) {
        this.url = url;
    }

    @Override
    public InputStream getInputStream() {
        try {
            return new BufferedInputStream(url.openStream());
        } catch (IOException e) {
            throw new FlowableIllegalArgumentException("couldn't open url '" + url + "'", e);
        }
    }
}
Flowable是一个开源的程引擎,可以用于处理和管理各种型的业务程。Flowable源码可以在其官方的GitHub仓库上找到,具体地址是https://github.com/flowable/flowable-engine/releases/tag/flowable-6.7.2。 Flowable的启动程有两种方式,但最终都是执行了StartProcessInstanceCmd命令。在我以程key方式启动来分析源码中,启动程的入口是通过runtimeService.startProcessInstance方法来实现的。 通过研究Flowable源码,可以深入了解其内部的实现机制,从而更好地理解Flowable的工作原理和使用方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [flowable 6.7.2 源码压缩包](https://download.csdn.net/download/weixin_44393822/86790116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [flowable部署和启动源码解析](https://blog.csdn.net/u012483153/article/details/106736343)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Flowable程启动源码分析](https://blog.csdn.net/CH_PaulFrank/article/details/116800070)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值