Search in sources :

Example 31 with ZipArchiveEntry

use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project AozoraEpub3 by hmdev.

the class Epub3Writer method startSection.

/** セクション開始. 
	 * @throws IOException */
void startSection(int lineNum, int pageType, int imagePageType, String srcImageFilePath) throws IOException {
    this.sectionIndex++;
    String sectionId = decimalFormat.format(this.sectionIndex);
    //package.opf用にファイル名
    SectionInfo sectionInfo = new SectionInfo(sectionId);
    //次の行が単一画像なら画像専用指定
    switch(imagePageType) {
        case PageBreakType.IMAGE_PAGE_W:
            //幅100%指定
            sectionInfo.setImagePage(true);
            sectionInfo.setImageFitW(true);
            break;
        case PageBreakType.IMAGE_PAGE_H:
            //高さ100%指定
            sectionInfo.setImagePage(true);
            sectionInfo.setImageFitH(true);
            break;
        case PageBreakType.IMAGE_PAGE_NOFIT:
            sectionInfo.setImagePage(true);
            break;
    }
    if (pageType == PageBreakType.PAGE_MIDDLE)
        sectionInfo.setMiddle(true);
    else if (pageType == PageBreakType.PAGE_BOTTOM)
        sectionInfo.setBottom(true);
    this.sectionInfos.add(sectionInfo);
    //セクション開始は名称がnullなので改ページ処理で文字列が設定されなければ出力されない 階層レベルは1
    //this.addChapter(null, null, 1);
    this.zos.putArchiveEntry(new ZipArchiveEntry(OPS_PATH + XHTML_PATH + sectionId + ".xhtml"));
    //ヘッダ出力
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(zos, "UTF-8"));
    //出力開始するセクションに対応したSectionInfoを設定
    this.velocityContext.put("sectionInfo", sectionInfo);
    Velocity.mergeTemplate(this.templatePath + OPS_PATH + XHTML_PATH + XHTML_HEADER_VM, "UTF-8", velocityContext, bw);
    bw.flush();
}
Also used : ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) OutputStreamWriter(java.io.OutputStreamWriter) SectionInfo(com.github.hmdev.info.SectionInfo) BufferedWriter(java.io.BufferedWriter)

Example 32 with ZipArchiveEntry

use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project dex2jar by pxb1988.

the class BadZipEntryFlagTest method test1.

@Test
public void test1() throws IOException {
    ZipArchiveInputStream zis = new ZipArchiveInputStream(BadZipEntryFlagTest.class.getResourceAsStream("/bad.zip"));
    for (ZipArchiveEntry e = zis.getNextZipEntry(); e != null; e = zis.getNextZipEntry()) {
        e.getGeneralPurposeBit().useEncryption(false);
        if (!e.isDirectory()) {
            zis.read();
            System.out.println(e.getName());
        }
    }
}
Also used : ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) Test(org.junit.Test)

Example 33 with ZipArchiveEntry

use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.

the class ZipUtils method extractZipFileToFolder.

/**
     * 解压zip文件中的某个文件到指定地方
     *
     * @param zipFile
     * @param path
     * @param destFolder
     * @throws IOException
     */
public static File extractZipFileToFolder(File zipFile, String path, File destFolder) {
    ZipFile zip;
    File destFile = null;
    try {
        zip = new ZipFile(zipFile);
        ZipArchiveEntry zipArchiveEntry = zip.getEntry(path);
        if (null != zipArchiveEntry) {
            String name = zipArchiveEntry.getName();
            name = FilenameUtils.getName(name);
            destFile = new File(destFolder, name);
            destFolder.mkdirs();
            destFile.createNewFile();
            InputStream is = zip.getInputStream(zipArchiveEntry);
            FileOutputStream fos = new FileOutputStream(destFile);
            int length = 0;
            byte[] b = new byte[1024];
            while ((length = is.read(b, 0, 1024)) != -1) {
                fos.write(b, 0, length);
            }
            is.close();
            fos.close();
        }
        if (null != zip)
            ZipFile.closeQuietly(zip);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return destFile;
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IOException(java.io.IOException) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 34 with ZipArchiveEntry

use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.

the class ZipUtils method isFolderExist.

/**
     * 判断在指定的zip目录下,指定的文件夹是否存在
     *
     * @param zipFile
     * @param pathName
     * @return
     */
public static boolean isFolderExist(File zipFile, String pathName) {
    ZipFile file = null;
    try {
        file = new ZipFile(zipFile);
        Enumeration<ZipArchiveEntry> en = file.getEntries();
        while (en.hasMoreElements()) {
            ZipArchiveEntry entry = en.nextElement();
            String name = entry.getName();
            if (name.startsWith(pathName)) {
                return true;
            }
        }
        return false;
    } catch (IOException e) {
    } finally {
        if (null != file) {
            try {
                file.close();
            } catch (IOException e) {
            }
        }
    }
    return false;
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry)

Example 35 with ZipArchiveEntry

use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.

the class ZipUtils method extractZipFileToFolder.

/**
     * 压zip文件中的某个文件到指定地方
     *
     * @param zipFile
     * @param path
     * @param destFolder
     * @throws java.io.IOException
     */
public static File extractZipFileToFolder(File zipFile, String path, File destFolder) {
    ZipFile zip;
    File destFile = null;
    try {
        zip = new ZipFile(zipFile);
        ZipArchiveEntry zipArchiveEntry = zip.getEntry(path);
        if (null != zipArchiveEntry) {
            String name = zipArchiveEntry.getName();
            name = FilenameUtils.getName(name);
            destFile = new File(destFolder, name);
            FileMkUtils.mkdirs(destFolder);
            destFile.createNewFile();
            InputStream is = zip.getInputStream(zipArchiveEntry);
            FileOutputStream fos = new FileOutputStream(destFile);
            int length = 0;
            byte[] b = new byte[1024];
            while ((length = is.read(b, 0, 1024)) != -1) {
                fos.write(b, 0, length);
            }
            is.close();
            fos.close();
        }
        if (null != zip)
            ZipFile.closeQuietly(zip);
    } catch (IOException e) {
    }
    return destFile;
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) ZipInputStream(java.util.zip.ZipInputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile)

Aggregations

ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)46 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)21 IOException (java.io.IOException)13 File (java.io.File)12 FileInputStream (java.io.FileInputStream)10 InputStream (java.io.InputStream)10 Path (java.nio.file.Path)10 Test (org.junit.Test)8 BufferedInputStream (java.io.BufferedInputStream)7 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)7 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)6 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 ImageInfo (com.github.hmdev.info.ImageInfo)4 SectionInfo (com.github.hmdev.info.SectionInfo)4 BufferedWriter (java.io.BufferedWriter)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileNotFoundException (java.io.FileNotFoundException)4