Code example for ZipFile

Methods: closegetEntrygetName

0
	private void validateJdrReportContents(File reportFile) {
	    String reportName = reportFile.getName().replace(".zip","");
 
		ZipFile reportZip = null;
		try { 
			reportZip = new ZipFile(reportFile);
			validateReportEntries(reportZip, reportName);
		} catch (Exception e) {
			throw new RuntimeException("Unable to validate JDR report: " + reportFile.getName(), e);
		} finally { 
			if (reportZip != null) {
				try { 
				    reportZip.close();
				} catch (IOException e) {
				    throw new RuntimeException("Unable to close JDR report: " + reportFile.getName(), e);
				} 
			} 
		} 
	} 
 
	private void validateReportEntries(ZipFile reportZip, String reportName) {
	    validateEntryNotEmpty("version.txt", reportZip, reportName);
	    // TODO: Add additional files for more complete test. 
	} 
 
	private void validateJdrTimeStamps(ModelNode result) {
		// TODO: Validate time structures beyond just not null. 
		Assert.assertNotNull("JDR start time was null.", result.get("start-time").asString());
		Assert.assertNotNull("JDR end time was null.", result.get("end-time").asString());
	} 
 
	private void validateEntryNotEmpty(String fileName, ZipFile reportZip, String reportName) {
	    String entryInZip = reportName + "/" + fileName;
	    ZipEntry entry = reportZip.getEntry(entryInZip);
	    Assert.assertNotNull("Report entry " + fileName + " missing from JDR report " + reportZip.getName(), entry);
	    Assert.assertTrue("Report entry " + fileName + " was empty or could not be determined", entry.getSize() > 0);
	} 
}