Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major bug, there is a dead cycle in parsing #149

Open
DearMrT opened this issue Nov 25, 2023 · 0 comments
Open

Major bug, there is a dead cycle in parsing #149

DearMrT opened this issue Nov 25, 2023 · 0 comments

Comments

@DearMrT
Copy link

DearMrT commented Nov 25, 2023

private static final ZipEntry ERROR_ZIP_ENTRY = new ZipEntry("<error>");


private static ZipEntry getNextZipEntry(ZipInputStream zipInputStream) throws IOException {
	ZipEntry result = ERROR_ZIP_ENTRY;
	try {
		result = zipInputStream.getNextEntry();
	} catch(ZipException e) {
		LOG.error(e.getMessage());
		zipInputStream.closeEntry();
	}
	return result;
}

public static Resources loadResources(ZipInputStream zipInputStream, String defaultHtmlEncoding) throws IOException {
	Resources result = new Resources();
	ZipEntry zipEntry;
	do {
		// get next valid zipEntry
		zipEntry = getNextZipEntry(zipInputStream);
		if((zipEntry == null) || (zipEntry == ERROR_ZIP_ENTRY) || zipEntry.isDirectory()) {
			continue;
		}
		
		// store resource
		Resource resource = ResourceUtil.createResource(zipEntry, zipInputStream);
		if(resource.getMediaType() == MediatypeService.XHTML) {
			resource.setInputEncoding(defaultHtmlEncoding);
		}
		result.add(resource);
	} while(zipEntry != null);

	return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant