Bubble up gzip/bzip errors, fix map dumper test, add datafile xtea testcase
This commit is contained in:
@@ -128,7 +128,7 @@ public class CacheClient
|
||||
return clientRevision;
|
||||
}
|
||||
|
||||
public void download() throws InterruptedException, ExecutionException, FileNotFoundException
|
||||
public void download() throws InterruptedException, ExecutionException, FileNotFoundException, IOException
|
||||
{
|
||||
FileResult result = requestFile(255, 255).get();
|
||||
result.decompress(null);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
package net.runelite.cache.downloader;
|
||||
|
||||
import java.io.IOException;
|
||||
import net.runelite.cache.fs.DataFile;
|
||||
import net.runelite.cache.fs.DataFileReadResult;
|
||||
|
||||
@@ -67,7 +68,7 @@ public class FileResult
|
||||
return compressedData;
|
||||
}
|
||||
|
||||
public void decompress(int[] keys)
|
||||
public void decompress(int[] keys) throws IOException
|
||||
{
|
||||
DataFileReadResult res = DataFile.decompress(compressedData, keys);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
package net.runelite.cache.fs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -134,7 +135,7 @@ public class Archive
|
||||
}
|
||||
}
|
||||
|
||||
public void decompressAndLoad(int[] keys)
|
||||
public void decompressAndLoad(int[] keys) throws IOException
|
||||
{
|
||||
byte[] encryptedData = this.getData();
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ public class DataFile implements Closeable
|
||||
return res;
|
||||
}
|
||||
|
||||
public static DataFileReadResult decompress(byte[] b, int[] keys)
|
||||
public static DataFileReadResult decompress(byte[] b, int[] keys) throws IOException
|
||||
{
|
||||
InputStream stream = new InputStream(b);
|
||||
|
||||
@@ -420,24 +420,6 @@ public class DataFile implements Closeable
|
||||
|
||||
return stream.flip();
|
||||
}
|
||||
|
||||
private static int checkRevision(InputStream stream, int compressedLength)
|
||||
{
|
||||
int offset = stream.getOffset();
|
||||
int revision;
|
||||
if (stream.getLength() - (compressedLength + stream.getOffset()) >= 2)
|
||||
{
|
||||
stream.setOffset(stream.getLength() - 2);
|
||||
revision = stream.readUnsignedShort();
|
||||
assert revision != -1;
|
||||
stream.setOffset(offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
revision = -1;
|
||||
}
|
||||
return revision;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] data, int length, int[] keys)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.cache.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -46,62 +45,47 @@ public class BZip2
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BZip2.class);
|
||||
|
||||
private static final byte[] BZIP_HEADER = new byte[] {
|
||||
private static final byte[] BZIP_HEADER = new byte[]
|
||||
{
|
||||
'B', 'Z', // magic
|
||||
'h', // 'h' for Bzip2 ('H'uffman coding)
|
||||
'h', // 'h' for Bzip2 ('H'uffman coding)
|
||||
'1' // block size
|
||||
};
|
||||
|
||||
public static byte[] compress(byte[] bytes)
|
||||
|
||||
public static byte[] compress(byte[] bytes) throws IOException
|
||||
{
|
||||
try
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
try (OutputStream os = new BZip2CompressorOutputStream(bout, 1))
|
||||
{
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
try (OutputStream os = new BZip2CompressorOutputStream(bout, 1))
|
||||
{
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
byte[] out = bout.toByteArray();
|
||||
|
||||
assert BZIP_HEADER[0] == out[0];
|
||||
assert BZIP_HEADER[1] == out[1];
|
||||
assert BZIP_HEADER[2] == out[2];
|
||||
assert BZIP_HEADER[3] == out[3];
|
||||
|
||||
return Arrays.copyOfRange(out, BZIP_HEADER.length, out.length); // remove header..
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn(null, ex);
|
||||
return null;
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
byte[] out = bout.toByteArray();
|
||||
|
||||
assert BZIP_HEADER[0] == out[0];
|
||||
assert BZIP_HEADER[1] == out[1];
|
||||
assert BZIP_HEADER[2] == out[2];
|
||||
assert BZIP_HEADER[3] == out[3];
|
||||
|
||||
return Arrays.copyOfRange(out, BZIP_HEADER.length, out.length); // remove header..
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes, int len)
|
||||
public static byte[] decompress(byte[] bytes, int len) throws IOException
|
||||
{
|
||||
try
|
||||
byte[] data = new byte[len + BZIP_HEADER.length];
|
||||
|
||||
// add header
|
||||
System.arraycopy(BZIP_HEADER, 0, data, 0, BZIP_HEADER.length);
|
||||
System.arraycopy(bytes, 0, data, BZIP_HEADER.length, len);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
try (InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data)))
|
||||
{
|
||||
byte[] data = new byte[len + BZIP_HEADER.length];
|
||||
|
||||
// add header
|
||||
System.arraycopy(BZIP_HEADER, 0, data, 0, BZIP_HEADER.length);
|
||||
System.arraycopy(bytes, 0, data, BZIP_HEADER.length, len);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
try (InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data)))
|
||||
{
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
return os.toByteArray();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn(null, ex);
|
||||
return null;
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
return os.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class GZip
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(GZip.class);
|
||||
|
||||
public static byte[] compress(byte[] bytes)
|
||||
public static byte[] compress(byte[] bytes) throws IOException
|
||||
{
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
@@ -54,16 +54,11 @@ public class GZip
|
||||
{
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn(null, ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
return bout.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes, int len)
|
||||
public static byte[] decompress(byte[] bytes, int len) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
@@ -71,11 +66,6 @@ public class GZip
|
||||
{
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn(null, ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user