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(int length, InputStream inStream)
get Bytes
int bytesRead = 0;
byte[] content = new byte[length];
while (bytesRead < length) {
    int result;
    try {
        result = inStream.read(content, bytesRead, length - bytesRead);
        if (result == -1)
            break;
...
byte[]getBytes(int value)
get Bytes
if ((value >= 0x20 && value <= 0x7F) || (value >= 0xA0 && value <= 0xDF)) {
    return new byte[] { (byte) value };
} else {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int high = (byte) ((value >>> 8) & 0xFF);
    int low = (byte) ((0xFF & value));
    baos.write(high);
    baos.write(low);
...
byte[]getBytes(String content)
Gets byte[] according to string.
byte[] bytes = null;
try {
    bytes = content.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
    bytes = content.getBytes();
return bytes;
byte[]getBytes(String data, String encoding)
Convert a string to an array of bytes, representing the string in the given encoding.
try {
    return data.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
byte[]getBytes(String defaultPlain)
get Bytes
byte[] data = null;
while (true) {
    System.out.print("Please Input Data \"" + defaultPlain + "\"(default): ");
    try {
        String str = new BufferedReader(new InputStreamReader(System.in)).readLine();
        if ("".equals(str)) {
            data = defaultPlain.getBytes();
        } else {
...
byte[]getBytes(String fileName)
get Bytes
File file = new File("src/test/resources/crc_test_files/" + fileName);
FileInputStream fin = new FileInputStream(file);
byte fileContent[] = new byte[(int) file.length()];
fin.read(fileContent);
return fileContent;
byte[]getBytes(String fileName)
get Bytes
return getBytes(new File(fileName));
byte[]getBytes(String filePath)
get Bytes
byte[] buffer = null;
try {
    File file = new File(filePath);
    FileInputStream fis = new FileInputStream(file);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
    byte[] b = new byte[1000];
    int n;
    while ((n = fis.read(b)) != -1) {
...
byte[]getBytes(String filePath, long startPos, long endPos)
get Bytes
byte[] buffer = null;
try {
    File file = new File(filePath);
    FileInputStream fis = new FileInputStream(file);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(DEFAULT_BUFF_SIZE * UNIT_LEN);
    byte[] b = new byte[DEFAULT_BUFF_SIZE * UNIT_LEN];
    int n;
    while ((n = fis.read(b)) != -1) {
...
byte[]getBytes(String fileUrl)
get Bytes
File file = new File(fileUrl);
if (!file.exists()) {
    return null;
FileInputStream io = null;
byte[] data = null;
try {
    io = new FileInputStream(file);
...