Files.write上的java.nio.channels.ClosedByInterruptException(Path,byte [])

时间:2018-06-19 05:40:34

标签: java resttemplate

我需要下载附件文件(例如jpeg,gif,pdf等)我使用了Files.write(Path,byte [])方法,但我得到了ClosedByInterruptException

     public String downloadattachment(){
               try {            
                   headers.set("authorization", authorization);              
                   HttpEntity<String> entity = new HttpEntity<>(headers);            
                   ResponseEntity<byte[]> result = 
    restTemplate.exchange(attachmentUrl, 
                        HttpMethod.GET, entity, byte[].class);              
  String fileName = 
                result.getHeaders().getContentDisposition().getFilename();           
                String pathDirStr = applicationProperties.getLoggerPath() + 
                   File.separator + ticketId;            
                 SyncUtils.createDirIfNotExist(pathDirStr);                     
                 String pathFile = pathDirStr+File.separator+fileName;           
                 Files.write(Paths.get(pathFile), result.getBody());             
                 logger.debug("Attachment file downloaded in location : " + 
                  pathFile);            
                   resultPath=pathFile;         
              } catch (Exception e) { 
                    logger.debug("Exception occur while downloading attachment file.", e);

        } return resultPath; 
    }

迹:

"java.nio.channels.ClosedByInterruptException: null
        at java.nio.channels.spi.AbstractInterruptibleChannel.end(Unknown Source)
        at sun.nio.ch.FileChannelImpl.write(Unknown Source)
        at java.nio.channels.Channels.writeFullyImpl(Unknown Source)
        at java.nio.channels.Channels.writeFully(Unknown Source)
        at java.nio.channels.Channels.access$000(Unknown Source)
        at java.nio.channels.Channels$1.write(Unknown Source)
        at java.nio.file.Files.write(Unknown Source)
        at com.rogers.service.ComcastServiceImpl.downloadComcastAttachmentInDir(ComcastServiceImpl.java:564)

0 个答案:

没有答案