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
81 @Override
82 public int getType() {
83 return type;
84 }
85
86
87 @Override
88 public long getSize() {
89 return size;
90 }
91
92
93 @Override
94 public boolean isLarge() {
95 return true;
96 }
97
98
99 @Override
100 public byte[] getCachedBytes() throws LargeObjectException {
101 try {
102 throw new LargeObjectException(getObjectId());
103 } catch (IOException cannotObtainId) {
104 throw new LargeObjectException(cannotObtainId);
105 }
106 }
107
108
109 @Override
110 public ObjectStream openStream() throws MissingObjectException, IOException {
111 WindowCursor wc = new WindowCursor(db);
112 InputStream in;
113 try {
114 in = new PackInputStream(pack, objectOffset + headerLength, wc);
115 } catch (IOException packGone) {
116
117
118
119
120 return wc.open(getObjectId(), type).openStream();
121 }
122
123 in = new BufferedInputStream(
124 new InflaterInputStream(
125 in,
126 wc.inflater(),
127 8192),
128 8192);
129 return new ObjectStream.Filter(type, size, in);
130 }
131
132 private ObjectId getObjectId() throws IOException {
133 return pack.findObjectForOffset(objectOffset);
134 }
135 }