Always check for a packed object before a loose object.
[egit.git] / org.spearce.jgit / src / org / spearce / jgit / lib / DeltaPackedObjectReader.java
blob5ec037b56a121524ac4700f9b1dcd710a702b6c3
1 package org.spearce.jgit.lib;
3 import java.io.IOException;
4 import java.io.InputStream;
6 /** Reader for a deltafied object stored in a pack file. */
7 abstract class DeltaPackedObjectReader extends PackedObjectReader {
8 DeltaPackedObjectReader(final PackFile pr, final long offset) {
9 super(pr, offset);
10 objectSize = -1;
13 public String getType() throws IOException {
14 if (objectType == null) {
15 final ObjectReader b = baseReader();
16 try {
17 objectType = b.getType();
18 } finally {
19 b.close();
22 return objectType;
25 public long getSize() throws IOException {
26 if (objectSize == -1) {
27 final PatchDeltaStream p;
28 p = new PatchDeltaStream(packStream(), null);
29 objectSize = p.getResultLength();
30 p.close();
32 return objectSize;
35 public InputStream getInputStream() throws IOException {
36 final ObjectReader b = baseReader();
37 final PatchDeltaStream p = new PatchDeltaStream(packStream(), b);
38 if (objectSize == -1)
39 objectSize = p.getResultLength();
40 if (objectType == null)
41 objectType = b.getType();
42 return p;
45 protected abstract ObjectReader baseReader() throws IOException;