How to get an answer as input stream in Volley

1

I am developing an app where I use volley, my app is sending and receiving zip files, the problem is that my method of decompressing the parameter that I expect is of the input stream type and the onResponse of Volley returns the response as byte [] (when it is a file) and does not fit my need, there is a way that onResponse de Volley returns the file as input stream instead of byte []?

PS: I tried to convert the byte [] to insput stream and it did not save any errror but neither did the unzip method work.

The code I used to convert from byte [] to input Stream was:

InputStream is = new ByteArrayInputStream(decodedBytes);

The code to unzip that I use is the following:

 String Decompress(InputStream is) throws Exception {
    byte[] bytes=null;
    String returnValue="";
    ZipInputStream zis = new ZipInputStream(is);

    try {
        ZipEntry ze;
        while ((ze = zis.getNextEntry()) != null) {
            String filename = ze.getName();
            if(returnContent)
            {
                if(filename.endsWith("ext"))
                {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[1024];
                    int count;
                    while ((count = zis.read(buffer)) != -1) {
                        baos.write(buffer, 0, count);
                    }
                    bytes = baos.toByteArray();
                    returnValue=new String(bytes);
                    continue;
                }
            }

            if(filename.endsWith("html") || filename.endsWith("txt"))
            {
                timestamp = new Date();
                String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(timestamp);
                filename = "HTML_" + timeStamp + ".html";
            }

            if(filename.endsWith("ext") )
            {
                Log.e("n_json", "llego el extra");

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int count;
                while ((count = zis.read(buffer)) != -1) {
                    baos.write(buffer, 0, count);
                }
                bytes = baos.toByteArray();
                //this.n_json=new String(bytes);
                Log.e("ext",new String(bytes));
                continue;
            }


            File f=new File(activity.getFilesDir(),filename);
            FileOutputStream fos=new FileOutputStream(f);
            byte[] buffer = new byte[1024];
            int count;
            while ((count = zis.read(buffer)) != -1) {
                fos.write(buffer, 0, count);
            }
            if(!returnContent && (filename.endsWith("txt") || filename.endsWith("html") ))
                returnValue=f.getPath();

            if (filename.endsWith("cache")){

                Log.i("vino","vino el fichero de cache "+filename);
                // this.mincache = takenum(filename);

            }

        }
    } finally {
        zis.close();
    }
    return returnValue;
}

I hope your help, thanks in advance ...

    
asked by cjamdeveloper 09.02.2018 в 00:59
source

0 answers