1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.dfs;
12
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17
18 import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
19
20
21
22
23
24 public class DfsReftableStack implements AutoCloseable {
25
26
27
28
29
30
31
32
33
34
35
36
37 public static DfsReftableStack open(DfsReader ctx, List<DfsReftable> files)
38 throws IOException {
39 DfsReftableStack stack = new DfsReftableStack(files.size());
40 boolean close = true;
41 try {
42 for (DfsReftable t : files) {
43 stack.files.add(t);
44 stack.tables.add(t.open(ctx));
45 }
46 close = false;
47 return stack;
48 } finally {
49 if (close) {
50 stack.close();
51 }
52 }
53 }
54
55 private final List<DfsReftable> files;
56 private final List<ReftableReader> tables;
57
58 private DfsReftableStack(int tableCnt) {
59 this.files = new ArrayList<>(tableCnt);
60 this.tables = new ArrayList<>(tableCnt);
61 }
62
63
64
65
66
67
68
69 public List<DfsReftable> files() {
70 return Collections.unmodifiableList(files);
71 }
72
73
74
75
76
77
78
79 public List<ReftableReader> readers() {
80 return Collections.unmodifiableList(tables);
81 }
82
83
84 @Override
85 public void close() {
86 for (ReftableReader t : tables) {
87 try {
88 t.close();
89 } catch (IOException e) {
90
91 }
92 }
93 }
94 }