OSDN Git Service

Fix constructor of DictZipInputStream class
authorHiroshi Miura <miurahr@linux.com>
Sat, 29 Jan 2022 03:26:13 +0000 (12:26 +0900)
committerHiroshi Miura <miurahr@linux.com>
Sat, 29 Jan 2022 03:26:13 +0000 (12:26 +0900)
- Reset input position after reading trailer

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
build.gradle
dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java
dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java
dictzip-lib/src/test/resources/test.dsl.dz [new file with mode: 0644]

index db2744f..07464ce 100644 (file)
@@ -4,7 +4,6 @@ plugins {
     id 'java-library'
     id 'maven-publish'
     id 'java-library-distribution'
-    id "signing"
     id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
     id 'com.palantir.git-version' version "0.12.3"
 }
@@ -86,6 +85,7 @@ project(':northside-io') {
 
 project(':dictzip-lib') {
     apply plugin: 'java-library'
+    apply plugin: "signing"
     version = rootProject.version
 
     dependencies {
index 627c234..97cadd2 100644 (file)
@@ -103,7 +103,9 @@ public class DictZipInputStream extends InflaterInputStream {
     public DictZipInputStream(final RandomAccessInputStream in, final int size) throws IOException {
         super(in, new Inflater(true), size);
         header = readHeader();
+        in.mark(in.getLength());
         readTrailer();
+        in.reset();
     }
 
     /**
@@ -123,7 +125,7 @@ public class DictZipInputStream extends InflaterInputStream {
      * Get raw content offset in bytes.
      * @return offset.
      */
-    public final long getPos() {
+    public final long position() {
         return rawOffset;
     }
 
index 4b4d147..305de24 100644 (file)
@@ -57,6 +57,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public class DictZipInputStreamTest {
 
     private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
+    private final String dataFile2 = this.getClass().getResource("/test.dsl.dz").getFile();
 
     /**
      * Test constructor @TestFactory.
@@ -90,7 +91,21 @@ public class DictZipInputStreamTest {
         byte[] buf = new byte[len];
         byte[] expResult = {0x70, 0x72, (byte) 0xc3, (byte) 0xa9, 0x70, 0x2e, 0x20, 0x3a, 0x20, 0x2b};
         try (DictZipInputStream din = new DictZipInputStream(new RandomAccessInputStream(dataFile, "r"), 65534)) {
-            din.seek(0);
+            din.read(buf, 0, len);
+            assertTrue(Arrays.equals(expResult, buf));
+        }
+    }
+
+    /**
+     * Test of read method with another file, of class DictZipInputStream.
+     * @throws Exception when i/o error.
+     */
+    @Test
+    public void testRead2() throws Exception {
+        int len = 10;
+        byte[] buf = new byte[len];
+        byte[] expResult = {(byte)0xFF, (byte)0xFE, 35, 0, 78, 0, 65, 0, 77, 0};
+        try (DictZipInputStream din = new DictZipInputStream(new RandomAccessInputStream(dataFile2, "r"))) {
             din.read(buf, 0, len);
             assertTrue(Arrays.equals(expResult, buf));
         }
diff --git a/dictzip-lib/src/test/resources/test.dsl.dz b/dictzip-lib/src/test/resources/test.dsl.dz
new file mode 100644 (file)
index 0000000..3591eb8
Binary files /dev/null and b/dictzip-lib/src/test/resources/test.dsl.dz differ