public RarStream(final File file, final Executor executor) throws Exception { rarArchive = new Archive(file); this.executor = executor; }
@Override public void close() throws IOException { rarArchive.close(); }
Archive a=null; try { a = new Archive(new NativeStorage(f)); } catch (RarException e) { a.getMainHeader().print(); FileHeader fh = a.nextFileHeader(); while(fh!=null){ try { System.out.println(out.getAbsolutePath()); FileOutputStream os = new FileOutputStream(out); a.extractFile(fh, os); os.close(); } catch (FileNotFoundException e) { fh=a.nextFileHeader();
return; Archive rarFile = new Archive(new NativeStorage(new File(rarFilePath))); de.innosystec.unrar.rarfile.FileHeader fileHeader = null; final int total = rarFile.getFileHeaders().size(); int progressNow = -1; for (int i = 0; i < rarFile.getFileHeaders().size(); i++) { fileHeader = rarFile.getFileHeaders().get(i); String entrypath = ""; if (fileHeader.isUnicode()) {//解决中文乱码 rarFile.extractFile(fileHeader, fileOut); fileOut.close();
public static boolean mergeArchive(Archive archive, ComprDataIO dataIO) throws IOException { FileHeader hd = dataIO.getSubHeader(); if (hd.getUnpVersion()>=20 && hd.getFileCRC()!=0xffffffff && dataIO.getPackedCRC()!=~hd.getFileCRC()) { System.err.println("Data Bad CRC"); } boolean oldNumbering = !archive.getMainHeader().isNewNumbering() || archive.isOldFormat(); String nextName = nextVolumeName(archive.getFile().getPath(), oldNumbering); NativeStorage nextVolume = archive.getFile().getParent().open(nextName); UnrarCallback callback = archive.getUnrarCallback(); if ((callback != null) && !callback.isNextVolumeReady(nextVolume)) { return false; } if (!nextVolume.exists()) { return false; } archive.setFile(nextVolume); hd = archive.nextFileHeader(); if (hd == null) { return false; } dataIO.init(hd); return true; }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws SAXException, IOException, TikaException { EmbeddedDocumentExtractor extractor = new EmbeddedDocumentExtractor(context); try { File file = TikaInputStream.get(stream).getFile(); Archive archive = new Archive(new NativeStorage(file)); metadata.set(Metadata.CONTENT_TYPE, TYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); for (FileHeader header : archive.getFileHeaders()) { Metadata entrydata = new Metadata(); entrydata.set( Metadata.RESOURCE_NAME_KEY, header.getFileNameString()); if (extractor.shouldParseEmbedded(entrydata)) { extractor.parseEmbedded(stream, xhtml, entrydata, true); } } xhtml.endDocument(); } catch (RarException e) { throw new TikaException("Unable to parse a RAR archive", e); } }
@Override public void run() { try { latch.countDown(); rarArchive.extractFile(header, pOut); } catch (final RarException e) { LOGGER.error("Unknown exception:", e); } finally { try { pOut.close(); } catch (final IOException e) { LOGGER.warn("Unknown exception closing reader.", e); } } } }
void setFile(NativeStorage file) throws IOException { this.file = file; totalPackedSize = 0L; totalPackedRead = 0L; close(); rof =file.read(); try { readHeaders(); } catch (Exception e) { logger.log(Level.WARNING, "exception in archive constructor maybe file is encrypted " + "or currupt", e); // ignore exceptions to allow exraction of working files in // corrupt archive } // Calculate size of packed data for (BaseBlock block : headers) { if (block.getHeaderType() == UnrarHeadertype.FileHeader) { totalPackedSize += ((FileHeader) block).getFullPackSize(); } } if (unrarCallback != null) { unrarCallback.volumeProgressChanged(totalPackedRead, totalPackedSize); } }
@Override public ArchiveEntry getNextEntry(boolean calculateSize) { header = rarArchive.nextFileHeader(); if (header == null) { return null; } return new DefaultArchiveEntry(header.getFileNameString(), header.getFullUnpackSize(), header.getMTime().getTime()); }
/** * Extract the file specified by the given header and write it to the * supplied output stream * * @param header * the header to be extracted * @param os * the outputstream * @throws RarException */ public void extractFile(FileHeader hd, OutputStream os) throws RarException { if (!headers.contains(hd)) { throw new RarException(RarExceptionType.headerNotInArchive); } try { doExtractFile(hd, os); } catch (Exception e) { if (e instanceof RarException) { throw (RarException) e; } else { throw new RarException(e); } } }
count -= retCode; unpPackedSize -= retCode; archive.bytesReadRead(retCode); if (unpPackedSize == 0 && subHead.isSplitAfter()) { if (!Volume.mergeArchive(archive, this)) {