Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.io.IOException;
  9. import java.nio.file.Files;
  10. import java.nio.file.Path;
  11. import java.nio.file.Paths;
  12.  
  13. public class Main {
  14.  
  15. public static void main(String[] args){
  16. try {
  17. File f = new File(FILE_NAME);
  18. FileInputStream fis = new FileInputStream(f);
  19.  
  20. byte[] b = new byte[20000];
  21.  
  22. while (true) {
  23. int n = fis.read(b);
  24. System.out.println("n = " + n);
  25.  
  26. byte type = b[16];
  27. byte code = b[18];
  28. byte value = b[20];
  29.  
  30. if (type == 2 && code == 8) {
  31. if(value == -1) {
  32. System.out.println("Down");
  33. } else {
  34. System.out.println("Up");
  35. }
  36. }
  37.  
  38. // for (int i = 0; i < 12; i++) {
  39. // for (int j = 0; j < 4; j++) {
  40. // System.out.print("" + b[i * 4 + j] + " ");
  41. // }
  42. // System.out.println();
  43. // }
  44.  
  45. System.out.println("type = " + type);
  46. System.out.println("code = " + code);
  47. System.out.println("value = " + value);
  48.  
  49. }
  50.  
  51.  
  52. } catch (FileNotFoundException e) {
  53. e.printStackTrace();
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. }
  57.  
  58. /*
  59. Main binary = new Main();
  60. try {
  61. byte[] bytes = binary.readSmallBinaryFile(FILE_NAME);
  62. System.out.println(bytes.length);
  63. } catch (IOException e) {
  64. e.printStackTrace();
  65. }
  66. */
  67.  
  68.  
  69. }
  70.  
  71. final static String FILE_NAME = "/dev/input/event17";
  72.  
  73. byte[] readSmallBinaryFile(String aFileName) throws IOException {
  74. Path path = Paths.get(aFileName);
  75. System.out.println(path);
  76. return Files.readAllBytes(path);
  77. }
  78.  
  79. private static void log(Object aMsg){
  80. System.out.println(String.valueOf(aMsg));
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement