Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gitchen;
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.util.Arrays;
- import java.util.zip.InflaterInputStream;
- // a class to look into the private parts of your git repo
- public class Read {
- // path to the object store of your git repo: .git/objects/
- static String path = "~/projects/test/.git/objects/";
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.out.println("Please give a SHA as argument.");
- return;
- }
- String sha = args[0];
- String prefix = sha.substring(0, 2);
- String rest = sha.substring(2);
- File file = new File(path+prefix+"\\"+rest);
- FileInputStream fin = new FileInputStream(file);
- // how many bytes to read? Create the array to take them.
- byte[] fileContent = new byte[(int) file.length()];
- fin.read(fileContent);
- ByteArrayInputStream bais = new ByteArrayInputStream(fileContent);
- InflaterInputStream iis = new InflaterInputStream(bais);
- String result = "";
- byte[] buf = new byte[5];
- int rlen = -1;
- while ((rlen = iis.read(buf)) != -1) {
- result += new String(Arrays.copyOf(buf, rlen));
- }
- System.out.println("Decompress result: \n" + result);
- // for quality programming, this would belong into a finally block, of course:
- fin.close();
- }
- }
Add Comment
Please, Sign In to add comment