Skip to content
Snippets Groups Projects
Utils.java 988 B
Newer Older
  • Learn to ignore specific revisions
  • package quantization;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    public class Utils {
        public static byte[] readFileBytes(final String path) throws FileNotFoundException {
            FileInputStream fileStream = new FileInputStream(path);
            try {
                return fileStream.readAllBytes();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return new byte[0];
        }
    
    
    Vojtech Moravec's avatar
    Vojtech Moravec committed
        public static int[] convertU16BytesToInt(final byte[] bytes) {
            assert (bytes.length % 2 == 0);
            int[] values = new int[bytes.length / 2];
    
    
            int index = 0;
            for (int i = 0; i < bytes.length; i += 2) {
    
    Vojtech Moravec's avatar
    Vojtech Moravec committed
                final int value = (int)(((bytes[i] & 0xff) << 8) | (bytes[i + 1] & 0xff));
                if (value > 0)
                {
                    values[index++] = value;
                    continue;
                }
                values[index++] = value;