Java Utililty Methods ByteArrayOutputStream Write

List of utility methods to do ByteArrayOutputStream Write

Description

The list of methods to do ByteArrayOutputStream Write are organized into topic(s).

Method

byte[]loadBinFile(java.io.File f)
Loads a binary file 'f' and returns its content as a byte array.
byte[] ans = null;
try {
    java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
    copyStream(new java.io.FileInputStream(f), bo).close();
    ans = bo.toByteArray();
} catch (java.io.IOException e) {
return ans;
...
byte[]loadFully(final InputStream aStream)
load Fully
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
copy(aStream, bytes);
return bytes.toByteArray();
byte[]loadIfileAsBytes(final IFile ifile)
Helper to read a ifile from the workspace into a byte array.
final InputStream is = ifile.getContents();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buffer = new byte[BUF_SIZE];
int num;
while ((num = is.read(buffer)) > 0) {
    baos.write(buffer, 0, num);
is.close();
...
byte[]loadIntoMemory(InputStream is)
Writes all contents of the given InputStream to a byte array.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
copyStream(is, bos);
bos.close();
return bos.toByteArray();
byte[]loadProbe(InputStream in, int buffSize)
load Probe
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buff = new byte[buffSize];
int read = in.read(buff);
if (read > 0) {
    bout.write(buff, 0, read);
return bout.toByteArray();
StringloadStream(InputStream in, String encoding)
load Stream
if (encoding == null)
    encoding = "UTF-8";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
while (true) {
    int readlen = in.read(buf);
    if (readlen == -1)
        break;
...
byte[]readAll(File file)
read All
ByteArrayOutputStream baos = new ByteArrayOutputStream();
copy(new BufferedInputStream(new FileInputStream(file)), baos);
return baos.toByteArray();
byte[]readAll(InputStream aInputStream)
read All
try (InputStream in = aInputStream) {
    byte[] buffer = new byte[4096];
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (;;) {
        int len = in.read(buffer);
        if (len <= 0) {
            break;
        baos.write(buffer, 0, len);
    return baos.toByteArray();
byte[]readAll(InputStream bytes)
Read all of the bytes in an input stream.
ByteArrayOutputStream builder = new ByteArrayOutputStream();
int read = bytes.read();
while (read != -1) {
    builder.write(read);
    read = bytes.read();
builder.flush();
bytes.close();
...
byte[]readAll(InputStream bytes, int bufferSize)
Read all of the bytes in an input stream.
try {
    return readAllAndKeepOpen(bytes, bufferSize);
} finally {
    bytes.close();