signatureoutputstream.java

来自「一个java开发的非常全面的关于证书发放」· Java 代码 · 共 61 行

JAVA
61
字号
package net.sourceforge.jcetaglib.tools;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.Signature;
import java.security.SignatureException;


/**
 * Signature output stream is a stream wrapper that
 * passes data though a Signature object before passing it on.
 */


public class SignatureOutputStream
        extends FilterOutputStream {
    private Signature sig = null;

    public SignatureOutputStream(OutputStream out,
                                 Signature sig) {
        super(out);
        this.sig = sig;
    }

    public void write(int b)
            throws IOException {
        try {
            sig.update((byte) b);
        } catch (SignatureException s_ex) {
            throw new IOException(s_ex.getMessage());
        }
        out.write(b);
    }

    public void write(byte[] b)
            throws IOException {
        try {
            sig.update(b);
        } catch (SignatureException s_ex) {
            throw new IOException(s_ex.getMessage());
        }

        out.write(b);
    }

    public void write(byte[] b,
                      int o,
                      int l)
            throws IOException {
        try {
            sig.update(b, o, l);
        } catch (SignatureException s_ex) {
            throw(new IOException(s_ex.getMessage()));
        }

        out.write(b, o, l);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?