RandomAccessFile targetRaFile = new RandomAccessFile(targetFile, "r");
try (RandomAccessInputStream in = new RandomAccessInputStream(targetRaFile);
DictZipInputStream din = new DictZipInputStream(in);) {
+ // These three parameters are able to get only from din.
long uncomp = din.getLength();
long comp = din.getCompLength();
long crc = din.getCrc();
- DictZipHeader header = din.readHeader();
- String type = header.getType();
- int chunkLength = header.getChunkLength();
- int chunkCount = header.getChunkCount();
- Date mtime = new Date(header.getMtime() * 1000);
- String filename = header.getFilename();
+ // Get header parameters.
+ String type = din.getType();
+ int chunkLength = din.getChunkLength();
+ int chunkCount = din.getChunkCount();
+ Date mtime = new Date(din.getMtime() * 1000);
+ String filename = din.getFilename();
Format timeFormatter = new SimpleDateFormat("MMMM dd, yyyy hh:mm:ss");
System.out.println(RESOURCE_BUNDLE.getString("dictzip.header.title"));
System.out.print(String.format("%s\t%08x\t%s\t", type, crc,
* @return header object.
* @exception IOException if an I/O error has occurred.
*/
- public final DictZipHeader readHeader() throws IOException {
+ private final DictZipHeader readHeader() throws IOException {
if (header == null) {
header = DictZipHeader.readHeader(in, crc);
crc.reset();
return compLength;
}
+ public String getType() throws IOException {
+ return header.getType();
+ }
+
+ public int getChunkLength() throws IOException {
+ return header.getChunkLength();
+ }
+
+ public int getChunkCount() throws IOException {
+ return header.getChunkCount();
+ }
+
+ public long getMtime() throws IOException {
+ return header.getMtime();
+ }
+
+ public String getFilename() throws IOException {
+ return header.getFilename();
+ }
+
/**
* Check gzip member trailer; CRC and length.
* @throws IOException when CRC error or total length error.
assertEquals(din.getCrc(), 0x024d1f37);
assertEquals(din.getLength(), 383783);
}
-
- /**
- * Test of readHeader method, of class DictZipInputStream.
- * @throws java.lang.Exception
- */
- @Test
- public void testReadHeader() throws Exception {
- System.out.println("readHeader");
- header = din.readHeader();
- StringBuilder sb = new StringBuilder();
- sb.append("\nHeader length = 49");
- sb.append("\nSubfield ID = RA");
- sb.append("\nSubfield length = 20");
- sb.append("\nSubfield version = 1");
- sb.append("\nChunk length = 58315");
- sb.append("\nNumber of chunks = 7");
- String expResult = sb.toString();
- assertEquals(header.toString(), expResult);
- }
-
}