in Education by
My application is receiving email through SMTP server. There are one or more attachments in the email and email attachment return as byte[] (using sun javamail api). I am trying to zip the attachment files on the fly without writing them to disk first. What is/are possible way to achieve this outcome? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use Java's java.util.zip.ZipOutputStream to create a zip file in memory. For example: public static byte[] zipBytes(String filename, byte[] input) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); ZipEntry entry = new ZipEntry(filename); entry.setSize(input.length); zos.putNextEntry(entry); zos.write(input); zos.closeEntry(); zos.close(); return baos.toByteArray(); }

Related questions

0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Which of these classes are used by Byte streams for input and output operation? (a) InputStream (b) ... Applets of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    How to read entire file in one line using java 8? (a) Files.readAllLines() (b) Files.read() (c) ... Autoboxing & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I have to copy classpath resource from one package to another. My program is: public static void main( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    How do we convert a byte array to a hexadecimal string, and vice versa?...
asked Jan 16, 2021 in Technology by JackTerrance
0 votes
    How to copy the file from one location to other? (a) Files.copy(source, target) (b) Path.copy(source, ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of these class object can be used to form a dynamic array? (a) ArrayList (b) Map (c) Vector ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these class object has an architecture similar to that of array? (a) Bitset (b) Map (c) ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these method of Array class is used sort an array or its subset? (a) binarysort() (b) ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which is better in terms of performance for iterating an array? (a) for(int i=0; i=0; i-) (c) ... Autoboxing & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
...