OSDN Git Service

Not exposed header directory from DictZipInputStream
authorHiroshi Miura <miurahr@linux.com>
Sat, 9 Apr 2016 14:55:28 +0000 (23:55 +0900)
committerHiroshi Miura <miurahr@linux.com>
Sat, 9 Apr 2016 14:55:28 +0000 (23:55 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
dictzip-cli/src/main/java/org/dict/zip/cli/DictData.java
dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java
dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java

index db095d0..32825eb 100644 (file)
@@ -72,15 +72,16 @@ public class DictData {
         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,
index 23b4d24..0cda50f 100644 (file)
@@ -181,7 +181,7 @@ public class DictZipInputStream extends InflaterInputStream {
      * @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();
@@ -242,6 +242,26 @@ public class DictZipInputStream extends InflaterInputStream {
         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.
index 3bc432f..64989a4 100644 (file)
@@ -157,24 +157,4 @@ public class DictZipInputStreamTest {
         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);
-    }
-
 }