Java Code Examples for java.util.zip.ZipEntry#toString()

The following examples show how to use java.util.zip.ZipEntry#toString() . 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: GpxCacher.java    From GpsPrune with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get an inputstream of a GPX file inside a zip
 * @param inFile File object describing zip file
 * @return input stream for Xml parser
 */
private static InputStream getZipInputStream(File inFile)
{
	try
	{
		ZipInputStream zis = new ZipInputStream(new FileInputStream(inFile));
		while (zis.available() > 0)
		{
			ZipEntry entry = zis.getNextEntry();
			String entryName = entry.toString();
			if (entryName != null && entryName.length() > 4)
			{
				String suffix = entryName.substring(entryName.length()-4).toLowerCase();
				if (suffix.equals(".gpx") || suffix.equals(".xml")) {
					// First matching file so must be gpx
					return zis;
				}
			}
		}
	}
	catch (Exception e) {} // ignore errors
	// not found - error!
	return null;
}
 
Example 2
Source File: LocalResourcesTools.java    From webery with MIT License 6 votes vote down vote up
protected void getClasses(File archive, List<Class> l) {
    try {
        ZipInputStream zip = new ZipInputStream(new FileInputStream(archive));
        ZipEntry entry;
        while ((entry = zip.getNextEntry()) != null) {
            String name = entry.toString();
            if (name.startsWith("WEB-INF/classes/"))
                name = name.substring("WEB-INF/classes/".length());
            Class c = getClass(name);
            if (c != null)
                l.add(c);
        }
        zip.close();
    } catch (IOException ignored) {
    }
}
 
Example 3
Source File: TestValidatorTest2.java    From openxds with Apache License 2.0 5 votes vote down vote up
public void testTopElement() throws XdsInternalException, FactoryConfigurationError, IOException {
	List<ZipEntry> content = getContentEntries(zip);
	for (int i=0; i<content.size(); i++) {
		ZipEntry entry = content.get(i);
		String entryName = entry.toString();
		InputStream is = zip.getInputStream(entry);
		String entryString = Io.getStringFromInputStream(is);
		System.out.println("entryString = " + entryString.substring(0, min(entryString.length(), 25)));
		OMElement entryElement = Util.parse_xml(entryString);
		assertTrue("name is " + entryElement.getLocalName(),
				entryElement.getLocalName().equals("TestResults"));
	}
}
 
Example 4
Source File: ProjectExporter.java    From webanno with Apache License 2.0 5 votes vote down vote up
static String normalizeEntryName(ZipEntry aEntry)
{
    // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
    String entryName = aEntry.toString();
    if (entryName.startsWith("/")) {
        entryName = entryName.substring(1);
    }
   
    return entryName;
}
 
Example 5
Source File: ZipUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static String normalizeEntryName(ZipEntry aEntry)
{
    // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
    String entryName = aEntry.toString();
    if (entryName.startsWith("/")) {
        entryName = entryName.substring(1);
    }
   
    return entryName;
}
 
Example 6
Source File: ClassPath.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Override
ClassFile getClassFile(final String name, final String suffix) throws IOException {
    final ZipEntry entry = zipFile.getEntry(toEntryName(name, suffix));

    if (entry == null) {
        return null;
    }

    return new ClassFile() {

        @Override
        public String getBase() {
            return zipFile.getName();
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return zipFile.getInputStream(entry);
        }

        @Override
        public String getPath() {
            return entry.toString();
        }

        @Override
        public long getSize() {
            return entry.getSize();
        }

        @Override
        public long getTime() {
            return entry.getTime();
        }
    };
}
 
Example 7
Source File: ZipFileLoader.java    From GpsPrune with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Open the selected file and select appropriate xml loader
 * @param inFile File to open
 */
public void openFile(File inFile)
{
	try
	{
		ZipFile file = new ZipFile(inFile);
		Enumeration<?> entries = file.entries();
		boolean xmlFound = false;
		while (entries.hasMoreElements() && !xmlFound)
		{
			ZipEntry entry = (ZipEntry) entries.nextElement();
			String entryName = entry.toString();
			if (entryName != null && entryName.length() > 4)
			{
				String suffix = entryName.substring(entryName.length()-4).toLowerCase();
				if (suffix.equals(".kml") || suffix.equals(".gpx") || suffix.equals(".xml"))
				{
					_xmlLoader.reset();
					// Parse the stream using either Xerces or java classes
					_xmlLoader.parseXmlStream(file.getInputStream(entry));
					XmlHandler handler = _xmlLoader.getHandler();
					if (handler == null) {
						_app.showErrorMessage("error.load.dialogtitle", "error.load.othererror");
					}
					else
					{
						// Send back to app
						SourceInfo sourceInfo = new SourceInfo(inFile,
							(handler instanceof GpxHandler?SourceInfo.FILE_TYPE.GPX:SourceInfo.FILE_TYPE.KML));
						_app.informDataLoaded(handler.getFieldArray(), handler.getDataArray(),
							null, sourceInfo, handler.getTrackNameList(),
							new MediaLinkInfo(inFile, handler.getLinkArray()));
						xmlFound = true;
					}
				}
			}
		}
		file.close();
		// Check whether there was an xml file inside
		if (!xmlFound) {
			_app.showErrorMessage("error.load.dialogtitle", "error.load.noxmlinzip");
		}
	}
	catch (Exception e) {
		_app.showErrorMessageNoLookup("error.load.dialogtitle", e.getClass().getName() + "\n - " + e.getMessage());
	}
}
 
Example 8
Source File: ZipFileLoader.java    From GpsPrune with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Use the given stream to access a remote zip file
 * @param inStream stream to use to access file
 */
public void openStream(InputStream inStream)
{
	try
	{
		ZipInputStream zis = new ZipInputStream(inStream);
		boolean xmlFound = false;
		while (!xmlFound && zis.available() > 0)
		{
			ZipEntry entry = zis.getNextEntry();
			String entryName = entry.toString();
			if (entryName != null && entryName.length() > 4)
			{
				String suffix = entryName.substring(entryName.length()-4).toLowerCase();
				if (suffix.equals(".kml") || suffix.equals(".gpx") || suffix.equals(".xml"))
				{
					_xmlLoader.reset();
					SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
					saxParser.parse(zis, _xmlLoader);
					XmlHandler handler = _xmlLoader.getHandler();
					if (handler == null) {
						_app.showErrorMessage("error.load.dialogtitle", "error.load.othererror");
					}
					else
					{
						// Send back to app
						_app.informDataLoaded(handler.getFieldArray(), handler.getDataArray(),
							new SourceInfo("gpsies", SourceInfo.FILE_TYPE.GPSIES),
							handler.getTrackNameList());
						xmlFound = true;
					}
				}
			}
		}
		// Check whether there was an xml file inside
		if (!xmlFound) {
			_app.showErrorMessage("error.load.dialogtitle", "error.load.noxmlinzip");
		}
	}
	catch (Exception e) {
		System.err.println("ZipStream Error: " + e.getClass().getName() + " -message= " + e.getMessage());
	}
}