org.apache.commons.compress.archivers.cpio.CpioArchiveEntry Java Examples
The following examples show how to use
org.apache.commons.compress.archivers.cpio.CpioArchiveEntry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CpioFileSystem.java From ghidra with Apache License 2.0 | 6 votes |
private void storeFile(GFile file, CpioArchiveEntry entry, TaskMonitor monitor) { if (monitor.isCancelled()) { return; } if (file == null) { return; } if (file.equals(root)) { return; } if (!map.containsKey(file) || map.get(file) == null) { map.put(file, entry); } GFile parentFile = file.getParentFile(); storeFile(parentFile, null, monitor); }
Example #2
Source File: AttributeAccessor.java From jarchivelib with Apache License 2.0 | 6 votes |
/** * Detects the type of the given ArchiveEntry and returns an appropriate AttributeAccessor for it. * * @param entry the adaptee * @return a new attribute accessor instance */ public static AttributeAccessor<?> create(ArchiveEntry entry) { if (entry instanceof TarArchiveEntry) { return new TarAttributeAccessor((TarArchiveEntry) entry); } else if (entry instanceof ZipArchiveEntry) { return new ZipAttributeAccessor((ZipArchiveEntry) entry); } else if (entry instanceof CpioArchiveEntry) { return new CpioAttributeAccessor((CpioArchiveEntry) entry); } else if (entry instanceof ArjArchiveEntry) { return new ArjAttributeAccessor((ArjArchiveEntry) entry); } else if (entry instanceof ArArchiveEntry) { return new ArAttributeAccessor((ArArchiveEntry) entry); } return new FallbackAttributeAccessor(entry); }
Example #3
Source File: PayloadRecorder.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
public Result addSymbolicLink ( final String targetPath, final String linkTo, final Consumer<CpioArchiveEntry> customizer ) throws IOException { final byte[] bytes = linkTo.getBytes ( StandardCharsets.UTF_8 ); final CpioArchiveEntry entry = new CpioArchiveEntry ( CpioConstants.FORMAT_NEW, targetPath ); entry.setSize ( bytes.length ); if ( customizer != null ) { customizer.accept ( entry ); } this.archiveStream.putArchiveEntry ( entry ); this.archiveStream.write ( bytes ); this.archiveStream.closeArchiveEntry (); return new Result ( bytes.length, null ); }
Example #4
Source File: CpioFileSystem.java From ghidra with Apache License 2.0 | 6 votes |
@Override protected InputStream getData(GFile file, TaskMonitor monitor) throws IOException, CancelledException, CryptoException { CpioArchiveEntry fileEntry = map.get(file); if (!fileEntry.isRegularFile()) { throw new IOException("CPIO entry " + file.getName() + " is not a regular file."); } try (CpioArchiveInputStream cpioInputStream = new CpioArchiveInputStream(provider.getInputStream(0));) { CpioArchiveEntry entry; while ((entry = cpioInputStream.getNextCPIOEntry()) != null) { if (!entry.equals(fileEntry)) { skipEntryContents(cpioInputStream, monitor); } else { byte[] entryBytes = readEntryContents(cpioInputStream, monitor); return new ByteArrayInputStream(entryBytes); } } } catch (IllegalArgumentException e) { //unknown MODES.. } return null; }
Example #5
Source File: PayloadRecorder.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
public Result addFile ( final String targetPath, final InputStream stream, final Consumer<CpioArchiveEntry> customizer ) throws IOException { final Path tmpFile = Files.createTempFile ( "rpm-payload-", null ); try { try ( OutputStream os = Files.newOutputStream ( tmpFile ) ) { ByteStreams.copy ( stream, os ); } return addFile ( targetPath, tmpFile, customizer ); } finally { Files.deleteIfExists ( tmpFile ); } }
Example #6
Source File: Cpio.java From gradle-plugins with MIT License | 5 votes |
@Override @SneakyThrows public void processFile(FileCopyDetailsInternal details) { CpioArchiveEntry archiveEntry = new CpioArchiveEntry(format, details.getPath()); archiveEntry.setTime(details.getLastModified()); if (details.isDirectory()) { archiveEntry.setMode(CpioConstants.C_ISDIR); } else { archiveEntry.setMode(CpioConstants.C_ISREG); archiveEntry.setSize(details.getSize()); } try { outputFile.putArchiveEntry(archiveEntry); } catch (IOException e) { log.error(e.getMessage()); throw e; } if (!details.isDirectory()) { details.copyTo(outputFile); } outputFile.closeArchiveEntry(); }
Example #7
Source File: Cpio.java From gradle-plugins with MIT License | 5 votes |
@Override @SneakyThrows public void processFile(FileCopyDetailsInternal details) { CpioArchiveEntry archiveEntry = new CpioArchiveEntry(format, details.getPath()); archiveEntry.setTime(details.getLastModified()); if (details.isDirectory()) { archiveEntry.setMode(CpioConstants.C_ISDIR); } else { archiveEntry.setMode(CpioConstants.C_ISREG); archiveEntry.setSize(details.getSize()); } try { outputFile.putArchiveEntry(archiveEntry); } catch (IOException e) { log.error(e.getMessage()); throw e; } if (!details.isDirectory()) { details.copyTo(outputFile); } outputFile.closeArchiveEntry(); }
Example #8
Source File: PayloadRecorder.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public Result addDirectory ( final String targetPath, final Consumer<CpioArchiveEntry> customizer ) throws IOException { final CpioArchiveEntry entry = new CpioArchiveEntry ( CpioConstants.FORMAT_NEW, targetPath ); if ( customizer != null ) { customizer.accept ( entry ); } this.archiveStream.putArchiveEntry ( entry ); this.archiveStream.closeArchiveEntry (); return new Result ( 4096, null ); }
Example #9
Source File: Dumper.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public static void dumpAll ( final RpmInputStream in ) throws IOException { final RpmLead lead = in.getLead (); System.out.format ( "Version: %s.%s%n", lead.getMajor (), lead.getMinor () ); System.out.format ( "Name: %s%n", lead.getName () ); System.out.format ( "Signature Version: %s%n", lead.getSignatureVersion () ); System.out.format ( "Type: %s, Arch: %s, OS: %s%n", dumpFlag ( lead.getType (), Type::fromValue ), dumpFlag ( lead.getArchitecture (), Architecture::fromValue ), dumpFlag ( lead.getOperatingSystem (), OperatingSystem::fromValue ) ); dumpHeader ( "Signature", in.getSignatureHeader (), tag -> RpmSignatureTag.find ( tag ), false ); dumpHeader ( "Payload", in.getPayloadHeader (), tag -> RpmTag.find ( tag ), false ); final CpioArchiveInputStream cpio = in.getCpioStream (); CpioArchiveEntry entry; while ( ( entry = cpio.getNextCPIOEntry () ) != null ) { dumpEntry ( entry ); } dumpGroup ( in, "Require", RpmTag.REQUIRE_NAME, RpmTag.REQUIRE_VERSION, RpmTag.REQUIRE_FLAGS ); dumpGroup ( in, "Provide", RpmTag.PROVIDE_NAME, RpmTag.PROVIDE_VERSION, RpmTag.PROVIDE_FLAGS ); dumpGroup ( in, "Conflict", RpmTag.CONFLICT_NAME, RpmTag.CONFLICT_VERSION, RpmTag.CONFLICT_FLAGS ); dumpGroup ( in, "Obsolete", RpmTag.OBSOLETE_NAME, RpmTag.OBSOLETE_VERSION, RpmTag.OBSOLETE_FLAGS ); dumpGroup ( in, "Suggest", RpmTag.SUGGEST_NAME, RpmTag.SUGGEST_VERSION, RpmTag.SUGGEST_FLAGS ); dumpGroup ( in, "Recommend", RpmTag.RECOMMEND_NAME, RpmTag.RECOMMEND_VERSION, RpmTag.RECOMMEND_FLAGS ); dumpGroup ( in, "Supplement", RpmTag.SUPPLEMENT_NAME, RpmTag.SUPPLEMENT_VERSION, RpmTag.SUPPLEMENT_FLAGS ); dumpGroup ( in, "Enhance", RpmTag.ENHANCE_NAME, RpmTag.ENHANCE_VERSION, RpmTag.ENHANCE_FLAGS ); }
Example #10
Source File: RpmBuilder.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
private Consumer<CpioArchiveEntry> cpioCustomizer ( final long mtime, final int inode, final short mode ) { return entry -> { entry.setTime ( mtime ); entry.setInode ( inode ); entry.setMode ( mode & 0xFFFF ); entry.setDeviceMaj ( 8 ); entry.setDeviceMin ( 17 ); }; }
Example #11
Source File: PayloadRecorder.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public Result addFile ( final String targetPath, final Path path, final Consumer<CpioArchiveEntry> customizer ) throws IOException { final long size = Files.size ( path ); final CpioArchiveEntry entry = new CpioArchiveEntry ( CpioConstants.FORMAT_NEW, targetPath ); entry.setSize ( size ); if ( customizer != null ) { customizer.accept ( entry ); } this.archiveStream.putArchiveEntry ( entry ); MessageDigest digest; try { digest = createDigest (); } catch ( final NoSuchAlgorithmException e ) { throw new IOException ( e ); } try ( InputStream in = new BufferedInputStream ( Files.newInputStream ( path ) ) ) { ByteStreams.copy ( new DigestInputStream ( in, digest ), this.archiveStream ); } this.archiveStream.closeArchiveEntry (); return new Result ( size, digest.digest () ); }
Example #12
Source File: Dumper.java From packagedrone with Eclipse Public License 1.0 | 4 votes |
private static void dumpEntry ( final CpioArchiveEntry entry ) { System.out.format ( "-----------------------------------%n" ); System.out.format ( " %s%n", entry.getName () ); System.out.format ( " Size: %s, Chksum: %016x, Align: %s, Inode: %016x, Mode: %08o, NoL: %s, Device: %s.%s%n", entry.getSize (), entry.getChksum (), entry.getAlignmentBoundary (), entry.getInode (), entry.getMode (), entry.getNumberOfLinks (), entry.getDeviceMaj (), entry.getDeviceMin () ); }
Example #13
Source File: AttributeAccessor.java From jarchivelib with Apache License 2.0 | 4 votes |
public CpioAttributeAccessor(CpioArchiveEntry entry) { super(entry); }
Example #14
Source File: PayloadRecorder.java From packagedrone with Eclipse Public License 1.0 | 4 votes |
public Result addFile ( final String targetPath, final ByteBuffer data, final Consumer<CpioArchiveEntry> customizer ) throws IOException { final long size = data.remaining (); final CpioArchiveEntry entry = new CpioArchiveEntry ( CpioConstants.FORMAT_NEW, targetPath ); entry.setSize ( size ); if ( customizer != null ) { customizer.accept ( entry ); } this.archiveStream.putArchiveEntry ( entry ); // record digest MessageDigest digest; try { digest = createDigest (); digest.update ( data.slice () ); } catch ( final NoSuchAlgorithmException e ) { throw new IOException ( e ); } // write data final WritableByteChannel channel = Channels.newChannel ( this.archiveStream ); while ( data.hasRemaining () ) { channel.write ( data ); } // close archive entry this.archiveStream.closeArchiveEntry (); return new Result ( size, digest.digest () ); }
Example #15
Source File: RpmInformations.java From packagedrone with Eclipse Public License 1.0 | 4 votes |
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 ) ) ); } // 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; }
Example #16
Source File: CompressFileOperationsImpl.java From gradle-plugins with MIT License | 4 votes |
private FileTree cpioTree(Object arPath, ArchiveInputStreamProvider<CpioArchiveInputStream> inputStreamProvider) { File file = fileOperations.file(arPath); ArchiveFileTree<CpioArchiveInputStream, CpioArchiveEntry> cpioFileTree = new ArchiveFileTree<>(file, inputStreamProvider, getExpandDir(), fileSystem, directoryFileTreeFactory, fileHasher); return new FileTreeAdapter(cpioFileTree, patternSetFactory); }
Example #17
Source File: CompressFileOperationsImpl.java From gradle-plugins with MIT License | 4 votes |
private FileTree cpioTree(Object arPath, ArchiveInputStreamProvider<CpioArchiveInputStream> inputStreamProvider) { File file = fileOperations.file(arPath); ArchiveFileTree<CpioArchiveInputStream, CpioArchiveEntry> cpioFileTree = new ArchiveFileTree<>(file, inputStreamProvider, getExpandDir(), fileSystem, directoryFileTreeFactory, fileHasher); return new FileTreeAdapter(cpioFileTree, patternSetFactory); }
Example #18
Source File: CpioFileSystem.java From ghidra with Apache License 2.0 | 4 votes |
private void storeEntry(CpioArchiveEntry entry, TaskMonitor monitor) { monitor.setMessage(entry.getName()); GFileImpl file = GFileImpl.fromPathString(this, root, entry.getName(), null, entry.isDirectory(), entry.getSize()); storeFile(file, entry, monitor); }
Example #19
Source File: RpmBuilder.java From packagedrone with Eclipse Public License 1.0 | votes |
public Result record ( PayloadRecorder recorder, String targetName, T data, Consumer<CpioArchiveEntry> customizer ) throws IOException;