View Javadoc

1   package org.codehaus.xfire.wsdl;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.io.OutputStream;
6   import java.net.URL;
7   import java.net.MalformedURLException;
8   
9   import javax.wsdl.WSDLException;
10  
11  /***
12   * Create a WSDL instance from a URI.
13   *
14   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
15   */
16  public class ResourceWSDL
17  	implements WSDLWriter
18  {
19      private final URL wsdlUrl;
20  
21      /***
22       * @param wsdlUrl
23       */
24      public ResourceWSDL(String wsdlUrl) throws WSDLException
25      {
26          try
27          {
28              this.wsdlUrl = new URL( wsdlUrl );
29          }
30          catch (MalformedURLException e)
31          {
32              throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid URL to WSDL file", e);
33          }
34      }
35  
36      /***
37       * @param wsdlUrl
38       */
39      public ResourceWSDL(URL wsdlUrl)
40      {
41          this.wsdlUrl = wsdlUrl;
42      }
43  
44      public void write(OutputStream out) throws IOException
45      {
46         copy( wsdlUrl.openStream(), out, 8096 );
47      }
48  
49      private void copy(final InputStream input,
50                       final OutputStream output,
51                       final int bufferSize)
52          throws IOException
53      {
54          try
55          {
56              final byte[] buffer = new byte[bufferSize];
57  
58              int n = 0;
59              while (-1 != (n = input.read(buffer)))
60              {
61                  output.write(buffer, 0, n);
62              }
63          }
64          finally
65          {
66              input.close();
67          }
68      }
69  }