package kr.co.udapsoft.ebid.buyer.common.file;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class IOUtil {

	public static ByteArrayInputStream toByteArrayInputStream(InputStream inputStream) throws Exception {

        byte[] buffer = new byte[1024];
        BufferedInputStream  bis = new BufferedInputStream(inputStream);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        int offset = 0;
        try {
            while( (offset = bis.read(buffer)) != -1 ) {
                bos.write(buffer, 0, offset);
            }             
            bos.flush();
            
            return new ByteArrayInputStream(bos.toByteArray());
        }
        catch (Exception e) {
            throw e;
        }
        finally {
            if( bos != null ) try { bos.close(); } catch(Exception e){}
            if( bis != null ) try { bis.close(); } catch(Exception e){}
        }
	}
}
