# Read a blob object #IC4 of Git In Java

**URL:** <https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653>\
**Category:** Challenges\
**Tags:** challenge:git\
**Created:** [June 7, 2024, 11:26am UTC](https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653 "2024-06-07T11:26:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarthak1907](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sarthak1907/32/592_2.png) [@Sarthak1907](https://forum.codecrafters.io/u/Sarthak1907)\
**Post date:** [June 7, 2024, 11:26am UTC](https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653/1 "2024-06-07T11:26:06Z")

</div>

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:

```auto
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:

```auto
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);
        }
      }

```

---

<div class="post-metadata">

**Author:** ![Vijaychandra-Govindapalle](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/vijaychandra-govindapalle/32/549_2.png) [@Vijaychandra-Govindapalle](https://forum.codecrafters.io/u/Vijaychandra-Govindapalle)\
**Post date:** [June 7, 2024, 12:47pm UTC](https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653/2 "2024-06-07T12:47:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sarthak1907](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sarthak1907/32/592_2.png) [@Sarthak1907](https://forum.codecrafters.io/u/Sarthak1907)\
**Post date:** [June 8, 2024, 11:37am UTC](https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653/3 "2024-06-08T11:37:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 13, 2024, 11:37am UTC](https://forum.codecrafters.io/t/read-a-blob-object-ic4-of-git-in-java/653/4 "2024-06-13T11:37:59Z")

</div>

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