Java ByteBuffer Put toByteBuffer(InputStream inputStream)

Here you can find the source of toByteBuffer(InputStream inputStream)

Description

to Byte Buffer

License

Open Source License

Declaration

public static ByteBuffer toByteBuffer(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

public class Main {
    public static ByteBuffer toByteBuffer(InputStream inputStream) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int l;/*from ww w.jav  a  2s.com*/
        while ((l = inputStream.read(buffer)) != -1) {
            baos.write(buffer, 0, l);
        }
        return ByteBuffer.wrap(baos.toByteArray());
    }
}

Related

  1. serializeNullableString(ByteBuffer outputBuffer, String value)
  2. serializeObject(Object obj, ByteBuffer buffer, ByteArrayOutputStream baos, boolean markEndOfHeader)
  3. setBit(ByteBuffer input, int pos)
  4. skipBlank(ByteBuffer input)
  5. toByteArrayInputStream(ByteBuffer buffer)
  6. toByteBuffer(String input)
  7. wrap(ByteBuffer byteBuffer, ByteBuffer outputBB, SSLEngine sslEngine)
  8. write(ByteBuffer buffer, DataOutput out)
  9. write(ByteBuffer byteBuffer, OutputStream outputStream)