title: Convert byteArray to XSSFWorkbook using Apache POI
body: <p>I am using Apache POI and I am trying to send a <code>xlsx</code> file as HTTP request and get it back as response. I am using <code>jayway restassured</code> for making HTTP requests.</p>
  
  <p>Here is the part of the code where I send the request</p>
  
  <pre><code> File file = new File("path");
  String response = given().multipart(file).when().post("URL").getBody().asString();
  
  byte[] bytes = response.getBytes("ISO-8859-1");
  InputStream stream = new ByteArrayOutputStream(bytes);
  
  try
  {
      XSSFWorkbook workbook = new XSSFWorkbook(stream);
  }
  catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Here is the code where the response is generated for the request</p>
  
  <pre><code>XSSFWorkbook workBook;  //this workBook has the workbook sent as HTTP request
  //code to make changes in workBook
  
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  
  workBook.write(outStream);
  byte[] byteArray = outStream.toByteArray();
  String responseBody = new String(byteArray, "ISO-8859-1");
  
  context.response().putHeader("Content-Type", "multipart/form-data").setStatusCode(200).end(responseBody);
  </code></pre>
  
  <p>So, what I am trying to do is send a <code>xlsx</code> file as request make some changes and get it back as a string response, convert it back to xssfworkbook. When converting back I get error in the following line-</p>
  
  <pre><code>XSSFWorkbook workbook = new XSSFWorkbook(stream);
  </code></pre>
  
  <p>The error I get is</p>
  
  <pre><code>java.util.zip.ZipException: invalid code lengths set
  </code></pre>