本文整理汇总了Java中com.github.junrar.exception.RarException类的典型用法代码示例。如果您正苦于以下问题:Java RarException类的具体用法?Java RarException怎么用?Java RarException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RarException类属于com.github.junrar.exception包,在下文中一共展示了RarException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RarredFile
import com.github.junrar.exception.RarException; //导入依赖的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);
}
}
示例2: parse
import com.github.junrar.exception.RarException; //导入依赖的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);
}
});
}
示例3: main
import com.github.junrar.exception.RarException; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Integer numberOfPages = 5;
File path = new File("/Users/sparksmith/comicReader/");
DeleteMe testing = new DeleteMe();
//LibraryPopulatorService archiver = new LibraryPopulatorService();
try {
ComicBook test = LibraryPopulatorService.getComicBook(new File("/Users/sparksmith/Documents/Programming/GITHUB/TheComicBook/"
+ "The Comic Book/testFiles/testComic2.cbz"));
System.out.println("The file: " + test.getFileName() + "\n" + "With size: " + test.getFileSize() + "MB\n" + "With filetype: "
+ test.getFileType() + "\n" + "With original archiving method: " + test.getOriginalArchiving() + "\n"
+ "With number of pages: " + test.getNumberOfPages());
ArrayList<BufferedImage> t2 = ImageExtractingService.getImages(test, path, 22, 33, Destination.RAM);
System.out.println("Size: " + t2.size());
testing.start(t2.get(3));
} catch (fileNotFound | IOException | RarException e) {
e.printStackTrace();
}
}
示例4: openRarAddMetadata
import com.github.junrar.exception.RarException; //导入依赖的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;
}
示例5: doUnpack
import com.github.junrar.exception.RarException; //导入依赖的package包/类
public void doUnpack(int method, boolean solid) throws IOException,
RarException {
if (unpIO.getSubHeader().getUnpMethod() == 0x30) {
unstoreFile();
}
switch (method) {
case 15: // rar 1.5 compression
unpack15(solid);
break;
case 20: // rar 2.x compression
case 26: // files larger than 2GB
unpack20(solid);
break;
case 29: // rar 3.x compression
case 36: // alternative hash
unpack29(solid);
break;
}
}
示例6: readVMCode
import com.github.junrar.exception.RarException; //导入依赖的package包/类
private boolean readVMCode() throws IOException, RarException {
int FirstByte = getbits() >> 8;
addbits(8);
int Length = (FirstByte & 7) + 1;
if (Length == 7) {
Length = (getbits() >> 8) + 7;
addbits(8);
} else if (Length == 8) {
Length = getbits();
addbits(16);
}
List<Byte> vmCode = new ArrayList<Byte>();
for (int I = 0; I < Length; I++) {
if (inAddr >= readTop - 1 && !unpReadBuf() && I < Length - 1) {
return (false);
}
vmCode.add(Byte.valueOf((byte) (getbits() >> 8)));
addbits(8);
}
return (addVMCode(FirstByte, vmCode, Length));
}
示例7: ariDecNormalize
import com.github.junrar.exception.RarException; //导入依赖的package包/类
public void ariDecNormalize() throws IOException, RarException
{
// while ((low ^ (low + range)) < TOP || range < BOT && ((range = -low & (BOT - 1)) != 0 ? true : true))
// {
// code = ((code << 8) | unpackRead.getChar()&0xff)&uintMask;
// range = (range << 8)&uintMask;
// low = (low << 8)&uintMask;
// }
// Rewrote for clarity
boolean c2 = false;
while ((low ^ (low + range)) < TOP || (c2 = range < BOT)) {
if (c2) {
range = (-low & (BOT - 1))&uintMask;
c2 = false;
}
code = ((code << 8) | getChar())&uintMask;
range = (range << 8)&uintMask;
low = (low << 8)&uintMask;
}
}
示例8: unzipRAREntry
import com.github.junrar.exception.RarException; //导入依赖的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);
}
示例9: unzipTAREntry
import com.github.junrar.exception.RarException; //导入依赖的package包/类
private void unzipTAREntry(int id, TarArchiveInputStream zipfile, TarArchiveEntry entry, String outputDir,String string)
throws IOException, RarException {
String name=entry.getName();
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);
BufferedOutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(outputFile));
try {
int len;
byte buf[] = new byte[20480];
while ((len = zipfile.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(string,p,id,totalbytes,copiedbytes,false);
publishResults(true);}
lastpercent=p;
} else {
publishResults(string, 100, id, totalbytes, copiedbytes, true);
publishResults(false);
stopSelf(id);
}
}
}finally {
outputStream.close();
}
}
示例10: doInBackground
import com.github.junrar.exception.RarException; //导入依赖的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;
}
示例11: doInBackground
import com.github.junrar.exception.RarException; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... p) {
final ExtractService extractService = this.extractService.get();
if(extractService == null) return null;
File f = new File(compressedPath);
if (!compressedPath.equals(extractionPath)) {// custom extraction path not set, extract at default path
extractionPath = f.getParent() + "/" + f.getName().substring(0, f.getName().lastIndexOf("."));
} else if (extractionPath.endsWith("/")) {
extractionPath = extractionPath + f.getName().substring(0, f.getName().lastIndexOf("."));
}
try {
String path = f.getPath().toLowerCase();
boolean isZip = path.endsWith(".zip") || path.endsWith(".jar") || path.endsWith(".apk");
boolean isTar = path.endsWith(".tar") || path.endsWith(".tar.gz");
boolean isRar = path.endsWith(".rar");
if (entriesToExtract != null && entriesToExtract.length != 0) {
if (isZip) extract(extractService, f, extractionPath, entriesToExtract);
else if (isRar) extractRar(extractService, f, extractionPath, entriesToExtract);
} else {
if (isZip) extract(extractService, f, extractionPath);
else if (isRar) extractRar(extractService, f, extractionPath);
else if (isTar) extractTar(extractService, f, extractionPath);
}
} catch (IOException | RarException e) {
Log.e("amaze", "Error while extracting file " + compressedPath, e);
AppConfig.toast(extractService, extractService.getString(R.string.error));
}
return null;
}
示例12: unzipRAREntry
import com.github.junrar.exception.RarException; //导入依赖的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();
}
}
示例13: fromFile
import com.github.junrar.exception.RarException; //导入依赖的package包/类
/**
* Get the file, analyze it and return a filled in ComicBook
*
* @param file
* -> the absolute path to the file
* @return ComicBook -> filled with metadata that can be extracted and the
* images
* @throws fileNotFound
* the file does not exists
* @throws IOException
* the file can't be read
* @throws RarException
* the file can't be un-archived
*/
private static ComicBook fromFile(final File file) throws fileNotFound, IOException, RarException {
MetadataGatherer opener = new MetadataGatherer();
ComicBook result = null;
if (file.exists()) {
result = new ComicBook(file);
switch (result.getOriginalArchiving()) {
// ZIP
case ZIP:
result = opener.openZipAddMetadata(result);
break;
// RAR -> is a bit special because it is not in the JDK
case RAR:
result = opener.openRarAddMetadata(result);
break;
case TAR:
//TODO: Do the tar
throw new fileNotFound("NOT IMPLEMENTED TAR TYPE");
//break;
case SEVENz:
//TODO: Do the 7z
throw new fileNotFound("NOT IMPLEMENTED 7z TYPE");
//break;
case ACE:
//TODO: Do the ACE
throw new fileNotFound("NOT IMPLEMENTED ACE TYPE");
//break;
default:
//TODO: Need to change the error -> unsupported file type
throw new fileNotFound("Cant unarchive the file");
}
} else {
throw new fileNotFound("Comic book does not exist");
}
return result;
}
示例14: extractFile
import com.github.junrar.exception.RarException; //导入依赖的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();
}
}
示例15: unstoreFile
import com.github.junrar.exception.RarException; //导入依赖的package包/类
private void unstoreFile() throws IOException, RarException {
byte[] buffer = new byte[0x10000];
while (true) {
int code = unpIO.unpRead(buffer, 0, (int) Math.min(buffer.length,
destUnpSize));
if (code == 0 || code == -1)
break;
code = code < destUnpSize ? code : (int) destUnpSize;
unpIO.unpWrite(buffer, 0, code);
if (destUnpSize >= 0)
destUnpSize -= code;
}
}