Read a blob object #IC4 of Git In Java

I’m stuck on Stage #(#IC4).

I am trying to read the blob file but there seems to be some error and every time the test cases are failing. I have tried everything, even referred the code examples, but nothing seems to be working. Please help.

Here are my logs:

remote: [tester::#IC4] Running tests for Stage #IC4 (Read a blob object)
remote: [tester::#IC4] $ ./your_git.sh init
remote: [your_program] Logs from your program will appear here!
remote: [your_program] Initialized git directory
remote: [tester::#IC4] Added blob object to .git/objects: 6047f8fc18433ba22022e8a356c8539034219088
remote: [tester::#IC4] $ ./your_git.sh cat-file -p 6047f8fc18433ba22022e8a356c8539034219088
remote: [your_program] Logs from your program will appear here!
remote: [your_program] monkey doo scooby donkey doo donkey
remote: [tester::#IC4] Expected "monkey doo scooby donkey doo donkey" as stdout, got: "Logs from your program will appear here!\nmonkey doo scooby donkey doo donkey"

And here’s a snippet of my code:

case "cat-file" -> {
        String hash = args[2];
        String dirHash = hash.substring(0, 2);
        String fileHash = hash.substring(2);
        File blobFile = new File("./.git/objects/" + dirHash + "/" + fileHash);
        try(BufferedReader blobRead = new BufferedReader (new InputStreamReader(new InflaterInputStream(new FileInputStream(blobFile))))) {
          String blob = blobRead.readLine();
          String content = blob.substring(blob.indexOf("\0")+1);
          System.out.print(content);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

As it shows in the logs that the expected value and value got is different and the difference is the “Logs from your program will appear!\n” sentence. This sentence is getting added to the stdout. Commenting out the part that adds this sentence should do the work.

2 Likes

Thank you. I forgot to see the first line of the predefined program.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.