List of usage examples for java.util.zip ZipInputStream read
public int read(byte[] b, int off, int len) throws IOException
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Import plugins (JAR) from within a zip content. * @param zip/*from ww w . j av a2s . c om*/ * @throws Exception */ public void importPlugins(byte[] zip) throws Exception { ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(zip)); ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { if (entry.getName().endsWith(".jar")) { int length; byte[] temp = new byte[1024]; while ((length = in.read(temp, 0, 1024)) != -1) { out.write(temp, 0, length); } pluginManager.upload(entry.getName(), new ByteArrayInputStream(out.toByteArray())); } out.flush(); out.close(); } in.close(); }
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Reads XPDL from zip content./*from w ww . j a v a 2 s . com*/ * @param zip * @return * @throws Exception */ public byte[] getXpdlFromZip(byte[] zip) throws Exception { ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(zip)); ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { if (entry.getName().endsWith(".xpdl")) { int length; byte[] temp = new byte[1024]; while ((length = in.read(temp, 0, 1024)) != -1) { out.write(temp, 0, length); } return out.toByteArray(); } out.flush(); out.close(); } in.close(); return null; }
From source file:org.joget.apps.app.service.AppServiceImpl.java
/** * Reads app XML from zip content.//from w w w .j a v a2s.c om * @param zip * @return * @throws java.lang.Exception */ public byte[] getAppDataXmlFromZip(byte[] zip) throws Exception { ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(zip)); ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { if (entry.getName().contains("appDefinition.xml")) { int length; byte[] temp = new byte[1024]; while ((length = in.read(temp, 0, 1024)) != -1) { out.write(temp, 0, length); } return out.toByteArray(); } out.flush(); out.close(); } in.close(); return null; }
From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java
private void extractJSEmbedding(final JSEmbeddingItemTO packet) throws BrandingFailureException, NoSuchAlgorithmException, FileNotFoundException, IOException { File brandingCache = getJSEmbeddingPacketFile(packet.name); if (!brandingCache.exists()) throw new BrandingFailureException("Javascript package not found!"); File jsRootDir = getJSEmbeddingRootDirectory(); if (!(jsRootDir.exists() || jsRootDir.mkdir())) throw new BrandingFailureException("Could not create private javascript dir!"); File jsPacketDir = getJSEmbeddingPacketDirectory(packet.name); if (jsPacketDir.exists() && !SystemUtils.deleteDir(jsPacketDir)) throw new BrandingFailureException("Could not delete existing javascript dir"); if (!jsPacketDir.mkdir()) throw new BrandingFailureException("Could not create javascript dir"); MessageDigest digester = MessageDigest.getInstance("SHA256"); DigestInputStream dis = new DigestInputStream(new BufferedInputStream(new FileInputStream(brandingCache)), digester);/* w ww. ja va 2 s. c om*/ try { ZipInputStream zis = new ZipInputStream(dis); try { byte data[] = new byte[BUFFER_SIZE]; ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { L.d("Extracting: " + entry); int count = 0; if (entry.isDirectory()) { L.d("Skipping javascript dir " + entry.getName()); continue; } File destination = new File(jsPacketDir, entry.getName()); destination.getParentFile().mkdirs(); final OutputStream fos = new BufferedOutputStream(new FileOutputStream(destination), BUFFER_SIZE); try { while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) { fos.write(data, 0, count); } } finally { fos.close(); } } while (dis.read(data) >= 0) ; } finally { zis.close(); } } finally { dis.close(); } }
From source file:usbong.android.utils.UsbongUtils.java
public static void unzip(String zipFile, String location) throws IOException { final int BUFFER_SIZE = 8192;//1024; //65536; int size;//from w w w .j a v a 2 s .co m byte[] buffer = new byte[BUFFER_SIZE]; ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile), BUFFER_SIZE)); try { Log.d(">>>>>>>", "1"); File f = new File(location); if (!f.exists()) { if (!f.isDirectory()) { f.mkdirs(); Log.d(">>>>>>>", "1.5: f.mkdirs()"); } } Log.d(">>>>>>>", "2"); // zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile), BUFFER_SIZE)); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { String path = location + ze.getName(); Log.d(">>>>>>>", "3"); Log.d(">>>>>>>", "location: " + location); Log.d(">>>>>>>", "ze.getName(): " + ze.getName()); if (ze.isDirectory()) { Log.d(">>>>>>>", "4.1"); File unzipFile = new File(path); Log.d(">>>>>>>", "5.1"); Log.d(">>>>>>>", "path: " + path); if (!unzipFile.isDirectory()) { Log.d(">>>>>>>", "6.1"); unzipFile.mkdirs(); Log.d(">>>>>>>", "7.1"); } } else { Log.d(">>>>>>>", "4.2"); File file = new File(path); file.createNewFile(); FileOutputStream out = new FileOutputStream(path, false); BufferedOutputStream fout = new BufferedOutputStream(out, BUFFER_SIZE); try { while ((size = zin.read(buffer, 0, BUFFER_SIZE)) != -1) { Log.d(">>>>>>>", "4.3"); fout.write(buffer, 0, size); } Log.d(">>>>>>>", "4.4"); zin.closeEntry(); } finally { fout.flush(); fout.close(); } } } } catch (Exception e) { Log.e(TAG, "Unzip exception (Inner Exception)", e); } } catch (Exception e) { Log.e(TAG, "Unzip exception (Outer Exception)", e); } finally { zin.close(); } }
From source file:net.cbtltd.rest.interhome.A_Handler.java
/** * Get unzipped input stream for file name. * * @param fn the file name./*ww w .ja va2 s .com*/ * @return the input stream. * @throws Throwable the exception that can be thrown. */ private final synchronized FileInputStream ftp(String fn) throws Throwable { URL url = new URL("ftp://ihxmlpartner:S13oPjEu@ftp.interhome.com/" + fn + ".zip;type=i"); URLConnection urlc = url.openConnection(); byte[] buf = new byte[1024]; ZipInputStream zinstream = new ZipInputStream(new BufferedInputStream(urlc.getInputStream())); ZipEntry zentry = zinstream.getNextEntry(); String entryName = zentry.getName(); FileOutputStream outstream = new FileOutputStream(entryName); int n; while ((n = zinstream.read(buf, 0, 1024)) > -1) { outstream.write(buf, 0, n); } outstream.close(); zinstream.closeEntry(); zinstream.close(); return new FileInputStream(entryName); }
From source file:hu.sztaki.lpds.pgportal.services.asm.ASMService.java
private void convertOutputZip(String userId, String workflowId, String jobId, String fileName, InputStream is, OutputStream os) throws IOException { InputStream exactFile = null; ZipInputStream zis = new ZipInputStream(is); ZipEntry entry;/*ww w. j ava 2 s .co m*/ String runtimeID = getRuntimeID(userId, workflowId); ZipOutputStream zos = new ZipOutputStream(os); while ((entry = zis.getNextEntry()) != null) { if (jobId == null || (entry.getName().contains(jobId + "/outputs/" + runtimeID + "/") && (fileName == null || (fileName != null && entry.getName().endsWith(fileName))))) { int size; byte[] buffer = new byte[2048]; String parentDir = entry.getName().split("/")[entry.getName().split("/").length - 2]; String fileNameInZip = parentDir + "/" + entry.getName().split("/")[entry.getName().split("/").length - 1]; ZipEntry newFile = new ZipEntry(fileNameInZip); zos.putNextEntry(newFile); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { zos.write(buffer, 0, size); } zos.closeEntry(); } } zis.close(); zos.close(); }
From source file:de.intranda.goobi.plugins.CSICMixedImport.java
/** * Unzip a zip archive and write results into Array of Strings * // www . j a v a 2 s . com * @param source * @return */ private HashMap<String, byte[]> unzipFile(File source) { ArrayList<String> filenames = new ArrayList<String>(); HashMap<String, byte[]> contentMap = new HashMap<String, byte[]>(); FileInputStream fis = null; BufferedInputStream bis = null; ZipInputStream in = null; try { fis = new FileInputStream(source); bis = new BufferedInputStream(fis); in = new ZipInputStream(bis); ZipEntry entry; while ((entry = in.getNextEntry()) != null) { filenames.add(entry.getName()); logger.debug("Unzipping file " + entry.getName() + " from archive " + source.getName()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream out = new BufferedOutputStream(baos); int size; byte[] buffer = new byte[2048]; while ((size = in.read(buffer, 0, buffer.length)) != -1) { out.write(buffer, 0, size); } if (entry != null) in.closeEntry(); if (out != null) { out.close(); } if (baos != null) { baos.close(); } contentMap.put(entry.getName(), baos.toByteArray()); } } catch (IOException e) { logger.error(e.toString(), e); } finally { try { if (fis != null) { fis.close(); } if (bis != null) { bis.close(); } if (in != null) { in.close(); } } catch (IOException e) { logger.error(e.toString(), e); } } return contentMap; }
From source file:org.openmeetings.servlet.outputhandler.BackupImportController.java
public void performImport(InputStream is, String current_dir) throws Exception { File working_dir = new File(current_dir, OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar + "import"); if (!working_dir.exists()) { working_dir.mkdir();/*from w w w. j av a 2s.co m*/ } File f = new File(working_dir, "import_" + CalendarPatterns.getTimeForStreamId(new Date())); int recursiveNumber = 0; do { if (f.exists()) { f = new File(f.getAbsolutePath() + (recursiveNumber++)); } } while (f.exists()); f.mkdir(); log.debug("##### WRITE FILE TO: " + f); ZipInputStream zipinputstream = new ZipInputStream(is); byte[] buf = new byte[1024]; ZipEntry zipentry = zipinputstream.getNextEntry(); while (zipentry != null) { // for each entry to be extracted int n; FileOutputStream fileoutputstream; File fentryName = new File(f, zipentry.getName()); if (zipentry.isDirectory()) { if (!fentryName.mkdir()) { break; } zipentry = zipinputstream.getNextEntry(); continue; } File fparent = new File(fentryName.getParent()); if (!fparent.exists()) { File fparentparent = new File(fparent.getParent()); if (!fparentparent.exists()) { File fparentparentparent = new File(fparentparent.getParent()); if (!fparentparentparent.exists()) { fparentparentparent.mkdir(); fparentparent.mkdir(); fparent.mkdir(); } else { fparentparent.mkdir(); fparent.mkdir(); } } else { fparent.mkdir(); } } fileoutputstream = new FileOutputStream(fentryName); while ((n = zipinputstream.read(buf, 0, 1024)) > -1) { fileoutputstream.write(buf, 0, n); } fileoutputstream.close(); zipinputstream.closeEntry(); zipentry = zipinputstream.getNextEntry(); } // while zipinputstream.close(); /* * ##################### Import Organizations */ File orgFile = new File(f, "organizations.xml"); if (!orgFile.exists()) { throw new Exception("organizations.xml missing"); } this.importOrganizsations(orgFile); log.info("Organizations import complete, starting user import"); /* * ##################### Import Users */ File userFile = new File(f, "users.xml"); if (!userFile.exists()) { throw new Exception("users.xml missing"); } this.importUsers(userFile); log.info("Users import complete, starting room import"); /* * ##################### Import Rooms */ File roomFile = new File(f, "rooms.xml"); if (!roomFile.exists()) { throw new Exception("rooms.xml missing"); } this.importRooms(roomFile); log.info("Room import complete, starting room organizations import"); /* * ##################### Import Room Organisations */ File orgRoomListFile = new File(f, "rooms_organisation.xml"); if (!orgRoomListFile.exists()) { throw new Exception("rooms_organisation.xml missing"); } this.importOrgRooms(orgRoomListFile); log.info("Room organizations import complete, starting appointement import"); /* * ##################### Import Appointements */ File appointementListFile = new File(f, "appointements.xml"); if (!appointementListFile.exists()) { throw new Exception("appointements.xml missing"); } this.importAppointements(appointementListFile); log.info("Appointement import complete, starting meeting members import"); /* * ##################### Import MeetingMembers * * Reminder Invitations will be NOT send! */ File meetingmembersListFile = new File(f, "meetingmembers.xml"); if (!meetingmembersListFile.exists()) { throw new Exception("meetingmembersListFile missing"); } this.importMeetingmembers(meetingmembersListFile); log.info("Meeting members import complete, starting ldap config import"); /* * ##################### Import LDAP Configs */ File ldapConfigListFile = new File(f, "ldapconfigs.xml"); if (!ldapConfigListFile.exists()) { log.debug("meetingmembersListFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importLdapConfig(ldapConfigListFile); } log.info("Ldap config import complete, starting recordings import"); /* * ##################### Import Recordings */ File flvRecordingsListFile = new File(f, "flvRecordings.xml"); if (!flvRecordingsListFile.exists()) { log.debug("flvRecordingsListFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importFlvRecordings(flvRecordingsListFile); } log.info("FLVrecording import complete, starting private message folder import"); /* * ##################### Import Private Message Folders */ File privateMessageFoldersFile = new File(f, "privateMessageFolder.xml"); if (!privateMessageFoldersFile.exists()) { log.debug("privateMessageFoldersFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importPrivateMessageFolders(privateMessageFoldersFile); } log.info("Private message folder import complete, starting private message import"); /* * ##################### Import Private Messages */ File privateMessagesFile = new File(f, "privateMessages.xml"); if (!privateMessagesFile.exists()) { log.debug("privateMessagesFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importPrivateMessages(privateMessagesFile); } log.info("Private message import complete, starting usercontact import"); /* * ##################### Import User Contacts */ File userContactsFile = new File(f, "userContacts.xml"); if (!userContactsFile.exists()) { log.debug("userContactsFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importUserContacts(userContactsFile); } log.info("Usercontact import complete, starting file explorer item import"); /* * ##################### Import File-Explorer Items */ File fileExplorerListFile = new File(f, "fileExplorerItems.xml"); if (!fileExplorerListFile.exists()) { log.debug("fileExplorerListFile missing"); // throw new Exception // ("meetingmembersListFile missing"); } else { this.importFileExplorerItems(fileExplorerListFile); } log.info("File explorer item import complete, starting file poll import"); /* * ##################### Import Room Polls */ File roomPollListFile = new File(f, "roompolls.xml"); if (!roomPollListFile.exists()) { log.debug("roomPollListFile missing"); } else { this.importRoomPolls(roomPollListFile); } log.info("Poll import complete, starting configs import"); /* * ##################### Import Configs */ File configsFile = new File(f, "configs.xml"); if (!configsFile.exists()) { log.debug("configsFile missing"); } else { importConfigs(configsFile); } log.info("Configs import complete, starting asteriskSipUsersFile import"); /* * ##################### Import AsteriskSipUsers */ File asteriskSipUsersFile = new File(f, "asterisksipusers.xml"); if (!asteriskSipUsersFile.exists()) { log.debug("asteriskSipUsersFile missing"); } else { importAsteriskSipUsers(asteriskSipUsersFile); } log.info("AsteriskSipUsers import complete, starting extensions import"); /* * ##################### Import Extensions */ File extensionsFile = new File(f, "extensions.xml"); if (!extensionsFile.exists()) { log.debug("extensionsFile missing"); } else { importExtensions(extensionsFile); } log.info("Extensions import complete, starting members import"); /* * ##################### Import Extensions */ File membersFile = new File(f, "members.xml"); if (!membersFile.exists()) { log.debug("membersFile missing"); } else { importMembers(membersFile); } log.info("Members import complete, starting copy of files and folders"); /* * ##################### Import real files and folders */ importFolders(current_dir, f); log.info("File explorer item import complete, clearing temp files"); deleteDirectory(f); }
From source file:org.exoplatform.faq.service.impl.JCRDataStorage.java
@Override public boolean importData(String parentId, InputStream inputStream, boolean isZip) throws Exception { SessionProvider sProvider = CommonUtils.createSystemProvider(); List<String> patchNodeImport = new ArrayList<String>(); Node categoryNode = getFAQServiceHome(sProvider).getNode(parentId); Session session = categoryNode.getSession(); NodeIterator iter = categoryNode.getNodes(); while (iter.hasNext()) { patchNodeImport.add(iter.nextNode().getName()); }/*from www . j av a 2 s .c om*/ if (isZip) { // Import from zipfile ZipInputStream zipStream = new ZipInputStream(inputStream); while (zipStream.getNextEntry() != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); int available = -1; byte[] data = new byte[2048]; while ((available = zipStream.read(data, 0, 1024)) > -1) { out.write(data, 0, available); } zipStream.closeEntry(); out.close(); InputStream input = new ByteArrayInputStream(out.toByteArray()); session.importXML(categoryNode.getPath(), input, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); session.save(); } zipStream.close(); calculateImportRootCategory(categoryNode); } else { // import from xml session.importXML(categoryNode.getPath(), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); session.save(); } categoryNode = (Node) session.getItem(categoryNode.getPath()); iter = categoryNode.getNodes(); while (iter.hasNext()) { Node node = iter.nextNode(); if (patchNodeImport.contains(node.getName())) patchNodeImport.remove(node.getName()); else patchNodeImport.add(node.getName()); } for (String string : patchNodeImport) { Node nodeParentQuestion = categoryNode.getNode(string); iter = getQuestionsIterator(nodeParentQuestion, EMPTY_STR, true); // Update number answers and regeister question node listener while (iter.hasNext()) { Node node = iter.nextNode(); reUpdateNumberOfPublicAnswers(node); } } return true; }