Guest User

Untitled

a guest
Feb 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package gitchen;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.util.Arrays;
  7. import java.util.zip.InflaterInputStream;
  8.  
  9. // a class to look into the private parts of your git repo
  10. public class Read {
  11.  
  12. // path to the object store of your git repo: .git/objects/
  13. static String path = "~/projects/test/.git/objects/";
  14.  
  15. public static void main(String[] args) throws Exception {
  16. if (args.length != 1) {
  17. System.out.println("Please give a SHA as argument.");
  18. return;
  19. }
  20. String sha = args[0];
  21. String prefix = sha.substring(0, 2);
  22. String rest = sha.substring(2);
  23. File file = new File(path+prefix+"\\"+rest);
  24. FileInputStream fin = new FileInputStream(file);
  25. // how many bytes to read? Create the array to take them.
  26. byte[] fileContent = new byte[(int) file.length()];
  27. fin.read(fileContent);
  28. ByteArrayInputStream bais = new ByteArrayInputStream(fileContent);
  29. InflaterInputStream iis = new InflaterInputStream(bais);
  30.  
  31. String result = "";
  32. byte[] buf = new byte[5];
  33. int rlen = -1;
  34. while ((rlen = iis.read(buf)) != -1) {
  35. result += new String(Arrays.copyOf(buf, rlen));
  36. }
  37. System.out.println("Decompress result: \n" + result);
  38. // for quality programming, this would belong into a finally block, of course:
  39. fin.close();
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment