List of usage examples for org.apache.commons.compress.archivers.cpio CpioArchiveInputStream close
public void close() throws IOException
From source file:com.pclinuxos.rpm.util.FileUtils.java
/** * The method extracts a srpm into the default directory used by the program (/home/<user>/RCEB/srpms/tmp) * /*from w w w . j ava 2 s. c o m*/ * @param srpm the srpm to extract * @return 0 if the extraction was successfully, -1 if a IOException occurred, -2 if a InterruptException * occurred. Values > 0 for return codes of the rpm2cpio command. */ public static int extractSrpm(String srpm) { int returnCode = 0; try { Process extractProcess = Runtime.getRuntime() .exec("rpm2cpio " + FileConstants.SRCSRPMS.getAbsolutePath() + "/" + srpm); // 64kb buffer byte[] buffer = new byte[0xFFFF]; InputStream inread = extractProcess.getInputStream(); FileOutputStream out = new FileOutputStream(new File(FileConstants.F4SRPMEX + "archive.cpio")); while (inread.read(buffer) != -1) { out.write(buffer); } returnCode = extractProcess.waitFor(); if (returnCode == 0) { CpioArchiveInputStream cpioIn = new CpioArchiveInputStream( new FileInputStream(FileConstants.F4SRPMEX + "archive.cpio")); CpioArchiveEntry cpEntry; while ((cpEntry = cpioIn.getNextCPIOEntry()) != null) { FileOutputStream fOut = new FileOutputStream(FileConstants.F4SRPMEX + cpEntry.getName()); // Do not make this buffer bigger it breaks the cpio decompression byte[] buffer2 = new byte[1]; ArrayList<Byte> buf = new ArrayList<Byte>(); while (cpioIn.read(buffer2) != -1) { buf.add(buffer2[0]); } byte[] file = new byte[buf.size()]; for (int i = 0; i < buf.size(); i++) { file[i] = buf.get(i); } fOut.write(file); fOut.flush(); fOut.close(); } cpioIn.close(); } } catch (IOException e) { returnCode = -1; } catch (InterruptedException e) { returnCode = -2; } new File(FileConstants.F4SRPMEX + "archive.cpio").delete(); return returnCode; }
From source file:com.espringtran.compressor4j.processor.CpioProcessor.java
/** * Read from compressed file/* w w w.j a va 2s . c o m*/ * * @param srcPath * path of compressed file * @param fileCompressor * FileCompressor object * @throws Exception */ @Override public void read(String srcPath, FileCompressor fileCompressor) throws Exception { long t1 = System.currentTimeMillis(); byte[] data = FileUtil.convertFileToByte(srcPath); ByteArrayInputStream bais = new ByteArrayInputStream(data); CpioArchiveInputStream ais = new CpioArchiveInputStream(bais); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int readByte; CpioArchiveEntry entry = ais.getNextCPIOEntry(); while (entry != null && entry.getSize() > 0) { long t2 = System.currentTimeMillis(); baos = new ByteArrayOutputStream(); readByte = ais.read(buffer); while (readByte != -1) { baos.write(buffer, 0, readByte); readByte = ais.read(buffer); } BinaryFile binaryFile = new BinaryFile(entry.getName(), baos.toByteArray()); fileCompressor.addBinaryFile(binaryFile); LogUtil.createAddFileLog(fileCompressor, binaryFile, t2, System.currentTimeMillis()); entry = ais.getNextCPIOEntry(); } } catch (Exception e) { FileCompressor.LOGGER.error("Error on get compressor file", e); } finally { baos.close(); ais.close(); bais.close(); } LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1, System.currentTimeMillis()); }
From source file:org.eclipse.packagedrone.repo.adapter.rpm.internal.RpmExtractor.java
private RpmInformation makeInformation(final RpmInputStream in) throws IOException { final RpmHeader<RpmTag> header = in.getPayloadHeader(); final RpmHeader<RpmSignatureTag> signature = in.getSignatureHeader(); try {/* www . j a v a2 s.c o m*/ final RpmInformation result = new RpmInformation(); result.setHeaderStart(header.getStart()); result.setHeaderEnd(header.getStart() + header.getLength()); result.setName(asString(header.getTag(RpmTag.NAME))); result.setArchitecture(asString(header.getTag(RpmTag.ARCH))); result.setSummary(asString(header.getTag(RpmTag.SUMMARY))); result.setDescription(asString(header.getTag(RpmTag.DESCRIPTION))); result.setPackager(asString(header.getTag(RpmTag.PACKAGER))); result.setUrl(asString(header.getTag(RpmTag.URL))); result.setLicense(asString(header.getTag(RpmTag.LICENSE))); result.setVendor(asString(header.getTag(RpmTag.VENDOR))); result.setGroup(asString(header.getTag(RpmTag.GROUP))); result.setBuildHost(asString(header.getTag(RpmTag.BUILDHOST))); result.setBuildTimestamp(asLong(header.getTag(RpmTag.BUILDTIME))); result.setSourcePackage(asString(header.getTag(RpmTag.SOURCE_PACKAGE))); result.setInstalledSize(asLong(header.getTag(RpmTag.INSTALLED_SIZE))); result.setArchiveSize(asLong(header.getTag(RpmTag.ARCHIVE_SIZE))); if (result.getArchiveSize() == null) { result.setArchiveSize(asLong(signature.getTag(RpmSignatureTag.PAYLOAD_SIZE))); } // version final RpmInformation.Version ver = new RpmInformation.Version(asString(header.getTag(RpmTag.VERSION)), asString(header.getTag(RpmTag.RELEASE)), asString(header.getTag(RpmTag.EPOCH))); result.setVersion(ver); // changelog final Object val = header.getTag(RpmTag.CHANGELOG_TIMESTAMP); if (val instanceof Long[]) { final Long[] ts = (Long[]) val; final String[] authors = (String[]) header.getTag(RpmTag.CHANGELOG_AUTHOR); final String[] texts = (String[]) header.getTag(RpmTag.CHANGELOG_TEXT); final List<RpmInformation.Changelog> changes = new ArrayList<>(ts.length); for (int i = 0; i < ts.length; i++) { changes.add(new RpmInformation.Changelog(ts[i], authors[i], texts[i])); } Collections.sort(changes, (o1, o2) -> Long.compare(o1.getTimestamp(), o2.getTimestamp())); result.setChangelog(changes); } // dependencies result.setProvides( makeDependencies(header, RpmTag.PROVIDE_NAME, RpmTag.PROVIDE_VERSION, RpmTag.PROVIDE_FLAGS)); result.setRequires( makeDependencies(header, RpmTag.REQUIRE_NAME, RpmTag.REQUIRE_VERSION, RpmTag.REQUIRE_FLAGS)); result.setConflicts( makeDependencies(header, RpmTag.CONFLICT_NAME, RpmTag.CONFLICT_VERSION, RpmTag.CONFLICT_FLAGS)); result.setObsoletes( makeDependencies(header, RpmTag.OBSOLETE_NAME, RpmTag.OBSOLETE_VERSION, RpmTag.OBSOLETE_FLAGS)); // files final CpioArchiveInputStream cpio = in.getCpioStream(); CpioArchiveEntry cpioEntry; while ((cpioEntry = cpio.getNextCPIOEntry()) != null) { final String name = normalize(cpioEntry.getName()); if (cpioEntry.isRegularFile()) { result.getFiles().add(name); } else if (cpioEntry.isDirectory()) { result.getDirectories().add(name); } } cpio.close(); return result; } catch (final Exception e) { logger.info("Failed to create RPM information", e); return null; } }
From source file:org.eclipse.packagedrone.utils.rpm.info.RpmInformations.java
public static RpmInformation makeInformation(final RpmInputStream in) throws IOException { final InputHeader<RpmTag> header = in.getPayloadHeader(); final InputHeader<RpmSignatureTag> signature = in.getSignatureHeader(); final RpmInformation result = new RpmInformation(); result.setHeaderStart(header.getStart()); result.setHeaderEnd(header.getStart() + header.getLength()); result.setName(asString(header.getTag(RpmTag.NAME))); result.setArchitecture(asString(header.getTag(RpmTag.ARCH))); result.setSummary(asString(header.getTag(RpmTag.SUMMARY))); result.setDescription(asString(header.getTag(RpmTag.DESCRIPTION))); result.setPackager(asString(header.getTag(RpmTag.PACKAGER))); result.setUrl(asString(header.getTag(RpmTag.URL))); result.setLicense(asString(header.getTag(RpmTag.LICENSE))); result.setVendor(asString(header.getTag(RpmTag.VENDOR))); result.setGroup(asString(header.getTag(RpmTag.GROUP))); result.setBuildHost(asString(header.getTag(RpmTag.BUILDHOST))); result.setBuildTimestamp(asLong(header.getTag(RpmTag.BUILDTIME))); result.setSourcePackage(asString(header.getTag(RpmTag.SOURCE_PACKAGE))); result.setInstalledSize(asLong(header.getTag(RpmTag.SIZE))); result.setArchiveSize(asLong(header.getTag(RpmTag.ARCHIVE_SIZE))); if (result.getArchiveSize() == null) { result.setArchiveSize(asLong(signature.getTag(RpmSignatureTag.PAYLOAD_SIZE))); }/*from ww w . j ava 2 s .co m*/ // version final RpmInformation.Version ver = new RpmInformation.Version(asString(header.getTag(RpmTag.VERSION)), asString(header.getTag(RpmTag.RELEASE)), asString(header.getTag(RpmTag.EPOCH))); result.setVersion(ver); // changelog final Object val = header.getTag(RpmTag.CHANGELOG_TIMESTAMP); if (val instanceof Long[]) { final Long[] ts = (Long[]) val; final String[] authors = (String[]) header.getTag(RpmTag.CHANGELOG_AUTHOR); final String[] texts = (String[]) header.getTag(RpmTag.CHANGELOG_TEXT); final List<RpmInformation.Changelog> changes = new ArrayList<>(ts.length); for (int i = 0; i < ts.length; i++) { changes.add(new RpmInformation.Changelog(ts[i], authors[i], texts[i])); } Collections.sort(changes, (o1, o2) -> Long.compare(o1.getTimestamp(), o2.getTimestamp())); result.setChangelog(changes); } // dependencies result.setProvides( makeDependencies(header, RpmTag.PROVIDE_NAME, RpmTag.PROVIDE_VERSION, RpmTag.PROVIDE_FLAGS)); result.setRequires( makeDependencies(header, RpmTag.REQUIRE_NAME, RpmTag.REQUIRE_VERSION, RpmTag.REQUIRE_FLAGS)); result.setConflicts( makeDependencies(header, RpmTag.CONFLICT_NAME, RpmTag.CONFLICT_VERSION, RpmTag.CONFLICT_FLAGS)); result.setObsoletes( makeDependencies(header, RpmTag.OBSOLETE_NAME, RpmTag.OBSOLETE_VERSION, RpmTag.OBSOLETE_FLAGS)); // files final CpioArchiveInputStream cpio = in.getCpioStream(); CpioArchiveEntry cpioEntry; while ((cpioEntry = cpio.getNextCPIOEntry()) != null) { final String name = normalize(cpioEntry.getName()); if (cpioEntry.isRegularFile()) { result.getFiles().add(name); } else if (cpioEntry.isDirectory()) { result.getDirectories().add(name); } } cpio.close(); return result; }