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.
`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.
`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.

Since:
  1.0

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 (arg 1 is line, optional arg 2 is line number starting at line 1).

Returns:
  the last value returned by the closure

Since:
  1.5.6

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 (arg 1 is line, optional arg 2 is line number).

Returns:
  the last value returned by the closure

Since:
  1.5.7

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 (arg 1 is line, optional arg 2 is line number starting at line 1).

Returns:
  the last value returned by the closure

Since:
  1.5.6

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 (arg 1 is line, optional arg 2 is line number).

Returns:
  the last value returned by the closure

Since:
  1.5.7

See:
  #eachLine.

### getText

    public String getText()

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

Returns:
  the text from that URL

Since:
  1.0

### 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

Since:
  1.0

See:
  URLConnection#getInputStream().

### newInputStream

    public BufferedInputStream newInputStream()

  Creates a buffered input stream for this URL.

Returns:
  a BufferedInputStream for the URL

Since:
  1.5.2

### newReader

    public BufferedReader newReader()

  Creates a buffered reader for this URL.

Returns:
  a BufferedReader for the URL

Since:
  1.5.5

### 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

Since:
  1.5.5

### 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

Since:
  1.5.2

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

Since:
  1.5.2

### 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

Since:
  1.5.6

Groovy JDK