Java Code Examples for java.util.zip.ZipFile#getName()

The following examples show how to use java.util.zip.ZipFile#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BirtWizardUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * extract zip file and import files into project
 * 
 * @param srcZipFile
 * @param destPath
 * @param monitor
 * @param query
 * @throws CoreException
 */
private static void importFilesFromZip( ZipFile srcZipFile, IPath destPath,
		IProgressMonitor monitor, IOverwriteQuery query )
		throws CoreException
{
	try
	{
		ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
				srcZipFile );
		List list = prepareFileList( structureProvider, structureProvider
				.getRoot( ), null );
		ImportOperation op = new ImportOperation( destPath,
				structureProvider.getRoot( ), structureProvider, query,
				list );
		op.run( monitor );
	}
	catch ( Exception e )
	{
		String message = srcZipFile.getName( ) + ": " + e.getMessage( ); //$NON-NLS-1$
		Logger.logException( e );
		throw BirtCoreException.getException( message, e );
	}
}
 
Example 2
Source File: XmlZipPersistence.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
NamedBufferedInputStream getReTestXmlInStream( final ZipFile zipFile ) throws IOException {
	final ZipEntry entry = zipFile.getEntry( DEFAULT_XML_FILE_NAME );
	if ( entry == null ) {
		throw new IllegalArgumentException( "Given ZIP file " + zipFile.getName()
				+ " did not contain an entry named " + DEFAULT_XML_FILE_NAME + "!" );
	}
	return new NamedBufferedInputStream( zipFile.getInputStream( entry ), zipFile.getName() );
}
 
Example 3
Source File: AesZipFileEncrypter.java    From fingen with Apache License 2.0 5 votes vote down vote up
protected void add(ZipFile inFile, String password) throws IOException,
		UnsupportedEncodingException {
	ZipFileEntryInputStream zfe = new ZipFileEntryInputStream(inFile.getName());			
	try {
		Enumeration<? extends ZipEntry> en = inFile.entries();
		while (en.hasMoreElements()) {
			ZipEntry ze = en.nextElement();
			zfe.nextEntry(ze);
			add(ze, zfe, password);
		}
	} finally {
		zfe.close();
	}
}
 
Example 4
Source File: ScriptPackage.java    From L2jBrasil with GNU General Public License v3.0 5 votes vote down vote up
public ScriptPackage(ZipFile pack)
{
	_scriptFiles = new ArrayList<>();
	_otherFiles = new ArrayList<>();
	_name = pack.getName();
	addFiles(pack);
}
 
Example 5
Source File: AARLibrary.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the package name from the Android Archive without needing to unzip it to a location
 * in the file system
 *
 * @param zip the input stream reading from the Android Archive.
 * @return the package name declared in the archive's AndroidManifest.xml.
 * @throws IOException if reading the input stream fails.
 */
private String extractPackageName(ZipFile zip) throws IOException {
  ZipEntry entry = zip.getEntry("AndroidManifest.xml");
  if (entry == null) {
    throw new IllegalArgumentException(zip.getName() + " does not contain AndroidManifest.xml");
  }
  try {
    ZipEntryWrapper wrapper = new ZipEntryWrapper(zip.getInputStream(entry));
    // the following call will automatically close the input stream opened above
    return AndroidManifest.getPackage(wrapper);
  } catch(StreamException|XPathExpressionException e) {
    throw new IOException("Exception processing AndroidManifest.xml", e);
  }
}
 
Example 6
Source File: UnpackJarBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * {@inheritDoc}
 */

public void writeArchive(ZipFile jarFile, IProgressMonitor progressMonitor) {
	File jarPathFile= new File(jarFile.getName());
	String jarName= jarPathFile.getName();
	while (jarNames.contains(jarName)) {
		jarName= FatJarPackagerUtil.nextNumberedFileName(jarName);
	}
	jarNames.add(jarName);
	File destJarPathFile= new File(fSubfolderPath.toFile(), jarName);
	copyFile(jarPathFile, destJarPathFile);
}
 
Example 7
Source File: ArchiveClassPathRoot.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public URL getResource(final String name) throws MalformedURLException {
  final ZipFile zip = getRoot();
  try {
    final ZipEntry entry = zip.getEntry(name);
    if (entry != null) {
      return new URL("jar:file:" + zip.getName() + "!/" + entry.getName());
    } else {
      return null;
    }
  } finally {
    closeQuietly(zip);
  }

}
 
Example 8
Source File: ImageFileFactory.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the <code>ItemFile</code> for the given <code>ZipEntry</code> in
 * the <code>ZipFile</code>.
 * 
 * @param zipEntry - the <code>ZipEntry</code> that will be read to
 *            produce the item. This value must not be <code>null</code>.
 * @param zipFile - the <code>ZipFile</code> object that contains the
 *            <code>ZipEntry</code> that will produce the item. This value
 *            must not be <code>null</code>.
 * @return an <code>ItemFile</code> for the given zip file entry.
 * @throws <code>IllegalArgumentException</code> if either the
 *             <code>zipEntry</code> or the <code>zipFile</code> is
 *             <code>null</code>.
 */
public ItemFile getItemFile(final ZipEntry zipEntry, final ZipFile zipFile)
        throws IllegalArgumentException {

    // Validate the input.
    if (null == zipEntry) {
        throw new IllegalArgumentException("A null ZIP entry was passed."); //$NON-NLS-1$
    }
    if (null == zipFile) {
        throw new IllegalArgumentException("A null ZIP file was passed."); //$NON-NLS-1$
    }

    // Construct an anonymous class that gets an Image for the file.
    return new ItemFile() {

        private ZipEntry itemEntry = zipEntry; // copy the ZipEntry
        private Image image = null; // cache the Image

        public Object getItem() throws Exception {

            // Cache the image on first use.
            if (null == image) {

                // Get ready to read from the item.
                InputStream in = new BufferedInputStream(zipFile
                        .getInputStream(itemEntry), (int) itemEntry
                        .getSize());

                // Make a buffer big enough to hold the item,
                // read from the ZIP file, and write it to temp.
                byte[] buffer = new byte[(int) itemEntry.getSize()];
                in.read(buffer);

                // Check the last 10 bytes. I've been having
                // some problems with incomplete image files,
                // and I want to detect it early and give advice
                // to players for dealing with the problem.
                int index = (int) itemEntry.getSize() - 10;
                while (itemEntry.getSize() > index) {
                    if (0 != buffer[index]) {
                        break;
                    }
                    index++;
                }
                if (itemEntry.getSize() <= index) {
                    throw new IOException(
                            "Error reading " + itemEntry.getName() + //$NON-NLS-1$
                                    "\nYou may want to unzip " + //$NON-NLS-1$
                                    zipFile.getName());
                }

                // Create the image from the buffer.
                image = Toolkit.getDefaultToolkit().createImage(buffer);

            } // End get-image

            // Return a copy of the image.
            return ImageUtil.getScaledImage(image, 84, 72);

        } // End getItem()
    };

}