use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class MimePackage method getRegularPartCharset.
/**
* Get the character set of a regular part
*
* @param partIndex
* the index of the part
* @return the charset
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartCharset(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= regularPartIndices.size()) {
throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
}
try {
MimePart part = getPart(regularPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getParameter("charset");
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class MimePackage method getAllHeaders.
@SuppressWarnings("unchecked")
@PublicAtsApi
public List<PackageHeader> getAllHeaders() throws PackageException {
try {
List<PackageHeader> headers = new ArrayList<PackageHeader>();
Enumeration<Header> messageHeaders = message.getAllHeaders();
while (messageHeaders.hasMoreElements()) {
Header messageHeader = messageHeaders.nextElement();
headers.add(new PackageHeader(messageHeader.getName(), messageHeader.getValue()));
}
return headers;
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class MimePackage method writeToFile.
/**
* Write the constructed MIME message to a file
*
* @param fileName
* the name of the file to write to
*
* @throws IOException
* @throws PackageException
*/
@PublicAtsApi
public void writeToFile(String fileName) throws IOException, PackageException {
FileOutputStream outStream = null;
boolean storeReconnected = false;
try {
storeReconnected = reconnectStoreIfClosed();
// store should be opened for actions including getting InputStream. Hence store open is not in getPart
outStream = new FileOutputStream(new File(fileName));
message.writeTo(outStream);
} catch (MessagingException me) {
throw new PackageException("Could not write message content", me);
} finally {
if (outStream != null) {
outStream.close();
}
try {
closeStoreConnection(storeReconnected);
} catch (MessagingException ex) {
log.warn("Error closing IMAP connection", ex);
}
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class MimePackage method getPartChecksum.
/**
* Return the CRC checksum of a given part
*
* @param partIndex
* the index of the part
* @param isAttachment
* true if the part is an attachment
* @return the part checksum
* @throws PackageException
*/
@PublicAtsApi
public long getPartChecksum(int partIndex, boolean isAttachment) throws PackageException {
InputStream partDataStream = getPartData(partIndex, isAttachment);
if (partDataStream != null) {
try {
SeekInputStream seekDataStream = new SeekInputStream(partDataStream);
seekDataStream.seek(0);
// create a new crc and reset it
CRC32 crc = new CRC32();
// use checked stream to get the checksum
CheckedInputStream stream = new CheckedInputStream(seekDataStream, crc);
int bufLen = 4096;
byte[] buffer = new byte[bufLen];
int numBytesRead = bufLen;
while (numBytesRead == bufLen) {
numBytesRead = stream.read(buffer, 0, bufLen);
}
long checksum = stream.getChecksum().getValue();
stream.close();
return checksum;
} catch (IOException ioe) {
throw new PackageException(ioe);
}
} else {
throw new MimePartWithoutContentException("MIME part does not have any content");
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class MimePackage method getWholePackage.
@PublicAtsApi
public InputStream getWholePackage() throws PackageException {
boolean storeReconnected = false;
try {
storeReconnected = reconnectStoreIfClosed();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
message.writeTo(outStream);
return new ByteArrayInputStream(outStream.toByteArray());
} catch (MessagingException me) {
throw new PackageException("Could not write message content", me);
} catch (IOException ioe) {
throw new PackageException("Could not write message content", ioe);
} finally {
try {
closeStoreConnection(storeReconnected);
} catch (MessagingException ex) {
log.warn(ex);
}
}
}
Aggregations