Java Utililty Methods Byte Array from

List of utility methods to do Byte Array from

Description

The list of methods to do Byte Array from are organized into topic(s).

Method

byte[]getBytes(String input)
Returns the UTF-8 bytes for the given String, suppressing UnsupportedEncodingException (in lieu of log message)
try {
    return input.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
    return input.getBytes(); 
byte[]getBytes(ZipFile archive, ZipEntry entry)
get Bytes
return readAndClose(archive.getInputStream(entry), (int) entry.getSize());
byte[]getBytes(ZipInputStream zipInputStream)
get Bytes
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputStream inputStream = new BufferedInputStream(zipInputStream);
int b;
while ((b = inputStream.read()) != -1) {
    outputStream.write(b);
byte[] byteArray = outputStream.toByteArray();
return byteArray;
...
byte[]getBytes2(InputStream aStream)
Returns bytes for an input stream.
ByteArrayOutputStream bs = new ByteArrayOutputStream();
byte chunk[] = new byte[8192];
for (int len = aStream.read(chunk, 0, chunk.length); len > 0; len = aStream.read(chunk, 0, chunk.length))
    bs.write(chunk, 0, len);
return bs.toByteArray();
byte[]getBytesAndClose(InputStream in)
get Bytes And Close
try {
    return getBytes(in);
} catch (IOException e) {
    throw new RuntimeException(e);
} finally {
    try {
        in.close();
    } catch (IOException e) {
...
byte[]getBytesArrayFromFile(String fileName)
Get the bytes array from a file
byte[] readBytes = new byte[2000];
int n = 0;
int i = 0;
byte[] totalBytes = null;
byte[] tmpBytes = null;
int curByteCnt = 0;
try {
    FileInputStream file = new FileInputStream(fileName);
...
byte[]getBytesASCII(String s)
get Bytes ASCII
try {
    return s.getBytes("ASCII");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e); 
FilegetBytesAsTempFile(byte[] bytes)
get Bytes As Temp File
return writeStreamToTempFile("bytes", new ByteArrayInputStream(bytes));
byte[]getBytesClassic(final int count, final InputStream is)
Uses "old" IO's InputStream to read up exactly count bytes from provided input stream.
byte[] bytes = new byte[count];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
    offset += numRead;
if (offset < bytes.length) {
    return null;
...
byte[]getBytesFromArrayList(final ArrayList fileList)
TODO
byte[] yourBytes;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
try {
    out = new ObjectOutputStream(bos);
    out.writeObject(fileList);
    yourBytes = bos.toByteArray();
} finally {
...