本文整理汇总了Java中javax.mail.internet.MimeUtility.encode方法的典型用法代码示例。如果您正苦于以下问题:Java MimeUtility.encode方法的具体用法?Java MimeUtility.encode怎么用?Java MimeUtility.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeUtility
的用法示例。
在下文中一共展示了MimeUtility.encode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: digestString
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Calculate digest of given String using given algorithm. Encode digest in
* MIME-like base64.
*
* @param pass
* the String to be hashed
* @param algorithm
* the algorithm to be used
* @return String Base-64 encoding of digest
*
* @throws NoSuchAlgorithmException
* if the algorithm passed in cannot be found
*/
public static String digestString(String pass, String algorithm) throws NoSuchAlgorithmException {
MessageDigest md;
ByteArrayOutputStream bos;
try {
md = MessageDigest.getInstance(algorithm);
byte[] digest = md.digest(pass.getBytes("iso-8859-1"));
bos = new ByteArrayOutputStream();
OutputStream encodedStream = MimeUtility.encode(bos, "base64");
encodedStream.write(digest);
return bos.toString("iso-8859-1");
} catch (IOException ioe) {
throw new RuntimeException("Fatal error: " + ioe);
} catch (MessagingException me) {
throw new RuntimeException("Fatal error: " + me);
}
}
示例2: encodeBase64
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/***
* encode base64
*
* @param b
* @return
* @throws Exception
*/
// metas: 03749
public static byte[] encodeBase64(final byte[] b)
{
try
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final OutputStream b64os = MimeUtility.encode(baos, "base64");
b64os.write(b);
b64os.close();
return baos.toByteArray();
}
catch (Exception e)
{
throw new AdempiereException(e);
}
}
示例3: digestFile
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Calculate digest of given file with given algorithm. Writes digest to
* file named filename.algorithm .
*
* @param filename
* the String name of the file to be hashed
* @param algorithm
* the algorithm to be used to compute the digest
*/
public static void digestFile(String filename, String algorithm) {
byte[] b = new byte[65536];
int count = 0;
int read = 0;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
MessageDigest md = MessageDigest.getInstance(algorithm);
fis = new FileInputStream(filename);
while (fis.available() > 0) {
read = fis.read(b);
md.update(b, 0, read);
count += read;
}
byte[] digest = md.digest();
StringBuffer fileNameBuffer = new StringBuffer(128).append(filename).append(".").append(algorithm);
fos = new FileOutputStream(fileNameBuffer.toString());
OutputStream encodedStream = MimeUtility.encode(fos, "base64");
encodedStream.write(digest);
fos.flush();
} catch (Exception e) {
System.out.println("Error computing Digest: " + e);
} finally {
try {
fis.close();
fos.close();
} catch (Exception ignored) {
}
}
}
示例4: encode
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Enkodiert einen Java-Unicode-String in einen UTF-8-QUOTED-PRINTABLE-String.
*/
public String encode(String in) {
try {
InputStream input = new ReaderInputStream(new StringReader(in), "UTF-8");
StringWriter sw = new StringWriter();
OutputStream output = MimeUtility.encode(new WriterOutputStream(sw), "quoted-printable");
copyAndClose(input, output);
return sw.toString().replaceAll("=\\x0D\\x0A", "").replaceAll("\\x0D\\x0A", "=0D=0A");
} catch (Exception e) {
throw new RuntimeException("Exception caught in VntConverter.encode(in):", e);
}
}
示例5: encode
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public static byte[] encode(byte[] b) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream b64os = MimeUtility.encode(baos, "base64");
b64os.write(b);
b64os.close();
return baos.toByteArray();
}
示例6: EncodedScript
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Construct a new EncodedScript from the supplied {@link PackageScript}.
* @param source The {@link PackageScript} to encode.
* @param data The {@link DpkgData} to pass to the script.
* @throws IOException If the encoding fails.
*/
public EncodedScript (PackageScript source, DpkgData data)
throws IOException
{
_source = source;
// perform the encoding in memory. also, do this in the constructor as getEncodedSource()
// will be called inside of a Velocity template so let's get all the exception handling done
// right away so the caller can handle it.
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
OutputStream output = null;
try {
output = MimeUtility.encode(bytes, BASE64);
} catch (final MessagingException e) {
throw new IOException("Failed to uuencode script. name=[" + _source.getFriendlyName() + "], reason=[" + e.getMessage() + "].");
}
IOUtils.write(HEADER, bytes, Dpkg.CHAR_ENCODING);
bytes.flush();
IOUtils.copy(_source.getSource(data), output);
output.flush();
IOUtils.write(FOOTER, bytes, Dpkg.CHAR_ENCODING);
bytes.flush();
output.close();
bytes.close();
_encoded = bytes.toString(Dpkg.CHAR_ENCODING).replace("\r\n", "\n");
}
示例7: encodeBase64
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Encode an input byte array using Base-64 encoding and return as a String.
*
* @param publicBytes the byte array to encode
* @return the encoded byte array as a String
* @throws MessagingException when there is an encoding problem
* @throws IOException when there is a problem reading the byte array
*/
private static String encodeBase64(byte[] publicBytes)
throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream b64os = MimeUtility.encode(baos, "base64");
b64os.write(publicBytes);
b64os.close();
String publicDigest = new String(baos.toByteArray());
return publicDigest;
}
示例8: writeTo
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Output the message as an RFC 822 format stream, without
* specified headers. If the <code>saved</code> flag is not set,
* the <code>saveChanges</code> method is called.
* If the <code>modified</code> flag is not
* set and the <code>content</code> array is not null, the
* <code>content</code> array is written directly, after
* writing the appropriate message headers.
*
* @exception javax.mail.MessagingException
* @exception IOException if an error occurs writing to the stream
* or if an error is generated by the
* javax.activation layer.
* @see javax.activation.DataHandler#writeTo
*
* This method enhances the JavaMail method MimeMessage.writeTo(OutputStream os String[] ignoreList);
* See the according Sun Licence, this contribution is CDDL.
*/
public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException {
ByteArrayOutputStream osBody = new ByteArrayOutputStream();
// Inside saveChanges() it is assured that content encodings are set in all parts of the body
if (!saved) {
saveChanges();
}
// First, write out the body to the body buffer
if (modified) {
// Finally, the content. Encode if required.
// XXX: May need to account for ESMTP ?
OutputStream osEncoding = MimeUtility.encode(osBody, this.getEncoding());
this.getDataHandler().writeTo(osEncoding);
osEncoding.flush(); // Needed to complete encoding
} else {
// Else, the content is untouched, so we can just output it
// Finally, the content.
if (content == null) {
// call getContentStream to give subclass a chance to
// provide the data on demand
InputStream is = getContentStream();
// now copy the data to the output stream
byte[] buf = new byte[8192];
int len;
while ((len = is.read(buf)) > 0)
osBody.write(buf, 0, len);
is.close();
buf = null;
} else {
osBody.write(content);
}
osBody.flush();
}
encodedBody = osBody.toString();
// Second, sign the message
String signatureHeaderLine;
try {
signatureHeaderLine = signer.sign(this);
} catch (Exception e) {
throw new MessagingException(e.getLocalizedMessage(), e);
}
// Third, write out the header to the header buffer
LineOutputStream los = new LineOutputStream(os);
// set generated signature to the top
los.writeln(signatureHeaderLine);
Enumeration hdrLines = getNonMatchingHeaderLines(ignoreList);
while (hdrLines.hasMoreElements()) {
los.writeln((String) hdrLines.nextElement());
}
// The CRLF separator between header and content
los.writeln();
// Send signed mail to waiting DATA command
os.write(osBody.toByteArray());
os.flush();
}
示例9: encode
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public static OutputStream encode(String contentTransferEncoding, OutputStream os) throws MessagingException {
return MimeUtility.encode(os, contentTransferEncoding);
}
示例10: encodeContent
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
protected void encodeContent(final byte[] bytes, final String encoding, final ByteArrayOutputStream out)
throws MessagingException, IOException {
final OutputStream encoder = MimeUtility.encode(out, encoding);
encoder.write(bytes);
encoder.close();
}
示例11: encodeContent
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
protected void encodeContent(final byte[] bytes, final String encoding, final ByteArrayOutputStream out)
throws MessagingException, IOException {
try (final OutputStream encoder = MimeUtility.encode(out, encoding)) {
encoder.write(bytes);
}
}