The list of methods to do Byte Array from are organized into topic(s).
byte[]
getBytes(byte value) get Bytes
byte[] byteArray = new byte[1];
byteArray[0] = value;
return byteArray;
byte[]
getBytes(Class clazz) get Bytes
ByteArrayOutputStream result = new ByteArrayOutputStream();
try (InputStream in = getResourceAsStrem(getBytecodeRelativePath(clazz))) {
byte[] buffer = new byte[1024];
for (int read = in.read(buffer); read > -1; read = in.read(buffer)) {
result.write(buffer, 0, read);
return result.toByteArray();
...
byte[]
getBytes(Class> clazz) get Bytes
String resourcePath = clazz.getName().replace('.', '/') + ".class";
ClassLoader loader = clazz.getClassLoader();
InputStream in;
if (loader == null) {
in = ClassLoader.getSystemResourceAsStream(resourcePath);
} else {
in = loader.getResourceAsStream(resourcePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[100];
while (true) {
int len = in.read(buf);
if (len < 0) {
break;
out.write(buf, 0, len);
in.close();
return out.toByteArray();
byte[]
getBytes(final InputStream is) Reads an InputStream and returns the read byte[]
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int a = 0;
while ((a = is.read(buffer)) != -1) {
baos.write(buffer, 0, a);
baos.close();
buffer = null;
...
byte[]
getBytes(final Serializable obj) get Bytes
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(bos);
try {
oos.writeObject(obj);
} finally {
oos.close();
} finally {
bos.close();
return bos.toByteArray();
byte[]
getBytes(final String data, String charset) Converts the specified string to a byte array.
if (data == null) {
throw new IllegalArgumentException("data may not be null");
if (charset == null || charset.length() == 0) {
throw new IllegalArgumentException("charset may not be null or empty");
try {
return data.getBytes(charset);
...
byte[]
getBytes(final String data, String charset) get Bytes
if (data == null) {
throw new IllegalArgumentException("data may not be null");
if (charset == null || charset.length() == 0) {
throw new IllegalArgumentException("charset may not be null or empty");
try {
return data.getBytes(charset);
...