From 124f869faae3a0f75a3825e6a8e195c17f3c626a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 16 Oct 2014 23:34:20 +0400 Subject: initial for idea --- .../com/github/junrar/rarfile/FileNameDecoder.java | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 org.fox.ttcomics/src/main/java/com/github/junrar/rarfile/FileNameDecoder.java (limited to 'org.fox.ttcomics/src/main/java/com/github/junrar/rarfile/FileNameDecoder.java') diff --git a/org.fox.ttcomics/src/main/java/com/github/junrar/rarfile/FileNameDecoder.java b/org.fox.ttcomics/src/main/java/com/github/junrar/rarfile/FileNameDecoder.java new file mode 100644 index 0000000..aee1179 --- /dev/null +++ b/org.fox.ttcomics/src/main/java/com/github/junrar/rarfile/FileNameDecoder.java @@ -0,0 +1,76 @@ +/* + * + * Original author: alpha_lam + * Creation date: ? + * + * Source: $HeadURL$ + * Last changed: $LastChangedDate$ + * + * + * the unrar licence applies to all junrar source and binary distributions + * you are not allowed to use this source to re-create the RAR compression algorithm + * + * Here some html entities which can be used for escaping javadoc tags: + * "&": "&" or "&" + * "<": "<" or "<" + * ">": ">" or ">" + * "@": "@" + */ +package com.github.junrar.rarfile; + +public class FileNameDecoder { + public static int getChar(byte [] name,int pos){ + return name[pos]&0xff; + } + + public static String decode(byte [] name,int encPos){ + int decPos = 0; + int flags = 0; + int flagBits = 0; + + int low = 0; + int high = 0; + int highByte = getChar(name,encPos++); + StringBuffer buf = new StringBuffer(); + while(encPos < name.length){ + if(flagBits == 0){ + flags = getChar(name,encPos++); + flagBits = 8; + } + switch(flags >> 6){ + case 0: + buf.append((char)(getChar(name,encPos++))); + ++decPos; + break; + case 1: + buf.append((char)(getChar(name,encPos++)+(highByte<<8))); + ++decPos; + break; + case 2: + low = getChar(name,encPos); + high = getChar(name,encPos+1); + buf.append((char)((high << 8) + low)); + ++decPos; + encPos += 2; + break; + case 3: + int length = getChar(name,encPos++); + if((length&0x80)!=0){ + int correction = getChar(name,encPos++); + for(length=(length&0x7f)+2;length>0&&decPos0&&decPos