1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.internal.storage.file;
45
46 import java.io.BufferedInputStream;
47 import java.io.IOException;
48 import java.io.InputStream;
49 import java.util.zip.InflaterInputStream;
50
51 import org.eclipse.jgit.errors.LargeObjectException;
52 import org.eclipse.jgit.errors.MissingObjectException;
53 import org.eclipse.jgit.lib.ObjectId;
54 import org.eclipse.jgit.lib.ObjectLoader;
55 import org.eclipse.jgit.lib.ObjectStream;
56
57 class LargePackedWholeObject extends ObjectLoader {
58 private final int type;
59
60 private final long size;
61
62 private final long objectOffset;
63
64 private final int headerLength;
65
66 private final PackFile pack;
67
68 private final FileObjectDatabase db;
69
70 LargePackedWholeObject(int type, long size, long objectOffset,
71 int headerLength, PackFile pack, FileObjectDatabase db) {
72 this.type = type;
73 this.size = size;
74 this.objectOffset = objectOffset;
75 this.headerLength = headerLength;
76 this.pack = pack;
77 this.db = db;
78 }
79
80 @Override
81 public int getType() {
82 return type;
83 }
84
85 @Override
86 public long getSize() {
87 return size;
88 }
89
90 @Override
91 public boolean isLarge() {
92 return true;
93 }
94
95 @Override
96 public byte[] getCachedBytes() throws LargeObjectException {
97 try {
98 throw new LargeObjectException(getObjectId());
99 } catch (IOException cannotObtainId) {
100 LargeObjectException err = new LargeObjectException();
101 err.initCause(cannotObtainId);
102 throw err;
103 }
104 }
105
106 @Override
107 public ObjectStream openStream() throws MissingObjectException, IOException {
108 WindowCursor wc = new WindowCursor(db);
109 InputStream in;
110 try {
111 in = new PackInputStream(pack, objectOffset + headerLength, wc);
112 } catch (IOException packGone) {
113
114
115
116
117 return wc.open(getObjectId(), type).openStream();
118 }
119
120 in = new BufferedInputStream(
121 new InflaterInputStream(
122 in,
123 wc.inflater(),
124 8192),
125 8192);
126 return new ObjectStream.Filter(type, size, in);
127 }
128
129 private ObjectId getObjectId() throws IOException {
130 return pack.findObjectForOffset(objectOffset);
131 }
132 }