Java InputStream Read Bytes readBytes(InputStream inputStream)

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

Description

Reads all data from an InputStream

License

Open Source License

Declaration

public static byte[] readBytes(InputStream inputStream) throws IOException 

Method Source Code

//package com.java2s;
/**/*w w w. ja va 2  s  .co  m*/
 * Copyright (C) 2009  HungryHobo@mail.i2p
 * 
 * The GPG fingerprint for HungryHobo@mail.i2p is:
 * 6DD3 EAA2 9990 29BC 4AD2 7486 1E2C 7B61 76DC DC12
 * 
 * This file is part of I2P-Bote.
 * I2P-Bote is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * I2P-Bote is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with I2P-Bote.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /** Reads all data from an <code>InputStream</code> */
    public static byte[] readBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[32 * 1024];
        int bytesRead;
        do {
            bytesRead = inputStream.read(buffer, 0, buffer.length);
            if (bytesRead > 0)
                byteStream.write(buffer, 0, bytesRead);
        } while (bytesRead > 0);
        return byteStream.toByteArray();
    }
}

Related

  1. readBytes(InputStream inputStream)
  2. readBytes(InputStream inputStream)
  3. readBytes(InputStream inputStream)
  4. readBytes(InputStream inputStream)
  5. readBytes(InputStream inputStream)
  6. readBytes(InputStream inputStream)
  7. readBytes(InputStream inputStream, boolean close)
  8. readBytes(InputStream inputStream, byte[] buffer, int offset, int length)
  9. readBytes(InputStream inputStream, int bufSize)