Example usage for java.util.zip ZipInputStream close

List of usage examples for java.util.zip ZipInputStream close

Introduction

In this page you can find the example usage for java.util.zip ZipInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:hd3gtv.embddb.network.DataBlock.java

/**
 * Import mode//from w ww  . ja va2  s .  com
 */
DataBlock(Protocol protocol, byte[] request_raw_datas) throws IOException {
    if (log.isTraceEnabled()) {
        log.trace("Get raw datas" + Hexview.LINESEPARATOR + Hexview.tracelog(request_raw_datas));
    }

    ByteArrayInputStream inputstream_client_request = new ByteArrayInputStream(request_raw_datas);

    DataInputStream dis = new DataInputStream(inputstream_client_request);

    byte[] app_socket_header_tag = new byte[Protocol.APP_SOCKET_HEADER_TAG.length];
    dis.readFully(app_socket_header_tag, 0, Protocol.APP_SOCKET_HEADER_TAG.length);

    if (Arrays.equals(Protocol.APP_SOCKET_HEADER_TAG, app_socket_header_tag) == false) {
        throw new IOException("Protocol error with app_socket_header_tag");
    }

    int version = dis.readInt();
    if (version != Protocol.VERSION) {
        throw new IOException(
                "Protocol error with version, this = " + Protocol.VERSION + " and dest = " + version);
    }

    byte tag = dis.readByte();
    if (tag != 0) {
        throw new IOException("Protocol error, can't found request_name raw datas");
    }

    int size = dis.readInt();
    if (size < 1) {
        throw new IOException(
                "Protocol error, can't found request_name raw datas size is too short (" + size + ")");
    }

    byte[] request_name_raw = new byte[size];
    dis.read(request_name_raw);
    request_name = new String(request_name_raw, Protocol.UTF8);

    tag = dis.readByte();
    if (tag != 1) {
        throw new IOException("Protocol error, can't found zip raw datas");
    }

    entries = new ArrayList<>(1);

    ZipInputStream request_zip = new ZipInputStream(dis);

    ZipEntry entry;
    while ((entry = request_zip.getNextEntry()) != null) {
        entries.add(new RequestEntry(entry, request_zip));
    }
    request_zip.close();
}

From source file:br.gov.jfrj.siga.wf.servlet.UploadServlet.java

/**
 * Coloca as informaes do arquivo da definio do processo no banco de
 * dados./*ww w  .ja  v  a 2s.c om*/
 * 
 * @param fileItem
 * @return
 */
private String doDeployment(FileItem fileItem) {
    try {
        ZipInputStream zipInputStream = new ZipInputStream(fileItem.getInputStream());
        JbpmContext jbpmContext = WfContextBuilder.getJbpmContext().getJbpmContext();
        ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
        jbpmContext.deployProcessDefinition(processDefinition);
        zipInputStream.close();
        long id = processDefinition.getId();

        String sReturn = "Deployed archive " + processDefinition.getName() + " successfully";

        // ProcessDefinition pi = jbpmContext.getGraphSession()
        // .loadProcessDefinition(id);

        Delegation d = new Delegation("br.gov.jfrj.siga.wf.util.WfAssignmentHandler");

        for (Swimlane s : ((Collection<Swimlane>) processDefinition.getTaskMgmtDefinition().getSwimlanes()
                .values())) {
            if (s.getTasks() != null)
                for (Object t : s.getTasks()) {
                    System.out.println(((Task) t).toString());
                }
            if (s.getAssignmentDelegation() == null)
                s.setAssignmentDelegation(d);
        }

        for (Task t : ((Collection<Task>) processDefinition.getTaskMgmtDefinition().getTasks().values())) {
            if (t.getSwimlane() == null && t.getAssignmentDelegation() == null)
                t.setAssignmentDelegation(d);
        }

        return sReturn;
    } catch (IOException e) {
        return "IOException";
    }
}

From source file:com.wavemaker.tools.project.upgrade.UpgradeTemplateFile.java

@Override
public void doUpgrade(Project project, UpgradeInfo upgradeInfo) {

    if (this.relativePath == null) {
        throw new WMRuntimeException("No file provided");
    }/* w w  w  .ja va  2s  .c o m*/

    try {
        File localFile = project.getRootFolder().getFile(this.relativePath);

        InputStream resourceStream = this.getClass().getClassLoader()
                .getResourceAsStream(ProjectManager._TEMPLATE_APP_RESOURCE_NAME);
        ZipInputStream resourceZipStream = new ZipInputStream(resourceStream);

        ZipEntry zipEntry = null;

        while ((zipEntry = resourceZipStream.getNextEntry()) != null) {
            if (this.relativePath.equals(zipEntry.getName())) {
                Writer writer = localFile.getContent().asWriter();
                IOUtils.copy(resourceZipStream, writer);
                writer.close();
            }
        }

        resourceZipStream.close();
        resourceStream.close();
    } catch (IOException e) {
        throw new WMRuntimeException(e);
    }

    if (this.message != null) {
        upgradeInfo.addMessage(this.message);
    }
}

From source file:com.aurel.track.admin.customize.category.report.ReportBL.java

/**
 * Save the new template at given location(repository, project)
 * @param repository//from   www.  ja v a 2s.c om
 * @param personID
 * @param project
 * @param templateName
 * @param uploadZip
 * @return an error meassage if exist
 */
public static void saveTemplate(Integer id, ZipInputStream zis) throws IOException {
    // specify buffer size for extraction
    final int BUFFER = 2048;
    // Open Zip file for reading
    File unzipDestinationDirectory = getDirTemplate(id);
    BufferedOutputStream dest = null;
    ZipEntry entry;
    while ((entry = zis.getNextEntry()) != null) {
        File destFile = new File(unzipDestinationDirectory, entry.getName());
        if (destFile.exists()) {
            destFile.delete();
        }
        // grab file's parent directory structure
        File destinationParent = destFile.getParentFile();
        // create the parent directory structure if needed
        destinationParent.mkdirs();
        int count;
        byte data[] = new byte[BUFFER];
        // write the files to the disk
        FileOutputStream fos = new FileOutputStream(destFile);
        dest = new BufferedOutputStream(fos, BUFFER);
        while ((count = zis.read(data, 0, BUFFER)) != -1) {
            dest.write(data, 0, count);
        }
        dest.flush();
        dest.close();
    }
    zis.close();
}

From source file:abfab3d.shapejs.Project.java

private static void extractZip(String zipFile, String outputFolder, Map<String, String> sceneFiles,
        List<String> resources) {
    byte[] buffer = new byte[1024];

    try {//from  w  ww.  j  a v  a2  s.co  m
        //create output directory is not exists
        File folder = new File(outputFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }

        ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry ze = zis.getNextEntry();

        while (ze != null) {
            // Ignore directories
            if (ze.isDirectory())
                continue;

            String fileName = ze.getName();
            File newFile = new File(outputFolder + File.separator + fileName);
            System.out.println("file unzip : " + newFile.getAbsoluteFile());

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            // Save path to the script and parameters files
            if (fileName.endsWith(".json")) {
                sceneFiles.put("paramFile", newFile.getAbsolutePath());
            } else if (fileName.endsWith(".js")) {
                sceneFiles.put("scriptFile", newFile.getAbsolutePath());
            } else {
                resources.add(newFile.getAbsolutePath());
            }

            fos.close();
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:cn.edu.zju.acm.onlinejudge.util.ProblemManager.java

public static ProblemPackage importProblem(InputStream in, ActionMessages messages) {

    Map<String, byte[]> files = new HashMap<String, byte[]>();
    ZipInputStream zis = null;
    try {//from w ww . j  av a 2 s. co  m

        zis = new ZipInputStream(new BufferedInputStream(in));
        // zis = new ZipInputStream(new BufferedInputStream(new FileInputStream("d:/100.zip")));
        ZipEntry entry = zis.getNextEntry();
        while (entry != null) {
            if (!entry.isDirectory()) {

                // TODO the file may be too big. > 100M
                /*
                 * byte data[] = new byte[(int) entry.getSize()]; int l = 0; while (l < data.length) { int ll =
                 * zis.read(data, l, data.length - l); if (ll < 0) { break; } l += ll; }
                 */
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                CopyUtils.copy(zis, buf);
                files.put(entry.getName(), buf.toByteArray());

            }
            entry = zis.getNextEntry();
        }

    } catch (IOException ioe) {
        messages.add("error", new ActionMessage("onlinejudge.importProblem.invalidzip"));
        return null;
    } finally {
        try {
            if (zis != null) {
                zis.close();
            }
        } catch (IOException e) {
            // ignore
        }
    }
    /*
     * files.clear(); files.put("problems.csv", "3,a\n2,b,true,1,2,3,4,a,b,c\n1,c".getBytes());
     * files.put("1\\checker", "checker".getBytes()); files.put("1\\input", "input".getBytes());
     * files.put("1\\output", "output".getBytes()); files.put("3\\checker", "checker3".getBytes());
     * files.put("3\\input", "input3".getBytes()); files.put("3\\output", "output3".getBytes());
     * files.put("images\\1.jpg", "1".getBytes()); files.put("images\\2\\2.jpg", "2".getBytes());
     */
    if (!files.containsKey(ProblemManager.PROBLEM_CSV_FILE)) {
        messages.add("error", new ActionMessage("onlinejudge.importProblem.missingproblemscsv"));
        return null;
    }
    ProblemPackage problemPackage = ProblemManager.parse(files, messages);
    if (messages.size() > 0) {
        return null;
    }
    return problemPackage;
}

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java

public static byte[] getShapeDataFromZip(byte[] localSourceData) {
    byte[] data = null;
    InputStream in = new ByteArrayInputStream(localSourceData);
    ZipInputStream zis = new ZipInputStream(in);
    ZipEntry ze;/*  w ww  . j  ava2  s . co m*/
    try {
        while ((ze = zis.getNextEntry()) != null) {
            if (!ze.isDirectory()) {
                String fileName = ze.getName().toLowerCase();
                if (fileName.endsWith(".shp")) {
                    long entrySize = ze.getSize();
                    if (entrySize != -1) {
                        data = IOUtils.toByteArray(zis, entrySize);
                        break;
                    }
                }
            }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            zis.closeEntry();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            zis.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return data;
}

From source file:be.fedict.eid.applet.service.signer.odf.AbstractODFSignatureService.java

private void outputSignedOpenDocument(byte[] signatureData) throws IOException {
    LOG.debug("output signed open document");
    OutputStream signedOdfOutputStream = getSignedOpenDocumentOutputStream();
    if (null == signedOdfOutputStream) {
        throw new NullPointerException("signedOpenDocumentOutputStream is null");
    }//from w  ww  . ja va 2 s  . c o m
    /*
     * Copy the original ODF content to the signed ODF package.
     */
    ZipOutputStream zipOutputStream = new ZipOutputStream(signedOdfOutputStream);
    ZipInputStream zipInputStream = new ZipInputStream(this.getOpenDocumentURL().openStream());
    ZipEntry zipEntry;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (!zipEntry.getName().equals(ODFUtil.SIGNATURE_FILE)) {
            zipOutputStream.putNextEntry(zipEntry);
            IOUtils.copy(zipInputStream, zipOutputStream);
        }
    }
    zipInputStream.close();
    /*
     * Add the ODF XML signature file to the signed ODF package.
     */
    zipEntry = new ZipEntry(ODFUtil.SIGNATURE_FILE);
    zipOutputStream.putNextEntry(zipEntry);
    IOUtils.write(signatureData, zipOutputStream);
    zipOutputStream.close();
}

From source file:org.dhatim.ect.formats.unedifact.UnEdifactSpecificationReader.java

private void readDefinitionEntries(ZipInputStream folderZip, ZipDirectoryEntry... entries) throws IOException {

    ZipEntry fileEntry = folderZip.getNextEntry();
    while (fileEntry != null) {
        String fName = new File(fileEntry.getName().toLowerCase()).getName().replaceFirst("tr", "ed");
        for (ZipDirectoryEntry entry : entries) {
            if (fName.startsWith(entry.getDirectory())) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                byte[] bytes = new byte[BUFFER];
                int size;
                while ((size = folderZip.read(bytes, 0, bytes.length)) != -1) {
                    baos.write(bytes, 0, size);
                }//from w ww  .j a  v a 2s .c  o m

                ZipInputStream zipInputStream = new ZipInputStream(
                        new ByteArrayInputStream(baos.toByteArray()));
                readZipEntry(entry.getEntries(), zipInputStream, entry.getFile());
                zipInputStream.close();
            }
        }
        folderZip.closeEntry();
        fileEntry = folderZip.getNextEntry();
    }
}

From source file:com.wavemaker.tools.project.upgrade.five_dot_zero.WebXmlUpgradeTask.java

@Override
public void doUpgrade(Project project, UpgradeInfo upgradeInfo) {

    File webXml = project.getWebXmlFile();
    if (webXml.exists()) {
        try {/*from  w ww.  ja  v a2s.co m*/
            File webXmlBak = project.getWebInfFolder().getFile(WEB_XML_BACKUP);
            webXmlBak.getContent().write(webXml);
            webXml.delete();
            File userWebXml = project.getWebInfFolder().getFile(ProjectConstants.USER_WEB_XML);
            InputStream resourceStream = this.getClass().getClassLoader()
                    .getResourceAsStream(ProjectManager._TEMPLATE_APP_RESOURCE_NAME);
            ZipInputStream resourceZipStream = new ZipInputStream(resourceStream);

            ZipEntry zipEntry = null;

            while ((zipEntry = resourceZipStream.getNextEntry()) != null) {
                if ("webapproot/WEB-INF/user-web.xml".equals(zipEntry.getName())) {
                    Writer writer = userWebXml.getContent().asWriter();
                    IOUtils.copy(resourceZipStream, writer);
                    writer.close();
                }
            }

            resourceZipStream.close();
            resourceStream.close();
        } catch (IOException e) {
            throw new WMRuntimeException(e);
        }

        upgradeInfo.addMessage("The web.xml file has changed.  If you have custom"
                + "modifications, please copy them from " + WEB_XML_BACKUP + " to the new user-web.xml.");
    }
}