|
59 | 59 | Optionally, the <xref:System.Text.UTF32Encoding> object provides a byte order mark (BOM), which is an array of bytes that can be prefixed to the sequence of bytes resulting from the encoding process. If the preamble contains a byte order mark (BOM), it helps the decoder determine the byte order and the transformation format or UTF of a byte array.
|
60 | 60 |
|
61 | 61 | If the <xref:System.Text.UTF32Encoding> instance is configured to provide a BOM, you can retrieve it by calling the <xref:System.Text.UTF32Encoding.GetPreamble%2A> method; otherwise, the method returns an empty array. Note that, even if a <xref:System.Text.UTF32Encoding> object is configured for BOM support, you must include the BOM at the beginning of the encoded byte stream as appropriate; the encoding methods of the <xref:System.Text.UTF32Encoding> class do not do this automatically.
|
62 |
| - |
63 |
| - To enable error detection and to make the class instance more secure, you should instantiate a <xref:System.Text.UTF32Encoding> object by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidBytes` argument to `true`. With error detection, a method that detects an invalid sequence of characters or bytes throws an <xref:System.ArgumentException> exception. Without error detection, no exception is thrown, and the invalid sequence is generally ignored. |
| 62 | +
|
| 63 | +> [!CAUTION] |
| 64 | +> To enable error detection and to make the class instance more secure, you should instantiate a <xref:System.Text.UTF32Encoding> object by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidBytes` argument to `true`. With error detection, a method that detects an invalid sequence of characters or bytes throws an <xref:System.ArgumentException> exception. Without error detection, no exception is thrown, and the invalid sequence is generally ignored. |
64 | 65 |
|
65 | 66 | You can instantiate a <xref:System.Text.UTF32Encoding> object in a number of ways, depending on whether you want to it to provide a byte order mark (BOM), whether you want big-endian or little-endian encoding, and whether you want to enable error detection. The following table lists the <xref:System.Text.UTF32Encoding> constructors and the <xref:System.Text.Encoding> properties that return a <xref:System.Text.UnicodeEncoding> object.
|
66 | 67 |
|
|
151 | 152 | ## Remarks
|
152 | 153 | This constructor creates an instance that uses the little endian byte order, provides a Unicode byte order mark, and does not throw an exception when an invalid encoding is detected.
|
153 | 154 |
|
154 |
| -> [!NOTE] |
| 155 | +> [!CAUTION] |
155 | 156 | > For security reasons, you should enable error detection by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidCharacters` argument to `true`.
|
156 | 157 |
|
157 | 158 |
|
|
207 | 208 | ## Remarks
|
208 | 209 | This constructor creates an instance that does not throw an exception when an invalid encoding is detected.
|
209 | 210 |
|
210 |
| -> [!NOTE] |
| 211 | +> [!CAUTION] |
211 | 212 | > For security reasons, you should enable error detection by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidCharacters` argument to `true`.
|
212 | 213 |
|
213 |
| - |
214 |
| - |
215 | 214 | ## Examples
|
216 | 215 | The following example retrieves and displays the byte order mark for different <xref:System.Text.UTF32Encoding> instances.
|
217 | 216 |
|
|
267 | 266 | ## Remarks
|
268 | 267 | If `throwOnInvalidCharacters` is `true`, a method that detects an invalid byte sequence throws <xref:System.ArgumentException?displayProperty=nameWithType>. Otherwise, the method does not throw an exception, and the invalid sequence is ignored.
|
269 | 268 |
|
270 |
| -> [!NOTE] |
271 |
| -> For security reasons, you should enable error detection by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidCharacters` argument to `true`. |
272 |
| - |
273 |
| - |
| 269 | +> [!CAUTION] |
| 270 | +> For security reasons, you should enable error detection by calling the <xref:System.Text.UTF32Encoding.%23ctor%28System.Boolean%2CSystem.Boolean%2CSystem.Boolean%29> constructor and setting its `throwOnInvalidCharacters` argument to `true`. |
274 | 271 |
|
275 | 272 | ## Examples
|
276 | 273 | The following example demonstrates the behavior of <xref:System.Text.UTF32Encoding>, both with error detection enabled and without.
|
|
659 | 656 |
|
660 | 657 | Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application uses the <xref:System.Text.Decoder> or the <xref:System.Text.Encoder> provided by the <xref:System.Text.UTF32Encoding.GetDecoder%2A> method or the <xref:System.Text.UTF32Encoding.GetEncoder%2A> method, respectively.
|
661 | 658 |
|
662 |
| -> [!NOTE] |
| 659 | +> [!IMPORTANT] |
663 | 660 | > To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting a preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a preamble to the beginning of a sequence of encoded bytes.
|
664 | 661 |
|
665 | 662 | ]]></format>
|
|
745 | 742 |
|
746 | 743 | Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application uses the <xref:System.Text.Decoder> or the <xref:System.Text.Encoder> provided by the <xref:System.Text.UTF32Encoding.GetDecoder%2A> method or the <xref:System.Text.UTF32Encoding.GetEncoder%2A> method, respectively.
|
747 | 744 |
|
748 |
| -> [!NOTE] |
749 |
| -> To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting a preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a preamble to the beginning of a sequence of encoded bytes. |
750 |
| - |
751 |
| - |
| 745 | +> [!IMPORTANT] |
| 746 | +> To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting a preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a preamble to the beginning of a sequence of encoded bytes. |
752 | 747 |
|
753 | 748 | ## Examples
|
754 | 749 | The following example determines the number of bytes required to encode three characters from a character array, then encodes the characters and displays the resulting bytes.
|
|
847 | 842 |
|
848 | 843 | Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application uses the <xref:System.Text.Decoder> or the <xref:System.Text.Encoder> provided by the <xref:System.Text.UTF32Encoding.GetDecoder%2A> method or the <xref:System.Text.UTF32Encoding.GetEncoder%2A> method, respectively.
|
849 | 844 |
|
850 |
| -> [!NOTE] |
851 |
| -> To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting a preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a preamble to the beginning of a sequence of encoded bytes. |
852 |
| - |
853 |
| - |
| 845 | +> [!IMPORTANT] |
| 846 | +> To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting a preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a preamble to the beginning of a sequence of encoded bytes. |
854 | 847 |
|
855 | 848 | ## Examples
|
856 | 849 | The following example determines the number of bytes required to encode a string, then encodes the string and displays the resulting bytes.
|
|
1457 | 1450 | > [!NOTE]
|
1458 | 1451 | > `GetMaxByteCount(N)` is not necessarily the same value as `N* GetMaxByteCount(1)`.
|
1459 | 1452 |
|
1460 |
| - |
1461 |
| - |
1462 | 1453 | ## Examples
|
1463 | 1454 | The following example determines the number of bytes required to encode a string, then encodes the string and displays the resulting bytes.
|
1464 | 1455 |
|
|
1533 | 1524 | > [!NOTE]
|
1534 | 1525 | > `GetMaxCharCount(N)` is not necessarily the same value as `N* GetMaxCharCount(1)`.
|
1535 | 1526 |
|
1536 |
| - |
1537 |
| - |
1538 | 1527 | ## Examples
|
1539 | 1528 | The following example encodes a string into an array of bytes, and then decodes the bytes into an array of characters.
|
1540 | 1529 |
|
|
1618 | 1607 |
|
1619 | 1608 | For more information on byte order and the byte order mark, see The Unicode Standard at the [Unicode home page](https://go.microsoft.com/fwlink/?LinkId=37123).
|
1620 | 1609 |
|
1621 |
| -> [!CAUTION] |
| 1610 | +> [!IMPORTANT] |
1622 | 1611 | > To ensure that the encoded bytes are decoded properly, you should prefix encoded bytes with a preamble. Note that the <xref:System.Text.UTF32Encoding.GetBytes%2A> method does not prepend a BOM to a sequence of encoded bytes; supplying a BOM at the beginning of an appropriate byte stream is the developer's responsibility.
|
1623 | 1612 |
|
1624 |
| - |
1625 |
| - |
1626 | 1613 | ## Examples
|
1627 | 1614 | The following code example retrieves and displays the byte order mark for different <xref:System.Text.UTF32Encoding> instances.
|
1628 | 1615 |
|
|
0 commit comments