Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK

## java.net
Class URL

Method Summary
`void` | `eachByte(Closure closure)` Reads the InputStream from this URL, passing each byte to the given closure
`Object` | `eachLine(Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure
`Object` | `eachLine(int firstLine, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure
`Object` | `eachLine(String charset, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure
`Object` | `eachLine(String charset, int firstLine, Closure closure)` Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure
`String` | `getText()` Read the content of this URL and returns it as a String
`String` | `getText(String charset)` Read the data from this URL and return it as a String stream is closed before this method returns
`BufferedInputStream` | `newInputStream()` Creates a buffered input stream for this URL
`BufferedReader` | `newReader()` Creates a buffered reader for this URL
`BufferedReader` | `newReader(String charset)` Creates a buffered reader for this URL using the given encoding
`Object` | `withInputStream(Closure closure)` Creates a new InputStream for this URL and passes it into the closure This method ensures the stream is closed after the closure returns
`Object` | `withReader(Closure closure)` Helper method to create a new BufferedReader for a URL and then passes it to the closure
`Object` | `withReader(String charset, Closure closure)` Helper method to create a new Reader for a URL and then passes it to the closure

Method Detail

### eachByte

    public void eachByte(Closure closure)

  Reads the InputStream from this URL, passing each byte to the given closure. The URL stream will be closed before this method returns.

Parameters:
  `closure` - closure to apply to each byte.
See:
  #eachByte(InputStream,Closure).

### eachLine

    public Object eachLine(Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
  `closure` - a closure to apply on each line.
Returns:
  the last value returned by the closure

See:
  #eachLine.

### eachLine

    public Object eachLine(int firstLine, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
  `firstLine` - the count of the first line.
  `closure` - a closure to apply on each line.
Returns:
  the last value returned by the closure

See:
  #eachLine.

### eachLine

    public Object eachLine(String charset, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
  `charset` - opens the stream with a specified charset.
  `closure` - a closure to apply on each line.
Returns:
  the last value returned by the closure

See:
  #eachLine.

### eachLine

    public Object eachLine(String charset, int firstLine, Closure closure)

  Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.

Parameters:
  `charset` - opens the stream with a specified charset.
  `firstLine` - the count of the first line.
  `closure` - a closure to apply on each line.
Returns:
  the last value returned by the closure

See:
  #eachLine.

### getText

    public String getText()

  Read the content of this URL and returns it as a String.

Returns:
  the text from that URL

### getText

    public String getText(String charset)

  Read the data from this URL and return it as a String. The connection stream is closed before this method returns.

Parameters:
  `charset` - opens the stream with a specified charset.
Returns:
  the text from that URL

See:
  URLConnection#getInputStream().

### newInputStream

    public BufferedInputStream newInputStream()

  Creates a buffered input stream for this URL.

Returns:
  a BufferedInputStream for the URL

### newReader

    public BufferedReader newReader()

  Creates a buffered reader for this URL.

Returns:
  a BufferedReader for the URL

### newReader

    public BufferedReader newReader(String charset)

  Creates a buffered reader for this URL using the given encoding.

Parameters:
  `charset` - opens the stream with a specified charset.
Returns:
  a BufferedReader for the URL

### withInputStream

    public Object withInputStream(Closure closure)

  Creates a new InputStream for this URL and passes it into the closure. This method ensures the stream is closed after the closure returns.

Parameters:
  `closure` - a closure.
Returns:
  the value returned by the closure

See:
  #withStream(InputStream,Closure).

### withReader

    public Object withReader(Closure closure)

  Helper method to create a new BufferedReader for a URL and then passes it to the closure. The reader is closed after the closure returns.

Parameters:
  `closure` - the closure to invoke with the reader.
Returns:
  the value returned by the closure

### withReader

    public Object withReader(String charset, Closure closure)

  Helper method to create a new Reader for a URL and then passes it to the closure. The reader is closed after the closure returns.

Parameters:
  `charset` - the charset used.
  `closure` - the closure to invoke with the reader.
Returns:
  the value returned by the closure

Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK