如何修复java.io.IOException:尝试从封闭流中读取?

时间:2014-10-08 07:39:44

标签: java ioexception rest-assured

我有下面的代码在第二个print语句中抛出IO错误。我无法弄清楚它为什么会扔。谁能帮我吗。如果我评论该行正常工作。我理解的是我使用了两次响应对象,但我应该可以使用多次。

Response response=customerResource.customerOperations("post",
    MDFCommonUtil.getInstance()
    .readFileAsString("CommonFiles/payloadForPost.xml"),null);

System.out.println("inside the methid=="+response.getStatusCode());

System.out.println("inside the methid=="+response.asString());

堆栈追踪:

  

java.io.IOException:尝试读取已关闭的流。在   org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:110)     在   org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:136)     at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)at   sun.nio.cs.StreamDecoder.implRead(未知来源)at   sun.nio.cs.StreamDecoder.read(未知来源)at   java.io.InputStreamReader.read(未知来源)at   java.io.BufferedReader.fill(未知来源)at   java.io.BufferedReader.read1(未知来源)at   java.io.BufferedReader.read(未知来源)at   java.io.Reader.read(未知来源)at   java_io_Reader $ read.call(未知来源)at   com.jayway.restassured.internal.RestAssuredResponseImpl.convertStreamToString(RestAssuredResponseImpl.groovy:366)     在   com.jayway.restassured.internal.RestAssuredResponseImpl.this $ 2 $ convertStreamToString(RestAssuredResponseImpl.groovy)     在   com.jayway.restassured.internal.RestAssuredResponseImpl $这$ 2 $ convertStreamToString.callCurrent(未知   来源)at   com.jayway.restassured.internal.RestAssuredResponseImpl.asString(RestAssuredResponseImpl.groovy:144)     在   mdf.test.rest.testcases.TestCustomerResource.postCustomerFeature2(TestCustomerResource.java:60)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)     在org.testng.internal.Invoker.invokeMethod(Invoker.java:714)at   org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)at at   org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)at at   org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)     在   org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)     在org.testng.TestRunner.privateRun(TestRunner.java:767)at   org.testng.TestRunner.run(TestRunner.java:617)at   org.testng.SuiteRunner.runTest(SuiteRunner.java:334)at   org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)at at   org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)at at   org.testng.SuiteRunner.run(SuiteRunner.java:240)at   org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)at   org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)at   org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)at at   org.testng.TestNG.runSuitesLocally(TestNG.java:1149)at at   org.testng.TestNG.run(TestNG.java:1057)at   org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)at at   org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)at at   org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

0 个答案:

没有答案