0

ArrayList is like this - [ Desktop/folder/abc.pdf, Desktop/folder/xyz.pdf ]

I am doing something like this

public byte[] compressByteArray(byte[] bytes){

        ByteArrayOutputStream baos = null;
        Deflater dfl = new Deflater();
        dfl.setLevel(Deflater.BEST_COMPRESSION);
        dfl.setInput(bytes);
        dfl.finish();
        baos = new ByteArrayOutputStream();
        byte[] tmp = new byte[4*1024];
        try{
            while(!dfl.finished()){
                int size = dfl.deflate(tmp);
                baos.write(tmp, 0, size);
            }
        } catch (Exception ex){

        } finally {
            try{
                if(baos != null) baos.close();
            } catch(Exception ex){}
        }

        return baos.toByteArray();
    }
  • What is wrong with your current solution? Or are you just looking for a way to read the PDFs as `byte[]`? – Turing85 May 03 '18 at 14:43
  • right Turing, I want to read the PDF as byte[]. Please let me know if you have solution – Ankur Kunal May 03 '18 at 14:47
  • [`FileInputStream#read(byte[])`](https://docs.oracle.com/javase/10/docs/api/java/io/FileInputStream.html#read(byte%5B%5D))? – Turing85 May 03 '18 at 14:53
  • Please clarify your question. Your method already gets a byte array as parameter. I don't see anything where you try to read a file. – vanje May 03 '18 at 15:30

0 Answers0