0

I have been getting this broken pipe Exception. As far as I understood this exception occurs when there is connection closed suddenly. I have attached the code below. Can you please tell where I am going wrong. Thanks.

        remaingBarcode = gdbAutomationService.getGdbBarcodes(); //returning list of barcodes
        StringBuffer barcodes = new StringBuffer();
        barcodes.append("Barcode").append("\n");
        for(int i = 0; i < remaingBarcode.size(); i++) {
            barcodes.append(remaingBarcode.get(i));
            barcodes.append("\n");
        }
        response.setContentType("text/csv");
        response.addHeader("Content-Disposition", "attachment; filename = BarcodeDetails.csv");
        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            outputStream.write(barcodes.toString().getBytes());
        } catch(IOException e) {
            e.printStackTrace();
        } finally {
            System.out.println("In finally");
            outputStream.flush();
            outputStream.close();
        }       
Anusha Bayya
  • 103
  • 1
  • 5
  • 17
  • I am sorry @AxelH I did not get solution from that. can you tell me from my code what I should add ? – Anusha Bayya Oct 31 '17 at 10:04
  • The solution is not to write to connections that have already been closed by the peer, i.e. don't engage in application protocol errors. This is [all already stated in the duplicate](https://stackoverflow.com/a/4232540/207421). – user207421 Oct 31 '17 at 10:19

0 Answers0