Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

android - ByteArrayBuffer missing in SDK23

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...