
13.07.2009, 22:31
|
|
Познающий
Регистрация: 07.04.2007
Сообщений: 48
Провел на форуме: 199652
Репутация:
8
|
|
Народ помогите пожалуйста найти ошибочку в коде... (Java)
Кину код функции которая должна архивировать данные...
public static void packing(){//File path, String fileName){
try{
BufferedImage image = ImageIO.read(new File("X:/workspace/Java project/K-RLEArhivator/test/avatar77547.gif"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", outputStream);
byte[] data = outputStream.toByteArray();
System.out.println(outputStream.size());
FileOutputStream out = new FileOutputStream("file.dat");
int temp = 0;
for(int i = 0; i < data.length; i++){
temp = i;
while(data[i] != data[i+1])
{
packingData[index] = 00;
count++;
i++;
}
packingData[++index] = (byte) count;
for(int index_c = 0; index_c <= count; index_c++){
packingData[++index] = data[temp++];
}
count = 0;
temp = i;
while(data[i] == data [i+1]){
count2++;
i++;
}
packingData[index] = (byte) ++count2;
packingData[++index] = data[temp];
count2 = 0;
i++;
temp = i;
while(data[i] == data[i+1]){
count2++;
i++;
loop = true;
}
if(loop){
packingData[++index] = (byte) count2;
packingData[++index] = data[temp];
count2 = 0;
loop = false;
}
index++;
}
for(int b = 0; b < packingData.length; b++)
{
out.write(packingData[b]);
}
}
catch(IOException ioe){
ioe.printStackTrace();
}
Размерность аватарки - 19,725.
1)Проблема в том что когда я загружаю побайтово данные в массив data получаю размерность массива 3,523.
2)После запуска программы получаю сл ошибку:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3523
at Archiver.packing(Class_Main.java:49)
at Class_Main.main(Class_Main.java:16)
|
|
|