Convert InputStream to Buffer - Android android.view.inputmethod

Android examples for android.view.inputmethod:KeyBoard

Description

Convert InputStream to Buffer

Demo Code

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

public class Main {

  public static ByteBuffer toBuffer(InputStream inputStream) throws IOException {
    ByteBuffer resultBuffer = ByteBuffer.allocate(inputStream.available());
    int bufferLength = 28800;
    byte[] buffer = new byte[bufferLength];
    while (inputStream.read(buffer) != -1) {
      resultBuffer.put(buffer);//ww w . ja v  a2s . com
    }
    return resultBuffer;
  }

}

Related Tutorials