本文整理汇总了Java中com.github.junrar.Archive类的典型用法代码示例。如果您正苦于以下问题:Java Archive类的具体用法?Java Archive怎么用?Java Archive使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Archive类属于com.github.junrar包,在下文中一共展示了Archive类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: RarredFile
import com.github.junrar.Archive; //导入依赖的package包/类
public RarredFile(File f) {
this.f = f;
setLastModified(f.lastModified());
try {
rarFile = new Archive(f);
List<FileHeader> headers = rarFile.getFileHeaders();
for (FileHeader fh : headers) {
// if (fh.getFullUnpackSize() < MAX_ARCHIVE_ENTRY_SIZE && fh.getFullPackSize() < MAX_ARCHIVE_ENTRY_SIZE)
addChild(new RarredEntry(fh.getFileNameString(), f, fh.getFileNameString(), fh.getFullUnpackSize()));
}
rarFile.close();
} catch (RarException | IOException e) {
LOGGER.error(null, e);
}
}
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:19,代码来源:RarredFile.java
示例2: parse
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
public void parse(File file) throws IOException {
try {
mArchive = new Archive(file);
}
catch (RarException e) {
throw new IOException("unable to open archive");
}
FileHeader header = mArchive.nextFileHeader();
while (header != null) {
if (!header.isDirectory()) {
String name = getName(header);
if (Utils.isImage(name)) {
mHeaders.add(header);
}
}
header = mArchive.nextFileHeader();
}
Collections.sort(mHeaders, new NaturalOrderComparator() {
@Override
public String stringValue(Object o) {
return getName((FileHeader) o);
}
});
}
开发者ID:nkanaev,项目名称:bubble,代码行数:29,代码来源:RarParser.java
示例3: init
import com.github.junrar.Archive; //导入依赖的package包/类
private boolean init(){
if (!rarFileName.toLowerCase().endsWith(".rar")) {
logger.error("not rar file, fileName:{}!", rarFileName);
return false;
}
try {
archive = new Archive(new File(rarFileName));
} catch(Exception e){
logger.error("", e);
return false;
}
getNextBuffer();
return true;
}
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:17,代码来源:ReadRarFile.java
示例4: openRarAddMetadata
import com.github.junrar.Archive; //导入依赖的package包/类
/**
* Extract information regarding the CBR format
*
* @param result
* path information about the file
* @return more information regarding the file including the page numbers
* and size
* @throws RarException
* @throws IOException
*/
public ComicBook openRarAddMetadata(ComicBook result) throws RarException, IOException {
int numberOfPages = 0;
Archive rar = new Archive(new File(result.getFileSystempath()));
FileHeader fileHeader = rar.nextFileHeader();
while (fileHeader != null) {
if (!fileHeader.isDirectory()) {
//name = fileHeader.getFileNameString();
if (fileHeader.getFileNameString().contains(".jpg")) {
numberOfPages++;
}
}
fileHeader = rar.nextFileHeader();
}
result.setNumberOfPages(numberOfPages);
//TODO: Add more metadata from file if there is one
rar.close();
return result;
}
开发者ID:sparksmith,项目名称:TheComicBook,代码行数:29,代码来源:MetadataGatherer.java
示例5: ZipExtractTask
import com.github.junrar.Archive; //导入依赖的package包/类
public ZipExtractTask(Archive rar, String outputDir, Activity zipViewer, String fileName,boolean zip,FileHeader fileHeader) {
this.zip=zip;
this.outputDir = outputDir;
this.rar = rar;
this.zipViewer = zipViewer;
this.fileName = fileName;
this.header = fileHeader;
}
开发者ID:DeFuture,项目名称:AmazeFileManager-master,代码行数:9,代码来源:ZipExtractTask.java
示例6: unzipRAREntry
import com.github.junrar.Archive; //导入依赖的package包/类
private void unzipRAREntry(Archive zipfile, FileHeader header, String outputDir)
throws IOException, RarException {
output = new File(outputDir + "/" + header.getFileNameString().trim());
FileOutputStream fileOutputStream = new FileOutputStream(output);
zipfile.extractFile(header, fileOutputStream);
}
开发者ID:DeFuture,项目名称:AmazeFileManager-master,代码行数:8,代码来源:ZipExtractTask.java
示例7: doInBackground
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
protected ArrayList<CompressedObjectParcelable> doInBackground(Void... params) {
ArrayList<CompressedObjectParcelable> elements = new ArrayList<>();
try {
if (createBackItem) {
elements.add(0, new CompressedObjectParcelable());
}
Archive zipfile = new Archive(new File(fileLocation));
String relativeDirDiffSeparator = relativeDirectory.replace("/", "\\");
for (FileHeader header : zipfile.getFileHeaders()) {
String name = header.getFileNameString();//This uses \ as separator, not /
boolean isInBaseDir = (relativeDirDiffSeparator == null || relativeDirDiffSeparator.equals("")) && !name.contains("\\");
boolean isInRelativeDir = relativeDirDiffSeparator != null && name.contains("\\")
&& name.substring(0, name.lastIndexOf("\\")).equals(relativeDirDiffSeparator);
if (isInBaseDir || isInRelativeDir) {
elements.add(new CompressedObjectParcelable(RarHelper.convertName(header), 0, header.getDataSize(), header.isDirectory()));
}
}
Collections.sort(elements, new CompressedObjectParcelable.Sorter());
} catch (RarException | IOException e) {
e.printStackTrace();
}
return elements;
}
开发者ID:TeamAmaze,项目名称:AmazeFileManager,代码行数:30,代码来源:RarHelperTask.java
示例8: unzipRAREntry
import com.github.junrar.Archive; //导入依赖的package包/类
private void unzipRAREntry(@NonNull final Context context, Archive zipFile, FileHeader entry, String outputDir)
throws RarException, IOException {
String name = entry.getFileNameString();
name = name.replaceAll("\\\\", "/");
if (entry.isDirectory()) {
FileUtil.mkdir(new File(outputDir, name), context);
return;
}
File outputFile = new File(outputDir, name);
if (!outputFile.getParentFile().exists()) {
FileUtil.mkdir(outputFile.getParentFile(), context);
}
// Log.i("Amaze", "Extracting: " + entry);
BufferedInputStream inputStream = new BufferedInputStream(
zipFile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(
FileUtil.getOutputStream(outputFile, context, entry.getFullUnpackSize()));
try {
int len;
byte buf[] = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
ServiceWatcherUtil.POSITION += len;
}
} finally {
outputStream.close();
inputStream.close();
}
}
开发者ID:TeamAmaze,项目名称:AmazeFileManager,代码行数:31,代码来源:ExtractService.java
示例9: extractFile
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
protected boolean extractFile(Archive archive, FileHeader fileHeader, File destFile) throws IOException {
final boolean success = super.extractFile(archive, fileHeader, destFile);
if (success)
listener.onNewItem(destFile);
return success;
}
开发者ID:reines,项目名称:mediamanager,代码行数:9,代码来源:MediaRarFileHandler.java
示例10: extractFile
import com.github.junrar.Archive; //导入依赖的package包/类
protected boolean extractFile(Archive archive, FileHeader fileHeader, File destFile) throws IOException {
final OutputStream out = new FileOutputStream(destFile);
try {
archive.extractFile(fileHeader, out);
files.addHandled(fileHeader.getFileNameString());
return true;
}
catch (RarException e) {
throw new IOException(e);
}
finally {
out.close();
}
}
开发者ID:reines,项目名称:mediamanager,代码行数:16,代码来源:RarFileHandler.java
示例11: nextArchive
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
public Volume nextArchive(Archive archive, Volume last)
throws IOException {
if (last == null)
return new FileVolume(archive, firstVolume);
FileVolume lastFileVolume = (FileVolume) last;
boolean oldNumbering = !archive.getMainHeader().isNewNumbering()
|| archive.isOldFormat();
String nextName = VolumeHelper.nextVolumeName(lastFileVolume.getFile()
.getAbsolutePath(), oldNumbering);
File nextVolume = new File(nextName);
return new FileVolume(archive, nextVolume);
}
开发者ID:pabloalba,项目名称:komics,代码行数:16,代码来源:FileVolumeManager.java
示例12: getAllImagesNamesFromFile
import com.github.junrar.Archive; //导入依赖的package包/类
public static ArrayList<String> getAllImagesNamesFromFile(File file,
File outputDir) {
ArrayList<String> fileNames = new ArrayList<String>();
try {
Archive arch = new Archive(file);
FileHeader fh = null;
while (true) {
fh = arch.nextFileHeader();
if (fh == null) {
break;
}
if ((fh != null)
&& (!fh.isDirectory())
&& (Utils.isSupportedFile(fh.getFileNameString(),
AppConstant.IMAGE_EXTN))) {
fileNames
.add(outputDir.getAbsolutePath()
+ File.separator
+ Utils.absolutePathToString(fh
.getFileNameString()));
}
}
arch.close();
} catch (Exception e) {
Log.e("Decompress", "unrar", e);
}
Collections.sort(fileNames);
return fileNames;
}
开发者ID:pabloalba,项目名称:komics,代码行数:31,代码来源:RarExtractor.java
示例13: unzipRAREntry
import com.github.junrar.Archive; //导入依赖的package包/类
private void unzipRAREntry(int id,String a, Archive zipfile, FileHeader entry, String outputDir)
throws IOException, RarException {
String name=entry.getFileNameString();
name=name.replaceAll("\\\\","/");
if (entry.isDirectory()) {
createDir(new File(outputDir, name));
return;
}
File outputFile = new File(outputDir, name);
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
// Log.i("Amaze", "Extracting: " + entry);
BufferedInputStream inputStream = new BufferedInputStream(
zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(outputFile));
try {
int len;
byte buf[] = new byte[20480];
while ((len = inputStream.read(buf)) > 0) {
//System.out.println(id + " " + hash.get(id));
if (hash.get(id)) {
outputStream.write(buf, 0, len);
copiedbytes=copiedbytes+len;
int p=(int) ((copiedbytes / (float) totalbytes) * 100);
if(p!=lastpercent || lastpercent==0){
publishResults(a,p,id,totalbytes,copiedbytes,false);
publishResults(true);
}
lastpercent=p;
} else {
publishResults(a,100,id,totalbytes,copiedbytes,true);
publishResults(false);
stopSelf(id);
}
}
}finally {
outputStream.close();
inputStream.close();
}
}
开发者ID:DeFuture,项目名称:AmazeFileManager-master,代码行数:43,代码来源:ExtractService.java
示例14: read
import com.github.junrar.Archive; //导入依赖的package包/类
/**
* Read from compressed file
*
* @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);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Archive arch = new Archive(new File(srcPath));
try {
if (arch.isEncrypted()) {
FileCompressor.LOGGER.error(fileCompressor.hashCode()
+ " Archive is encrypted. Cannot read <" + srcPath
+ ">");
return;
}
FileHeader entry = null;
while (true) {
entry = arch.nextFileHeader();
if (entry == null)
break;
if (entry.isDirectory()) {
continue;
}
String name = entry.isUnicode() ? entry.getFileNameW() : entry
.getFileNameString();
if (entry.isEncrypted()) {
FileCompressor.LOGGER.error(fileCompressor.hashCode()
+ " File is encrypted. Cannot read <" + name + ">");
continue;
}
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
arch.extractFile(entry, baos);
BinaryFile binaryFile = new BinaryFile(name, baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
arch.close();
baos.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
开发者ID:espringtran,项目名称:compressor4j,代码行数:56,代码来源:RarProcessor.java
示例15: handleFile
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
public void handleFile(String relativePath, File file) throws IOException {
try {
final Archive archive = new Archive(file);
int handled = 0;
final List<FileHeader> fileHeaders = archive.getFileHeaders();
for (FileHeader fileHeader : fileHeaders) {
if (!this.acceptContainedFile(fileHeader))
continue;
final String path = PATH_NORMALISATION_REGEX.matcher(fileHeader.getFileNameString()).replaceAll(File.separator);
final File destFile = this.getDestinationFile(path);
if (LOG.isDebugEnabled())
LOG.debug("Extracting {} to {}", fileHeader.getFileNameString(), destFile.getAbsoluteFile());
// Make the parent directory if required
final File destDir = destFile.getParentFile();
if (!destDir.exists())
destDir.mkdirs();
if (this.extractFile(archive, fileHeader, destFile))
handled++;
}
if (handled < 1)
throw new IOException("Skipping rar file with no handleable contents: " + file.getName());
if (delete) {
if (LOG.isDebugEnabled())
LOG.debug("Deleting archive {} after extracting {} files", file.getName(), handled);
// Delete the .rar
file.delete();
// Delete any related .r00 parts
final String filename = DownloadDirManager.getFileName(file.getName());
final Pattern pattern = Pattern.compile(Pattern.quote(filename) + "\\.(r\\d+)", Pattern.CASE_INSENSITIVE);
for (File part : file.getParentFile().listFiles()) {
// Only delete files that are related rars
if (!pattern.matcher(part.getName()).matches())
continue;
if (LOG.isTraceEnabled())
LOG.trace("Deleting archive part {} after extracting files", part.getName());
part.delete();
}
}
}
catch (RarException e) {
throw new IOException(e);
}
}
开发者ID:reines,项目名称:mediamanager,代码行数:57,代码来源:RarFileHandler.java
示例16: ComprDataIO
import com.github.junrar.Archive; //导入依赖的package包/类
public ComprDataIO(Archive arc) {
this.archive = arc;
}
开发者ID:pabloalba,项目名称:komics,代码行数:4,代码来源:ComprDataIO.java
示例17: FileVolume
import com.github.junrar.Archive; //导入依赖的package包/类
/**
* @param file
*/
public FileVolume(Archive archive, File file) {
this.archive = archive;
this.file = file;
}
开发者ID:pabloalba,项目名称:komics,代码行数:8,代码来源:FileVolume.java
示例18: getArchive
import com.github.junrar.Archive; //导入依赖的package包/类
@Override
public Archive getArchive() {
return archive;
}
开发者ID:pabloalba,项目名称:komics,代码行数:5,代码来源:FileVolume.java
注:本文中的com.github.junrar.Archive类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论