07-06-2013 05:15 AM
@Override
public void getContent(OutputStream os) throws ContentIOException {
if (!decrypt) { //i am checking if i must decrypt file
try
{
InputStream is = getContentInputStream();
os.flush();
FileCopyUtils.copy(is, os); // both streams are closed
// done
}
catch (IOException e)
{
throw new ContentIOException("Failed to copy content to output stream: \n" +
" accessor: " + this,
e);
}
} else {
decryptDuringCopy(os);
}
}
public void decryptDuringCopy(OutputStream os){
InputStream is = null;
CipherInputStream cis = null;
try
{
is = getContentInputStream();
os.flush();
AESManager am = new AESManager();
Cipher cipher = null;
try {
cipher = am.getCipherDecrypt(key.getBytes("UTF-8"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cis = new CipherInputStream(is, cipher);
byte[] data = new byte[1024];
int read = cis.read(data);
int readed = read;
while (read != -1) {
os.write(data, 0, read);
read = cis.read(data);
readed += read;
}
}
catch (IOException e)
{
throw new ContentIOException("Failed to copy content to output stream: \n" +
" accessor: " + this,
e);
} finally {
try {
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
cis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
07-08-2013 05:37 AM
07-10-2013 07:15 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.