Java ByteArrayOutputStream Write loadFully(final InputStream aStream)

Here you can find the source of loadFully(final InputStream aStream)

Description

load Fully

License

Open Source License

Declaration

public static final byte[] loadFully(final InputStream aStream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static final byte[] loadFully(final InputStream aStream) throws IOException {
        final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        copy(aStream, bytes);/*from  www  .ja  va2 s. c  o  m*/
        return bytes.toByteArray();
    }

    public static final void copy(final InputStream aInput, final OutputStream aOutput) throws IOException {
        final byte[] buffer = new byte[4096];
        while (true) {
            final int newBytes = aInput.read(buffer);
            if (newBytes == -1)
                break;
            aOutput.write(buffer, 0, newBytes);
        }
    }
}

Related

  1. load(String fileName)
  2. loadAFileToString(File f)
  3. loadAsciiTxt()
  4. loadAsText(Class cls, String name)
  5. loadBinFile(java.io.File f)
  6. loadIfileAsBytes(final IFile ifile)
  7. loadIntoMemory(InputStream is)
  8. loadProbe(InputStream in, int buffSize)
  9. loadStream(InputStream in, String encoding)