Java 为什么我的方法在调用InflateObject.inflate(字节[]数组)后无法继续?

Java 为什么我的方法在调用InflateObject.inflate(字节[]数组)后无法继续?,java,compression,inflate,Java,Compression,Inflate,我试图创建一个程序,该程序必须对文件内容进行反编译 我的代码如下,问题是在我调用了解压器.inflate(result)之后,这个方法不再执行任何操作。我是否必须通过另一个字段替换结果,或者错误在哪里 //The string with the not yet decompressed content is converted into a byte array Content was earlier defined and initialised byte[] notDeComPresCo =

我试图创建一个程序,该程序必须对文件内容进行反编译

我的代码如下,问题是在我调用了
解压器.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.");
}
//包含尚未解压缩内容的字符串将转换为字节数组内容,该内容是先前定义和初始化的
byte[]notDeComPresCo=新字节[content.length()];
对于(int i=0;i
控制台中没有给出错误,方法在到达
System.out.println(“This System.out.println-command not print”)
之前结束

我有两个猜测:

  • int decompressedatalength=减压器。充气(结果)抛出某种运行时异常,被上层吞没,这就是为什么您看不到任何合理的输出
  • notDeComPresCo
    的长度为0
  • aa我赌1。添加额外的
    catch
    子句,如

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

    并检查是否没有引发异常。

    您等待了多长时间?
    InvalidGitObjectFileException
    是否被抛出?是的,是的,sry,我错过了。。。但是它被抛出到调用此方法的另一个方法中!减压器应该减压,充气器应该充气。。。。。。但是这是离题的哦,notDeComPresCo的长度是85,这个异常也不会被抛出。。。这是否意味着问题是一种运行时异常?
    catch(exception e)
    would-catch
    RuntimeException
    以及调试此代码时发生的情况?顺便说一句,您也可以执行
    e.printStacktrace(),或
    e.fillInStackTrace(系统输出)解压器正在填充缓冲区数组