Utils.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package de.nplusc.izc.senabitwiggler;
  2. import com.google.common.primitives.Longs;
  3. import javax.swing.*;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.PrintStream;
  7. import java.util.Arrays;
  8. import java.util.Locale;
  9. public class Utils {
  10. public static byte[] LongToRawBytes(long l)
  11. {
  12. byte[] tmp = Longs.toByteArray(l);
  13. return new byte[]{tmp[7],tmp[6],tmp[5],tmp[4]};
  14. }
  15. public static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
  16. public static String bytesToHex(byte[] bytes) {
  17. char[] hexChars = new char[bytes.length * 2];
  18. for (int j = 0; j < bytes.length; j++) {
  19. int v = bytes[j] & 0xFF;
  20. hexChars[j * 2] = HEX_ARRAY[v >>> 4];
  21. hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
  22. }
  23. String hexxit = new String(hexChars).toLowerCase(Locale.ROOT);
  24. //hexxit = hexxit.replaceAll("^0+", "");
  25. return hexxit;
  26. }
  27. public static void makeSureThatOutFolderIsCreated(String output)
  28. {
  29. File od = (new File(output));
  30. if(!(od.exists()&&od.isDirectory()))
  31. {
  32. if(!od.mkdirs())
  33. {
  34. System.err.println("WTF! somethint ate shit");
  35. return;
  36. }
  37. }
  38. }
  39. public static short xorsum(short[] filewords)
  40. {
  41. short xorsum = 0;
  42. for(int i=0;i<filewords.length;i++)
  43. {
  44. xorsum ^= filewords[i];
  45. }
  46. return xorsum;
  47. }
  48. }