smime.SignedPart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smime-testing-rand Show documentation
Show all versions of smime-testing-rand Show documentation
Simple S/MIME library not dependent on Java Security
The newest version!
package smime;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Part;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
public final class SignedPart {
public final Message message;
public final SignInfo[] signatures;
public final Part dataPart;
final String rawData;
final Part rawSignature;
public final Throwable error;
SignedPart(Message message, Part dataPart, List signatures, String rawData, Part rawSignature) throws IOException, MessagingException {
this(message, dataPart, signatures.toArray(new SignInfo[0]), rawData, rawSignature, null);
}
SignedPart(Message message, Part dataPart, SignInfo[] signatures, String rawData, Part rawSignature, Throwable error) throws IOException, MessagingException {
this.message = message;
this.dataPart = dataPart;
copyStream(dataPart.getInputStream(), new OutputStream() {
public void write(int b) {
}
});
this.signatures = signatures;
this.rawData = rawData;
this.rawSignature = rawSignature;
this.error = error;
}
/**
* Does not close streams!
*/
public static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] arr = new byte[1024];
int read;
while ((read = in.read(arr)) != -1) {
out.write(arr, 0, read);
}
}
}