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