파일 업로드 다운로드 InputStream과string,bytes 호환

1276 단어 Inputstream
1. 파일 업로드 InputStream 회전string 또는 bytes
 
 
	private byte [] inputStreamToByte(InputStream is) throws IOException { 
        ByteArrayOutputStream bAOutputStream = new ByteArrayOutputStream(); 
        int ch; 
        while((ch = is.read() ) != -1){ 
            bAOutputStream.write(ch); 
        } 
        byte data [] =bAOutputStream.toByteArray(); 
        bAOutputStream.close(); 
        return data; 
    } 
	
	private String inputStreamToString(InputStream is) throws IOException { 
        ByteArrayOutputStream bAOutputStream = new ByteArrayOutputStream(); 
        int ch; 
        while((ch = is.read() ) != -1){ 
            bAOutputStream.write(ch); 
        } 
        String data = bAOutputStream.toString(); 
        bAOutputStream.close(); 
        return data; 
    }

 
2. string을 다운로드하여 InputStream으로 전환
 
 
 
public InputStream getInputStream() throws Exception {
          return new ByteArrayInputStream(org.getFileContent().getBytes("UTF-8"));
}
		
 : org.getFileContent()    clob  ,hibernate  “text” ,pojo  “String”

좋은 웹페이지 즐겨찾기