2011-07-27 4 views
0

Gmail에서 첨부 파일이있는 메일을 다운로드하려고 할 때 테스트 메일에 첨부 파일로 텍스트 파일이 포함되어 있습니다.javamail : 텍스트/일반 첨부 파일이 getContent에 의해 반환되고 InputStream에서 반환되지 않는 이유는 무엇입니까?

첨부 파일 부분은 텍스트 첨부 파일 콘텐츠 유형 및 파일 이름을 올바르게 반환합니다. 그러나 첨부 파일 InputStream에 대한 루프 조건은 절대로 0이 아닙니다.

시험 조금 후에

착오는

att_mbp.getContent() 

가 콘텐츠를 리턴 호를 도입 아래의 경우에 (텍스트/플레인의 콘텐츠가 부용의 getContent 방법을 사용하여 사용할 수 있음을 밝혀 첨부 된 텍스트 파일)

if (BodyPart.ATTACHMENT.equalsIgnoreCase(att_mbp.getDisposition())) { 

       att_mbp.getContentType(); 

       // process each attachment 
       // read the filename 
       file = att_mbp.getFileName(); 

       InputStream stream = att_mbp.getInputStream(); 

       BufferedInputStream br = new BufferedInputStream(stream); 
       BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file)); 

       while (br.available() > 0) { 
        // this loop is never executed for text/plain 
        bout.write(br.read()); 
       } 
       bout.flush(); 
       bout.close(); 

} 

내 질문입니다 - 왜의 getContent()에서만 사용할 수 있습니다, 그리고 너무 첨부의 InputStream 인스턴스의 텍스트/일반 첨부 바디?

답변

0

확인. 나는 마침내 그것을 알아 냈다.

사용할 수에 대한 호출은() 항상

int dataByte; 

while((dataByte = br.read()) > 0){ 
    bout.write(dataByte); 
} 

은 javadoc에 따르면,의 InputStream의 후손을 사용할 수 오버라이드 (override) 할 필요가 다음과 같이 내가 그것을 수정하면 코드는 일 0 반환합니다. 여기서는 그렇지 않은 것 같습니다.