use of com.axway.ats.action.objects.model.MimePartWithoutContentException 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.action.objects.model.MimePartWithoutContentException in project ats-framework by Axway.
the class Test_MimePartWithoutContentException method constructors.
@Test
public void constructors() {
MimePartWithoutContentException exception;
exception = new MimePartWithoutContentException("test");
assertEquals("test", exception.getMessage());
assertNull(exception.getCause());
Exception helperException = new Exception();
exception = new MimePartWithoutContentException("test", helperException);
assertEquals("test", exception.getMessage());
assertEquals(helperException, exception.getCause());
exception = new MimePartWithoutContentException(helperException);
assertEquals("java.lang.Exception", exception.getMessage());
assertEquals(helperException, exception.getCause());
}
Aggregations