# Class Reader

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.io.Reader](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md)

The class supports reading characters from a stream.

## All Known Subclasses

[FileReader](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.FileReader.md)

## Property Summary

| Property                                                                                                                | Description                                                                       |
| ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| ~~[lines](#lines): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)~~ `(read-only)`        | The method reads the whole input stream, parses it and returns a list of strings. |
| ~~[string](#string): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~ `(read-only)` | The method reads the whole input stream as one string and returns it.             |

## Constructor Summary

| Constructor                                                                                                                                                                                                        | Description                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
| [Reader](#readerstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))                                                                                                        | Creates a reader from a string.                                       |
| [Reader](#readerinputstream)([InputStream](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.InputStream.md))                                                                                            | Create a reader from a stream using UTF-8 character encoding.         |
| [Reader](#readerinputstream-string)([InputStream](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.InputStream.md), [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)) | Create a reader from a stream using the specified character encoding. |

## Method Summary

| Method                                                                                                                                                                           | Description                                                                       |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| [close](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#close)()                                                                                           | Closes the reader.                                                                |
| ~~[getLines](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#getlines)()~~                                                                                 | The method reads the whole input stream, parses it and returns a list of strings. |
| ~~[getString](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#getstring)()~~                                                                               | The method reads the whole input stream as one string and returns it.             |
| [read](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#read)()                                                                                             | Reads a single character from the stream.                                         |
| ~~[read](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))~~ | Reads multiple characters from the stream as string.                              |
| [readLine](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readline)()                                                                                     | Reads the next line.                                                              |
| [readLines](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readlines)()                                                                                   | The method reads the whole input stream, parses it and returns a list of strings. |
| [readN](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))   | Reads n characters from the stream as string.                                     |
| [readString](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readstring)()                                                                                 | The method reads the whole input stream as one string and returns it.             |
| [ready](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#ready)()                                                                                           | Identifies if this stream is ready to be read.                                    |
| [skip](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#skipnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))     | Skips the specified number of characters in the stream.                           |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Property Details

### lines

- ~~lines: [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)~~ `(read-only)`
  - : The method reads the whole input stream, parses it and returns a list of strings.

    Using this method on large feeds is inherently unsafe and may lead to an out-of-memory condition. Instead use
    method [readLine()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readline) and process one line at a time.

    **Deprecated:**

:::warning
Use [readLines()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readlines)
:::

***

### string

- ~~string: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~ `(read-only)`
  - : The method reads the whole input stream as one string and returns it.

    Using this method is unsafe if the length of the input stream is not known and may lead to an out-of-memory
    condition. Instead use method [readN(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnnumber).

    **Deprecated:**

:::warning
Use [readString()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readstring)
:::

***

## Constructor Details

### Reader(String)

- Reader(source: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))
  - : Creates a reader from a string.

    **Parameters:**

    - source - the source string.

***

### Reader(InputStream)

- Reader(stream: [InputStream](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.InputStream.md))
  - : Create a reader from a stream using UTF-8 character encoding.

    **Parameters:**

    - stream - the input stream to use.

***

### Reader(InputStream, String)

- Reader(stream: [InputStream](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.InputStream.md), encoding: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))
  - : Create a reader from a stream using the specified character encoding.

    **Parameters:**

    - stream - the input stream to use.
    - encoding - the encoding to use.

***

## Method Details

### close()

- close(): void
  - : Closes the reader.

***

### getLines()

- ~~getLines(): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)~~
  - : The method reads the whole input stream, parses it and returns a list of strings.

    Using this method on large feeds is inherently unsafe and may lead to an out-of-memory condition. Instead use
    method [readLine()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readline) and process one line at a time.

    **Returns:**

    - a list of strings

    **Deprecated:**

:::warning
Use [readLines()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readlines)
:::

***

### getString()

- ~~getString(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~
  - : The method reads the whole input stream as one string and returns it.

    Using this method is unsafe if the length of the input stream is not known and may lead to an out-of-memory
    condition. Instead use method [readN(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnnumber).

    **Returns:**

    - a string, which represents the whole content of the InputStream

    **Throws:**

    - IOException - if something went wrong while reading from the underlying stream

    **Deprecated:**

:::warning
Use [readString()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readstring)
:::

***

### read()

- read(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Reads a single character from the stream. The method returns null if the end of the stream is reached.

    **Returns:**

    - a single character in a string, or null if the end of the stream is reached

***

### read(Number)

- ~~read(length: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)~~
  - : Reads multiple characters from the stream as string. The actual number of characters that were read can be
    determined from the length of the returned string. If the end of the stream is reached and no more characters can
    be read, the method exits with an exception.

    **Parameters:**

    - length - the number of characters to read.

    **Returns:**

    - a string whose length is controlled by the length parameter. The actual number of characters that were
      read can be determined from the length of the returned string.

    **Throws:**

    - an - exception if the stream is exhausted

    **Deprecated:**

:::warning
use [readN(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnnumber) instead which does not throw an exception if the stream is exhausted
:::

***

### readLine()

- readLine(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Reads the next line.

    **Returns:**

    - A String containing the contents of the line, not including any line termination characters, or null if
      the end of the stream has been reached.

***

### readLines()

- readLines(): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : The method reads the whole input stream, parses it and returns a list of strings.

    Using this method on large feeds is inherently unsafe and may lead to an out-of-memory condition. Instead use
    method [readLine()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readline) and process one line at a time.

    **Returns:**

    - a list of strings

***

### readN(Number)

- readN(n: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Reads n characters from the stream as string. The actual number of characters that were read can be determined
    from the length of the returned string. If the end of the stream is reached and no more characters can be read,
    the method returns null.

    **Parameters:**

    - n - the number of characters to read

    **Returns:**

    - a string whose maximum length is controlled by the n parameter, or null if the end of the stream is
      reached and no more characters can be read

***

### readString()

- readString(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : The method reads the whole input stream as one string and returns it.

    Using this method is unsafe if the length of the input stream is not known and may lead to an out-of-memory
    condition. Instead use method [readN(Number)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.io.Reader.md#readnnumber).

    **Returns:**

    - a string, which represents the whole content of the InputStream

    **Throws:**

    - IOException - if something went wrong while reading from the underlying stream

***

### ready()

- ready(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if this stream is ready to be read.

    **Returns:**

    - true guarantees that the stream is ready to read without waiting for input. A false
      response means that the stream may or may not block to wait for input. Note that returning
      false does not guarantee that the next read() will block.

***

### skip(Number)

- skip(n: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): void
  - : Skips the specified number of characters in the stream.

    **Parameters:**

    - n - the number of characters to skip.

***
