为什么我的方法在调用InflateObject.inflate(byte [] array)后没有继续?

时间:2014-08-20 11:50:02

标签: java compression inflate

我尝试创建一个必须解压缩文件内容的程序。

我的代码如下,问题是在我调用decompresser.inflate(result)之后,在此方法中不再执行任何操作。我是否必须通过其他字段替换结果或错误在哪里?

//The string with the not yet decompressed content is converted into a byte array Content was earlier defined and initialised
byte[] notDeComPresCo = new byte[content.length()];
for (int i = 0; i < content.length(); i++) {
    notDeComPresCo[i] = content.substring(i, i + 1).getBytes()[0];
}
//Until here the programm works as I want, then the problem starts:

//A new inflater is contructed to decompress the byte array into an decompressed byte array
Inflater decompressor = new Inflater();
decompressor.setInput(notDeComPresCo, 0, notDeComPresCo.length);
byte[] result = new byte[content.length()];
try {
    System.out.println("This is printed");
    int decompressedDataLength = decompressor.inflate(result);
    System.out.println("This system.out.println - command is not printed"); 
    decompressor.end();
    String x = new String(result, 0, decompressedDataLength, "UTF-8");
} catch (DataFormatException e) {
    throw new InvalidGitObjectFileException("The content could not be decompressed.");
}

控制台中没有错误,方法只在到达System.out.println("This system.out.println - command is not printed")之前结束。

1 个答案:

答案 0 :(得分:0)

我有两个猜测:

  1. int decompressedDataLength = decompressor.inflate(result);抛出某种被上层吞噬的运行时异常,这就是为什么你没有看到任何合理的输出
  2. notDeComPresCo的长度为0
  3. Aaand我的赌注是1.添加额外的catch条款,如

    catch (Exception e) {System.out.println(e.getMessage());}
    

    并检查是否没有抛出异常。