Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ByteArrayBuffer missing in SDK23

Tags:

android

when updating android SDK 22->23 org.apache.http.util.ByteArrayBuffer is not there anymore - is there a replacement or is this a bug?

like image 979
ligi Avatar asked Aug 21 '15 11:08

ligi


1 Answers

this answer can be a bit late, but an alternative is to replace ByteArrayBuffer with ByteArrayOutputStream and use an array of bytes as follows:

Example of code with ByteArraybuffer:

   BufferedInputStream bis = new BufferedInputStream(is);
   ByteArrayBuffer baf = new ByteArrayBuffer(50);
   while ((current = bis.read()) != -1) {
                baf.append((byte) current);
   }
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(buffer.toByteArray());

Now, using with ByteArrayOutputStream:

     BufferedInputStream bis = new BufferedInputStream(is);
     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
     //We create an array of bytes
     byte[] data = new byte[50];
     int current = 0;

     while((current = bis.read(data,0,data.length)) != -1){
           buffer.write(data,0,current);
     }

     FileOutputStream fos = new FileOutputStream(file);
     fos.write(buffer.toByteArray());
     fos.close();

Well, I hope this be useful.

like image 183
ZLNK Avatar answered Oct 23 '22 01:10

ZLNK