1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress.harmony.unpack200;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23
24 import org.apache.commons.compress.harmony.pack200.Codec;
25 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
26 import org.apache.commons.compress.utils.IOUtils;
27
28
29
30
31
32
33 public class FileBands extends BandSet {
34
35 private byte[][] fileBits;
36
37 private int[] fileModtime;
38
39 private String[] fileName;
40
41 private int[] fileOptions;
42
43 private long[] fileSize;
44
45 private final String[] cpUTF8;
46
47 private InputStream in;
48
49
50
51
52 public FileBands(final Segment segment) {
53 super(segment);
54 this.cpUTF8 = segment.getCpBands().getCpUTF8();
55 }
56
57 public byte[][] getFileBits() {
58 return fileBits;
59 }
60
61 public int[] getFileModtime() {
62 return fileModtime;
63 }
64
65 public String[] getFileName() {
66 return fileName;
67 }
68
69 public int[] getFileOptions() {
70 return fileOptions;
71 }
72
73 public long[] getFileSize() {
74 return fileSize;
75 }
76
77
78 public void processFileBits() throws IOException {
79
80 final int numberOfFiles = header.getNumberOfFiles();
81 fileBits = new byte[numberOfFiles][];
82 for (int i = 0; i < numberOfFiles; i++) {
83 final int size = (int) fileSize[i];
84 fileBits[i] = IOUtils.readRange(in, size);
85 final int read = fileBits[i].length;
86 if (size != 0 && read < size) {
87 throw new IOException("Expected to read " + size + " bytes but read " + read);
88 }
89 }
90 }
91
92
93
94
95
96
97 @Override
98 public void read(final InputStream in) throws IOException, Pack200Exception {
99 final int numberOfFiles = header.getNumberOfFiles();
100 final SegmentOptions options = header.getOptions();
101
102 fileName = parseReferences("file_name", in, Codec.UNSIGNED5, numberOfFiles, cpUTF8);
103 fileSize = parseFlags("file_size", in, numberOfFiles, Codec.UNSIGNED5, options.hasFileSizeHi());
104 if (options.hasFileModtime()) {
105 fileModtime = decodeBandInt("file_modtime", in, Codec.DELTA5, numberOfFiles);
106 } else {
107 fileModtime = new int[numberOfFiles];
108 }
109 if (options.hasFileOptions()) {
110 fileOptions = decodeBandInt("file_options", in, Codec.UNSIGNED5, numberOfFiles);
111 } else {
112 fileOptions = new int[numberOfFiles];
113 }
114 this.in = in;
115
116 }
117
118 @Override
119 public void unpack() {
120
121 }
122
123 }