Search in sources :

Example 61 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class ZipInputStreamTest method test_closeAfterException.

public void test_closeAfterException() throws Exception {
    File resources = Support_Resources.createTempFolder();
    Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
    FileInputStream fis = new FileInputStream(new File(resources, "Broken_manifest.jar"));
    ZipInputStream zis1 = new ZipInputStream(fis);
    try {
        for (int i = 0; i < 6; i++) {
            zis1.getNextEntry();
        }
        fail("ZipException expected");
    } catch (ZipException ee) {
    // expected
    }
    zis1.close();
    try {
        zis1.getNextEntry();
        fail("IOException expected");
    } catch (IOException ee) {
    // expected
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 62 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class ZipFileTest method test_ConstructorLjava_lang_String.

/**
 * @throws IOException
 * java.util.zip.ZipFile#ZipFile(java.lang.String)
 */
public void test_ConstructorLjava_lang_String() throws IOException {
    // about to reopen the same temp file
    zfile.close();
    ZipFile zip = new ZipFile(tempFileName);
    zip.close();
    File file = File.createTempFile("zip", "tmp");
    try {
        zip = new ZipFile(file.getAbsolutePath());
        fail("ZipException expected");
    } catch (ZipException ee) {
    // expected
    }
    file.delete();
}
Also used : ZipFile(java.util.zip.ZipFile) ZipException(java.util.zip.ZipException) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 63 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class InflaterTest method setUp.

@Override
protected void setUp() {
    try {
        java.io.InputStream infile = Support_Resources.getStream("hyts_compressD.bin");
        BufferedInputStream inflatIP = new BufferedInputStream(infile);
        inflatIP.read(outPutBuff1, 0, outPutBuff1.length);
        inflatIP.close();
        java.io.InputStream infile2 = Support_Resources.getStream("hyts_compDiction.bin");
        BufferedInputStream inflatIP2 = new BufferedInputStream(infile2);
        inflatIP2.read(outPutDiction, 0, outPutDiction.length);
        inflatIP2.close();
    } catch (FileNotFoundException e) {
        fail("input file to test InflaterInputStream constructor is not found");
    } catch (ZipException e) {
        fail("read() threw an zip exception while testing constructor");
    } catch (IOException e) {
        fail("read() threw an exception while testing constructor");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 64 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class AbstractZipFileTest method testSTORED.

public void testSTORED() throws IOException {
    ZipOutputStream out = createZipOutputStream(createTemporaryZipFile());
    CRC32 crc = new CRC32();
    // Missing CRC, size, and compressed size => failure.
    try {
        ZipEntry ze = new ZipEntry("a");
        ze.setMethod(ZipEntry.STORED);
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
    // Missing CRC and compressed size => failure.
    try {
        ZipEntry ze = new ZipEntry("a");
        ze.setMethod(ZipEntry.STORED);
        ze.setSize(0);
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
    // Missing CRC and size => failure.
    try {
        ZipEntry ze = new ZipEntry("a");
        ze.setMethod(ZipEntry.STORED);
        ze.setSize(0);
        ze.setCompressedSize(0);
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
    // Missing size and compressed size => failure.
    try {
        ZipEntry ze = new ZipEntry("a");
        ze.setMethod(ZipEntry.STORED);
        ze.setCrc(crc.getValue());
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
    // Missing size is copied from compressed size.
    {
        ZipEntry ze = new ZipEntry("okay1");
        ze.setMethod(ZipEntry.STORED);
        ze.setCrc(crc.getValue());
        assertEquals(-1, ze.getSize());
        assertEquals(-1, ze.getCompressedSize());
        ze.setCompressedSize(0);
        assertEquals(-1, ze.getSize());
        assertEquals(0, ze.getCompressedSize());
        out.putNextEntry(ze);
        assertEquals(0, ze.getSize());
        assertEquals(0, ze.getCompressedSize());
    }
    // Missing compressed size is copied from size.
    {
        ZipEntry ze = new ZipEntry("okay2");
        ze.setMethod(ZipEntry.STORED);
        ze.setCrc(crc.getValue());
        assertEquals(-1, ze.getSize());
        assertEquals(-1, ze.getCompressedSize());
        ze.setSize(0);
        assertEquals(0, ze.getSize());
        assertEquals(-1, ze.getCompressedSize());
        out.putNextEntry(ze);
        assertEquals(0, ze.getSize());
        assertEquals(0, ze.getCompressedSize());
    }
    // Mismatched size and compressed size => failure.
    try {
        ZipEntry ze = new ZipEntry("a");
        ze.setMethod(ZipEntry.STORED);
        ze.setCrc(crc.getValue());
        ze.setCompressedSize(1);
        ze.setSize(0);
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
    // Everything present => success.
    ZipEntry ze = new ZipEntry("okay");
    ze.setMethod(ZipEntry.STORED);
    ze.setCrc(crc.getValue());
    ze.setSize(0);
    ze.setCompressedSize(0);
    out.putNextEntry(ze);
    out.close();
}
Also used : CRC32(java.util.zip.CRC32) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException)

Example 65 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class OldZipExceptionTest method testZipException.

public void testZipException() {
    ZipException zz = new ZipException();
    assertEquals(zz.getMessage(), null);
}
Also used : ZipException(java.util.zip.ZipException)

Aggregations

ZipException (java.util.zip.ZipException)197 IOException (java.io.IOException)96 File (java.io.File)74 ZipEntry (java.util.zip.ZipEntry)67 ZipFile (java.util.zip.ZipFile)63 InputStream (java.io.InputStream)50 FileInputStream (java.io.FileInputStream)39 ZipInputStream (java.util.zip.ZipInputStream)26 FileOutputStream (java.io.FileOutputStream)23 BufferedInputStream (java.io.BufferedInputStream)22 JarFile (java.util.jar.JarFile)21 FileNotFoundException (java.io.FileNotFoundException)19 JarEntry (java.util.jar.JarEntry)19 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 GZIPInputStream (java.util.zip.GZIPInputStream)12 BufferedOutputStream (java.io.BufferedOutputStream)8 RandomAccessFile (java.io.RandomAccessFile)8