Java ByteBuffer Put readToByteBuffer(InputStream inStream)

Here you can find the source of readToByteBuffer(InputStream inStream)

Description

read To Byte Buffer

License

LGPL

Declaration

static ByteBuffer readToByteBuffer(InputStream inStream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.*;
import java.nio.ByteBuffer;

public class Main {
    private static final int bufferSize = 0x20000;

    static ByteBuffer readToByteBuffer(InputStream inStream) throws IOException {
        byte[] buffer = new byte[bufferSize];
        ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);
        int read;
        while (true) {
            read = inStream.read(buffer);
            if (read == -1)
                break;
            outStream.write(buffer, 0, read);
        }//from  ww w. ja va  2 s .  c  o m
        ByteBuffer byteData = ByteBuffer.wrap(outStream.toByteArray());
        return byteData;
    }
}

Related

  1. readFully(InputStream is, ByteBuffer buf)
  2. readFully(InputStream is, ByteBuffer buffer, int nrBytes)
  3. readInto(ByteBuffer buf, InputStream inputStream)
  4. readNextLine(InputStream in, ByteBuffer buff, boolean acceptEOF, boolean requireCR)
  5. readPackedLong(ByteBuffer input)
  6. serializeNullableString(ByteBuffer outputBuffer, String value)
  7. serializeObject(Object obj, ByteBuffer buffer, ByteArrayOutputStream baos, boolean markEndOfHeader)
  8. setBit(ByteBuffer input, int pos)
  9. skipBlank(ByteBuffer input)