/** Gets the basenames header values. */ public String[] getBaseNames() { String[] array = new String[headers.size()]; int x = 0; for (CpioHeader header : headers) array[x++] = normalizePath(new File(header.getName()).getName()); return array; }
/** Gets the dirnames headers values. */ public String[] getDirNames() { final Set<String> set = new LinkedHashSet<String>(); for (CpioHeader header : headers) { String path = new File(header.getName()).getParent(); if (path == null) continue; String parent = normalizePath(path); if (!parent.endsWith("/")) parent += "/"; set.add(parent); } return set.toArray(new String[set.size()]); }
public static File convertRpmToZip(File file) throws Exception { LOG.info("File: " + file.getAbsolutePath()); FileInputStream fis = new FileInputStream(file); ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fis)); InputStream uncompressed = new GZIPInputStream(fis); in = new ReadableChannelWrapper(Channels.newChannel(uncompressed)); String rpmZipName = file.getName(); rpmZipName = StringUtils.replace(rpmZipName, ".", "-"); rpmZipName = rpmZipName + ".zip"; String rpmZipPath = FilenameUtils.getFullPath(file.getAbsolutePath()); File rpmZipOutput = new File(rpmZipPath + File.separator + rpmZipName); LOG.info("Converting RPM: " + file.getName() + " to ZIP: " + rpmZipOutput.getName()); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(rpmZipOutput)); String rpmName = file.getName(); rpmName = StringUtils.replace(rpmName, ".", "-"); CpioHeader header; int total = 0; do { header = new CpioHeader(); total = header.read(in, total); if (header.getFileSize() > 0) { BoundedInputStream bis = new BoundedInputStream(uncompressed, header.getFileSize()); String relPath = FilenameUtils.separatorsToSystem(header.getName()); relPath = StringUtils.removeStart(relPath, "."); relPath = StringUtils.removeStart(relPath, "/"); relPath = rpmName + File.separator + relPath; relPath = StringUtils.replace(relPath, "\\", "/"); ZipEntry zipEntry = new ZipEntry(relPath); zos.putNextEntry(zipEntry); IOUtils.copy(bis, zos); } else { final int skip = header.getFileSize(); if (uncompressed.skip(skip) != skip) throw new RuntimeException("Skip failed."); } total += header.getFileSize(); } while (!header.isLast()); zos.flush(); zos.close(); return rpmZipOutput; }
// TODO: Fix this (as part of general refactoring) to be much better. public int[] getDirIndexes() { final List<String> dirs = asList(getDirNames()); int[] array = new int[headers.size()]; int x = 0; for (CpioHeader header : headers) { String path = new File(header.getName()).getParent(); if (path == null) continue; String parent = normalizePath(path); if (!parent.endsWith("/")) parent += "/"; array[x++] = dirs.indexOf(parent); } return array; }
public boolean equals(final CpioHeader one, final CpioHeader two) { return one.getName().equals(two.getName()); }
public int compare(final CpioHeader one, final CpioHeader two) { return one.getName().compareTo(two.getName()); }