public static FactoryImage createImage(InputStream is,String mediaType,String name) throws BadRequestException, ServerException {
  try {
    final ByteArrayOutputStream out=new ByteArrayOutputStream();
    final byte[] buffer=new byte[1024];
    int read;
    while ((read=is.read(buffer,0,buffer.length)) != -1) {
      out.write(buffer,0,read);
      if (out.size() > 1024 * 1024) {
        throw new BadRequestException("Maximum upload size exceeded.");
      }
    }
    if (out.size() == 0) {
      return new FactoryImage();
    }
    out.flush();
    return new FactoryImage(out.toByteArray(),mediaType,name);
  }
 catch (  IOException ioEx) {
    throw new ServerException(ioEx.getLocalizedMessage());
  }
}

public static FactoryImage createImage ( InputStream is , String mediaType , String name ) throws BadRequestException , ServerException { try { final ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; final byte [ ] buffer = new byte [ 1024 ] ; int read ; while ( ( read = is . read ( buffer , 0 , buffer . length ) ) != - 1 ) { out . write ( buffer , 0 , read ) ; if ( out . size ( ) > 1024 * 1024 ) { throw new BadRequestException ( "Maximum upload size exceeded." ) ; } } if ( out . size ( ) == 0 ) { return new FactoryImage ( ) ; } out . flush ( ) ; return new FactoryImage ( out . toByteArray ( ) , mediaType , name ) ; } catch ( IOException ioEx ) { throw new ServerException ( ioEx . getLocalizedMessage ( ) ) ; } }
creates factory image from input stream . inputstream should be closed manually .
