if (!header.isDirectory()) { try (InputStream subFile = rar.getInputStream(header)) { Metadata entrydata = PackageParser.handleEntryMetadata( "".equals(header.getFileNameW()) ? header.getFileNameString() : header.getFileNameW(), header.getCTime(), header.getMTime(), header.getFullUnpackSize(), xhtml );
FileHeader fh = archive.nextFileHeader(); while (fh != null) { String compressFileName = fh.getFileNameString().trim(); File destFile = new File(destDir.getAbsolutePath() + StrConst.FILE_SEP + compressFileName); if (fh.isDirectory()) { if (!destFile.exists()) { destFile.mkdirs();
+ fileHeader.getFileName(); File outFile = new File(outFilePath); if (fileHeader.isDirectory()) { + fileHeader.getFileName()); } else { System.err.println("fileheader is null. Shouldn't be here");
@Override public void print() { super.print(); StringBuilder str = new StringBuilder(); str.append("unpSize: " + getUnpSize()); str.append("\nHostOS: " + hostOS.name()); str.append("\nMDate: " + mTime); str.append("\nFileName: " + getFileNameString()); str.append("\nunpMethod: " + Integer.toHexString(getUnpMethod())); str.append("\nunpVersion: " + Integer.toHexString(getUnpVersion())); str.append("\nfullpackedsize: " + getFullPackSize()); str.append("\nfullunpackedsize: " + getFullUnpackSize()); str.append("\nisEncrypted: " + isEncrypted()); str.append("\nisfileHeader: " + isFileHeader()); str.append("\nisSolid: " + isSolid()); str.append("\nisSplitafter: " + isSplitAfter()); str.append("\nisSplitBefore:" + isSplitBefore()); str.append("\nunpSize: " + getUnpSize()); str.append("\ndataSize: " + getDataSize()); str.append("\nisUnicode: " + isUnicode()); str.append("\nhasVolumeNumber: " + hasVolumeNumber()); str.append("\nhasArchiveDataCRC: " + hasArchiveDataCRC()); str.append("\nhasSalt: " + hasSalt()); str.append("\nhasEncryptVersions: " + hasEncryptVersion()); str.append("\nisSubBlock: " + isSubBlock()); logger.info(str.toString()); }
/** * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given {@link com.github.junrar.rarfile.FileHeader} * * @param header the object that serves to initialize the attributes of the returned ArchiveEntry * @return an ArchiveEntry whose attributes are fetched from the given FileHeader */ private ArchiveEntry createArchiveEntry(FileHeader header) { return new ArchiveEntry( header.getFileNameString().replace('\\', '/'), header.isDirectory(), header.getMTime().getTime(), header.getFullUnpackSize(), true ); }
@Override protected void handleEntry(FileHeader entry) throws IOException { try { if (entry.isDirectory()) { String path = entry.getFileNameString(); if (!(path.endsWith(UNIX_PATH_SPLITTER) || path.endsWith(WINDOWS_PATH_SPLITTER))) { path += UNIX_PATH_SPLITTER; } submitDirectory(path, entry.getMTime()); } else if (entry.isEncrypted()) { throw new RuntimeException("Encrypted entry : " + entry.getFileNameString()); } else { submitFile(entry); } } catch (URISyntaxException ex) { throw new RuntimeException("Malformed uri for entry : " + entry.getFileNameString(), ex); } catch (RarException rarEx) { throw new RuntimeException("Probem with RAR extraction : " + entry.getFileNameString(), rarEx); } } }
@Override public File createDirectory(final FileHeader fh) { File f = null; if (fh.isDirectory() && fh.isUnicode()) { f = new File(folderDestination, fh.getFileNameW()); if (!f.exists()) { makeDirectory(folderDestination, fh.getFileNameW()); } } else if (fh.isDirectory() && !fh.isUnicode()) { f = new File(folderDestination, fh.getFileNameString()); if (!f.exists()) { makeDirectory(folderDestination, fh.getFileNameString()); } } return f; }
private void processEntry(FileHeader entry, Archive archive, URI uri, String newPath) throws CommandExecutionException, IOException, RarException { String name = entry.getFileNameString(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getUnpSize(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); RarIdentificationRequest req = new RarIdentificationRequest(metaData, identifier, getTmpDir()); expandContainer(req, archive.getInputStream(entry), newPath); } else { log.trace("processing directory : " + entry.getFileNameString()); } } }
private static File tryToExtract( final Log logger, final ExtractDestination destination, final Archive arch, final FileHeader fileHeader ) throws IOException, RarException { final String fileNameString = fileHeader.getFileNameString(); if (fileHeader.isEncrypted()) { logger.warn("file is encrypted cannot extract: "+ fileNameString); return null; } logger.info("extracting: " + fileNameString); if (fileHeader.isDirectory()) { return destination.createDirectory(fileHeader); } else { return destination.extract(arch, fileHeader); } }
private void submitFile(FileHeader entry) throws IOException, URISyntaxException, RarException { String fullpath = entry.getFileNameString(); String path = FilenameUtils.getPath(fullpath); String name = FilenameUtils.getName(fullpath); //CHECKSTYLE:OFF log.debug("submitFile, processing path: " + path + " name: " + name); //CHECKSTYLE:ON ResourceId correlationId = getFromDirCache(path); if (correlationId == null) { correlationId = submitDirectory(path, entry.getMTime()); } InputStream entryInputStream = archive.getInputStream(entry); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toRarUri(parentURI, path + name)); identifier.setAncestorId(originatorNodeId); identifier.setParentResourceId(correlationId); RequestMetaData metaData = new RequestMetaData(entry.getUnpSize(), entry.getMTime().getTime(), name); IdentificationRequest<InputStream> request = identificationRequestFactory.newRequest(metaData, identifier); request.open(entryInputStream); droid.submit(request); }
private File createFile(final FileHeader fh, final File destination) { File f = null; String name = null; if (fh.isFileHeader() && fh.isUnicode()) { name = fh.getFileNameW(); } else { name = fh.getFileNameString(); } f = new File(destination, name); if (!f.exists()) { try { f = makeFile(destination, name); } catch (final IOException e) { logger.error("error creating the new file: " + f.getName(), e); } } return f; }
this.unpack = new Unpack(this.dataIO); if (!hd.isSolid()) { this.unpack.init(null); this.unpack.setDestSize(hd.getFullUnpackSize()); try { this.unpack.doUnpack(hd.getUnpVersion(), hd.isSolid()); final long actualCRC = hd.isSplitAfter() ? ~this.dataIO.getPackedCRC() : ~this.dataIO.getUnpFileCRC(); final int expectedCRC = hd.getFileCRC(); if (actualCRC != expectedCRC) { throw new RarException(RarExceptionType.crcError);
@Override protected FileType doGetType() { if (header == null || header.isDirectory()) { return FileType.FOLDER; } else { return FileType.FILE; } }
public static List<ContentDescription> getContentsDescription(final File rar) throws RarException, IOException { validateRarPath(rar); final Archive arch = createArchiveOrThrowException(logger, rar); final List<ContentDescription> contents = new ArrayList<ContentDescription>(); try{ if (arch.isEncrypted()) { logger.warn("archive is encrypted cannot extract"); return new ArrayList<ContentDescription>(); } for(final FileHeader fileHeader : arch ) { contents.add(new ContentDescription(fileHeader.getFileNameString(), fileHeader.getUnpSize())); } }finally { arch.close(); } return contents; }
if (h.getFileNameString().equals(path)) { header1 = h; break; if (header.isSplitAfter()) throw new RarException(RarExceptionType.notImplementedYet);
while (fh != null) { try { File out = new File(UNRAR_LOCATION + fh.getFileNameString().trim()); String fileName = out.getPath(); fileName = fileName.substring(0, fileName.lastIndexOf("\\"));
throw new EOFException(); if (subHead.isSplitAfter()) { packedCRC = RarCRC.checkCrc((int) packedCRC, addr, offset, retCode); unpPackedSize -= retCode; archive.bytesReadRead(retCode); if (unpPackedSize == 0 && subHead.isSplitAfter()) { Volume nextVolume = archive.getVolumeManager().nextArchive( archive, archive.getVolume()); if (hd.getUnpVersion() >= 20 && hd.getFileCRC() != 0xffffffff && this.getPackedCRC() != ~hd.getFileCRC()) { throw new RarException(RarExceptionType.crcError);
@Override protected long doGetLastModifiedTime() throws Exception { return header.getMTime().getTime(); }
@Override protected long doGetContentSize() { return header.getFullUnpackSize(); }
@Override public void print() { super.print(); StringBuilder str = new StringBuilder(); str.append("unpSize: " + getUnpSize()); str.append("\nHostOS: " + hostOS.name()); str.append("\nMDate: " + mTime); str.append("\nFileName: " + getFileNameString()); str.append("\nunpMethod: " + Integer.toHexString(getUnpMethod())); str.append("\nunpVersion: " + Integer.toHexString(getUnpVersion())); str.append("\nfullpackedsize: " + getFullPackSize()); str.append("\nfullunpackedsize: " + getFullUnpackSize()); str.append("\nisEncrypted: " + isEncrypted()); str.append("\nisfileHeader: " + isFileHeader()); str.append("\nisSolid: " + isSolid()); str.append("\nisSplitafter: " + isSplitAfter()); str.append("\nisSplitBefore:" + isSplitBefore()); str.append("\nunpSize: " + getUnpSize()); str.append("\ndataSize: " + getDataSize()); str.append("\nisUnicode: " + isUnicode()); str.append("\nhasVolumeNumber: " + hasVolumeNumber()); str.append("\nhasArchiveDataCRC: " + hasArchiveDataCRC()); str.append("\nhasSalt: " + hasSalt()); str.append("\nhasEncryptVersions: " + hasEncryptVersion()); str.append("\nisSubBlock: " + isSubBlock()); logger.info(str.toString()); }