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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Copyright (C) 2010, Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.internal.storage.file;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.InflaterInputStream;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectStream;
class LargePackedWholeObject extends ObjectLoader {
private final int type;
private final long size;
private final long objectOffset;
private final int headerLength;
private final Pack pack;
private final FileObjectDatabase db;
LargePackedWholeObject(int type, long size, long objectOffset,
int headerLength, Pack pack, FileObjectDatabase db) {
this.type = type;
this.size = size;
this.objectOffset = objectOffset;
this.headerLength = headerLength;
this.pack = pack;
this.db = db;
}
@Override
public int getType() {
return type;
}
@Override
public long getSize() {
return size;
}
@Override
public boolean isLarge() {
return true;
}
@Override
public byte[] getCachedBytes() throws LargeObjectException {
try {
throw new LargeObjectException(getObjectId());
} catch (IOException cannotObtainId) {
throw new LargeObjectException(cannotObtainId);
}
}
@Override
public ObjectStream openStream() throws MissingObjectException, IOException {
WindowCursor wc = new WindowCursor(db);
InputStream in;
try {
in = new PackInputStream(pack, objectOffset + headerLength, wc);
} catch (IOException packGone) {
// If the pack file cannot be pinned into the cursor, it
// probably was repacked recently. Go find the object
// again and open the stream from that location instead.
//
return wc.open(getObjectId(), type).openStream();
}
in = new BufferedInputStream( //
new InflaterInputStream( //
in, //
wc.inflater(), //
8192), //
8192);
return new ObjectStream.Filter(type, size, in);
}
private ObjectId getObjectId() throws IOException {
return pack.findObjectForOffset(objectOffset);
}
}
|