Java Byte Array from getBytes(int value)

Here you can find the source of getBytes(int value)

Description

get Bytes

License

Apache License

Declaration

private static byte[] getBytes(int value) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

public class Main {

    private static byte[] getBytes(int value) {
        if ((value >= 0x20 && value <= 0x7F) || (value >= 0xA0 && value <= 0xDF)) {
            return new byte[] { (byte) value };
        } else {//from   w  ww .  ja v  a  2 s.  c om
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int high = (byte) ((value >>> 8) & 0xFF);
            int low = (byte) ((0xFF & value));
            baos.write(high);
            baos.write(low);
            return baos.toByteArray();
        }
    }
}

Related

  1. getBytes(final Serializable obj)
  2. getBytes(final String data, String charset)
  3. getBytes(final String data, String charset)
  4. getBytes(final String value, final String characterEncoding)
  5. getBytes(int length, InputStream inStream)
  6. getBytes(String content)
  7. getBytes(String data, String encoding)
  8. getBytes(String defaultPlain)
  9. getBytes(String fileName)