/** * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object other) { if (other == null) { return false; } try { return equals((ArchivEntry) other); } catch (ClassCastException e) { return false; } }
private boolean isEqualsWith(final ArchivEntry other) { if (!StringUtils.equals(this.getEntry(), other.getEntry())) { return false; } try { if (this.getSize() != other.getSize()) { return false; } return Arrays.equals(this.getBytes(), other.getBytes()); } catch (IOException ioe) { LOG.info("Will use URI for comparison because cannot compare content of {} with {}.", this, other); LOG.debug("Details:", ioe); return this.uri.equals(other.uri); } }
/** * Instantiates a new archiv entry. * * @param scheme the scheme * @param archive the archive * @param entry the entry * * @throws URISyntaxException the URI syntax exception */ public ArchivEntry(String scheme, File archive, String entry) throws URISyntaxException { this(archive); uri = toURI(scheme, entry); }
/** * If two entries have a different size or not the same byte code they are * considered as not equal. * * @param other the other * * @return true if they have the same size and the same byte code. */ public boolean equals(ArchivEntry other) { try { if (this.getSize() != other.getSize()) { return false; } return Arrays.equals(this.getBytes(), other.getBytes()); } catch (IOException ioe) { log.debug("can't compare " + this + " with " + other, ioe); return false; } }
/** * Gets the size. * * @return the size * * @throws IOException * Signals that an I/O exception has occurred. */ public long getSize() throws IOException { if (size == null) { if (isFile()) { size = this.getFileArchiv().length(); } else { ZipFile zipFile = getZipFile(); String entry = this.getEntry(); ZipEntry zipEntry = zipFile.getEntry(entry); if (zipEntry == null) { throw new ZipException("entry '" + entry + "' not found in " + zipFile); } size = zipEntry.getSize(); } } return size; }
/** * Incompatible resources are doublets with different content. * * @return doublet resources with different content */ @Override public String[] getIncompatibleResources() { List<String> incompatibleResources = new ArrayList<>(); for (String rsc : this.getDoublets()) { Enumeration<URL> doubletURLs = this.getResourcesFor(rsc); try { URL url = doubletURLs.nextElement(); ArchivEntry archivEntry = new ArchivEntry(url); while (doubletURLs.hasMoreElements()) { url = doubletURLs.nextElement(); ArchivEntry doubletEntry = new ArchivEntry(url); if (archivEntry.equals(doubletEntry)) { incompatibleResources.add(rsc); break; } } } catch (NoSuchElementException nse) { LOG.warn("{} is not added to incompatible resource list:", rsc, nse); } } return incompatibleResources.toArray(new String[incompatibleResources.size()]); }
/** * Gets the size. * * @return the size * * @throws IOException Signals that an I/O exception has occurred. */ public long getSize() throws IOException { if (size == null) { if (isFile()) { size = this.archiv.length(); } else { ZipFile zipFile = getZipFile(); ZipEntry zipEntry = zipFile.getEntry(this.entry); size = zipEntry.getSize(); } } return size; }
/** * Gets the entry. If no entry can be found an empty string is returned now. * This behaviour has changed with 1.5. * * @return the entry */ public String getEntry() { if (this.hasEntry()) { String path = this.uri.getRawSchemeSpecificPart(); if (this.isBundleresource()) { return StringUtils.substringAfter(path.substring(2), "/"); } else { String entry = StringUtils.substringAfterLast(path, "!"); return (entry.charAt(0) == '/') ? entry.substring(1) : entry; } } else { return ""; } }
/** * Gets the zip entry. * * @return the zip entry */ public ZipEntry getZipEntry() { return new ZipEntry(this.getEntry()); }
/** * Gets the zip file. * * @return the zip file * * @throws IOException * Signals that an I/O exception has occurred. */ public ZipFile getZipFile() throws IOException { try { return new NestedZipFile(this.getFileArchiv()); } catch (IOException ioe) { throw new IOException("can't get zip file \"" + this.getFileArchiv() + '"', ioe); } }
/** * Gets the file archiv. The works of course only for JAR and ZIP files. * * @return the file */ public File getFileArchiv() { if (this.hasEntry()) { String prefix = StringUtils.substringBeforeLast(this.uri.toString(), "!"); return Converter.toFile(prefix); } return Converter.toFile(this.uri); }
/** * Looks for each doublet if it has a different doublets. For the * performance reason it looks in the incompatibleClassList from the last * time if it is already found. This is done because normally the number of * incompatible classed does not decrease. * * @return a sorted list of incompatible classes */ @ProfileMe public synchronized List<Class<?>> getIncompatibleClassList() { List<Class<?>> doublets = this.getDoubletList(); for (Class<?> clazz : doublets) { if (incompatibleClassList.contains(clazz)) { continue; } String resource = Converter.classToResource(clazz.getName()); Enumeration<URL> resources = getResources(resource); URL url = (URL) resources.nextElement(); ArchivEntry archivEntry = new ArchivEntry(url); while (resources.hasMoreElements()) { url = (URL) resources.nextElement(); ArchivEntry doubletEntry = new ArchivEntry(url); if (archivEntry.equals(doubletEntry)) { incompatibleClassList.add(clazz); break; } } } return incompatibleClassList; }
/** * Gets the bytes. * * @return the bytes * * @throws IOException Signals that an I/O exception has occurred. */ public byte[] getBytes() throws IOException { if (isFile()) { return FileUtils.readFileToByteArray(this.archiv); } else { ZipFile zipFile = getZipFile(); ZipEntry zipEntry = zipFile.getEntry(this.entry); InputStream istream = zipFile.getInputStream(zipEntry); byte[] bytes = IOUtils.toByteArray(istream); istream.close(); return bytes; } }
/** * Checks if is file. * * @return true, if is file */ public boolean isFile() { return StringUtils.isEmpty(this.getEntry()); }
try { URL url = resources.nextElement(); ArchivEntry archivEntry = new ArchivEntry(url); while (resources.hasMoreElements()) { url = resources.nextElement(); ArchivEntry doubletEntry = new ArchivEntry(url); if (!archivEntry.equals(doubletEntry)) { incompatibleClassList.add(clazz); break;
/** * Instantiates a new archiv entry. * * @param scheme * the scheme * @param archive * the archive * @param entry * the entry * * @throws URISyntaxException * the URI syntax exception */ public ArchivEntry(final String scheme, final File archive, final String entry) throws URISyntaxException { this(toURI(scheme, archive, entry)); }