Web messages format document number что это
MessageFormat takes a set of objects, formats them, then inserts the formatted strings into the pattern at the appropriate places.
Note: MessageFormat differs from the other Format classes in that you create a MessageFormat object with one of its constructors (not with a getInstance style factory method). The factory methods aren’t necessary because MessageFormat itself doesn’t implement locale specific behavior. Any locale specific behavior is defined by the pattern that you provide as well as the subformats used for inserted arguments.
Patterns and Their Interpretation
Usage Information
Here are some examples of usage. In real internationalized programs, the message format pattern and other static strings will, of course, be obtained from resource bundles. Other parameters will be dynamically determined at runtime.
The following example creates a MessageFormat instance that can be used repeatedly:
For more sophisticated patterns, you can use a ChoiceFormat to produce correct forms for singular and plural:
You can create the ChoiceFormat programmatically, as in the above example, or by using a pattern. See ChoiceFormat for more information.
When a single argument is parsed more than once in the string, the last match will be the final result of the parsing. For example,
Likewise, parsing with a MessageFormat object using patterns containing multiple occurrences of the same argument would return the last match. For example,
Synchronization
Message formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
Nested Class Summary
| Modifier and Type | Class and Description |
|---|---|
| static class | MessageFormat.Field |
Constructor Summary
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| void | applyPattern (String pattern) |
Methods inherited from class java.text.Format
Methods inherited from class java.lang.Object
Constructor Detail
MessageFormat
MessageFormat
Method Detail
setLocale
getLocale
applyPattern
toPattern
setFormatsByArgumentIndex
If an argument index is used for more than one format element in the pattern string, then the corresponding new format is used for all such format elements. If an argument index is not used for any format element in the pattern string, then the corresponding new format is ignored. If fewer formats are provided than needed, then only the formats for argument indices less than newFormats.length are replaced.
setFormats
If more formats are provided than needed by the pattern string, the remaining ones are ignored. If fewer formats are provided than needed, then only the first newFormats.length formats are replaced.
Since the order of format elements in a pattern string often changes during localization, it is generally better to use the setFormatsByArgumentIndex method, which assumes an order of formats corresponding to the order of elements in the arguments array passed to the format methods or the result array returned by the parse methods.
setFormatByArgumentIndex
If the argument index is used for more than one format element in the pattern string, then the new format is used for all such format elements. If the argument index is not used for any format element in the pattern string, then the new format is ignored.
setFormat
Since the order of format elements in a pattern string often changes during localization, it is generally better to use the setFormatByArgumentIndex method, which accesses format elements based on the argument index they specify.
getFormatsByArgumentIndex
If an argument index is used for more than one format element in the pattern string, then the format used for the last such format element is returned in the array. If an argument index is not used for any format element in the pattern string, then null is returned in the array.
getFormats
Since the order of format elements in a pattern string often changes during localization, it’s generally better to use the getFormatsByArgumentIndex method, which assumes an order of formats corresponding to the order of elements in the arguments array passed to the format methods or the result array returned by the parse methods.
format
format
format
formatToCharacterIterator
The text of the returned AttributedCharacterIterator is the same that would be returned by
parse
parse
See the parse(String, ParsePosition) method for more information on message parsing.
parseObject
See the parse(String, ParsePosition) method for more information on message parsing.
Формат часто используется вместе с RTMP Adobe для установления соединений и команд управления доставкой потокового мультимедиа. В этом случае данные AMF инкапсулируются в блок, который имеет заголовок, который определяет такие вещи, как длина и тип сообщения (будь то «эхо-запрос», «команда» или мультимедийные данные).
СОДЕРЖАНИЕ
Анализ формата
AMF был представлен в Flash Player 6, и эта версия называется AMF0. Он оставался неизменным до выпуска Flash Player 9 и ActionScript 3.0, когда новые типы данных и языковые функции потребовали обновления под названием AMF3. В Flash Player 10 добавлены векторные и словарные типы данных, задокументированные в пересмотренной спецификации от января 2013 года.
Adobe Systems опубликовала спецификацию протокола двоичных данных AMF в декабре 2007 года и объявила, что поддержит сообщество разработчиков, чтобы сделать этот протокол доступным для всех основных серверных платформ.
Автономный пакет AMF
| Длина | Имя | Тип | По умолчанию |
|---|---|---|---|
| 16 бит | версия | uimsbf | 0 или 3 |
| 16 бит | количество заголовков | uimsbf | 0 |
| количество заголовков * 56 + бит | заголовок-тип-структура | двоичный | свободная форма |
| 16 бит | счетчик сообщений | uimsbf | 1 |
| количество сообщений * 64 + бит | структура типа сообщения | двоичный | свободная форма |
| Длина | Имя | Тип | По умолчанию |
|---|---|---|---|
| 16 бит | заголовок-имя-длина | uimsbf | 0 |
| длина имени-заголовка * 8 бит | заголовок-имя-строка | UTF-8 | пустой |
| 8 бит | должен понимать | uimsbf | 0 |
| 32 бит | длина заголовка | simsbf | Переменная |
| длина заголовка * 8 бит | AMF0 или AMF3 | двоичный | свободная форма |
| Длина | Имя | Тип | По умолчанию |
|---|---|---|---|
| 16 бит | target-uri-length | uimsbf | Переменная |
| длина целевого URI * 8 бит | target-uri-string | UTF-8 | Переменная |
| 16 бит | длина ответа-uri | uimsbf | 2 |
| длина ответа-URI * 8 бит | ответ-URI-строка | UTF-8 | «/ 1» |
| 32 бит | длина сообщения | simsbf | Переменная |
| длина сообщения * 8 бит | AMF0 или AMF3 | двоичный | свободная форма |
uimsbf: целое число без знака, сначала старший бит
simsbf: целое число со знаком, сначала старший бит
Формат определяет различные типы данных, которые можно использовать для кодирования данных. Adobe заявляет, что AMF в основном используется для представления графов объектов, которые включают именованные свойства в форме пар ключ-значение, где ключи закодированы как строки, а значения могут быть любого типа данных, таких как строки или числа, а также массивы и другие объекты. XML поддерживается как собственный тип. Каждый тип обозначается одним байтом, предшествующим фактическим данным. Значения этого байта следующие (для AMF0):
Объекты AMF начинаются с (0x03), за которым следует набор пар ключ-значение, и заканчиваются (0x09) в качестве значения (которому предшествует 0x00 0x00 в качестве пустой ключевой записи). Ключи кодируются как строки с подразумеваемым байтом (0x02) ‘определение типа’ (не включаемым в сообщение). Значения могут быть любого типа, включая другие объекты, и таким образом можно сериализовать целые графы объектов. И ключам объекта, и строкам предшествуют два байта, обозначающие их длину в байтах. Это означает, что строкам предшествуют три байта, включая байт типа 0x02. Нулевые типы содержат только свое определение типа (0x05). Числа кодируются как числа с плавающей запятой двойной точности и состоят из восьми байтов.
В качестве примера при кодировании объекта ниже в коде actionscript 3.
Данные, хранящиеся в ByteArray:
| Шестнадцатеричный код | ASCII | |||||||
|---|---|---|---|---|---|---|---|---|
| 03 00 04 6e 61 6d 65 02 00 04 4d 69 6b 65 00 03 61 67 65 00 40 3e 00 00 00 00 00 00 00 05 61 6c 69 61 73 02 00 04 4d 69 6b 65 00 00 09 |
| Modifier and Type | Class and Description |
|---|---|
| static class | MessageFormat.Field |
Constructor Summary
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| void | applyPattern(String pattern) |
Methods inherited from class java.text.Format
Methods inherited from class java.lang.Object
Constructor Detail
MessageFormat
MessageFormat
Method Detail
setLocale
getLocale
applyPattern
toPattern
setFormatsByArgumentIndex
If an argument index is used for more than one format element in the pattern string, then the corresponding new format is used for all such format elements. If an argument index is not used for any format element in the pattern string, then the corresponding new format is ignored. If fewer formats are provided than needed, then only the formats for argument indices less than newFormats.length are replaced.
setFormats
If more formats are provided than needed by the pattern string, the remaining ones are ignored. If fewer formats are provided than needed, then only the first newFormats.length formats are replaced.
Since the order of format elements in a pattern string often changes during localization, it is generally better to use the setFormatsByArgumentIndex method, which assumes an order of formats corresponding to the order of elements in the arguments array passed to the format methods or the result array returned by the parse methods.
setFormatByArgumentIndex
If the argument index is used for more than one format element in the pattern string, then the new format is used for all such format elements. If the argument index is not used for any format element in the pattern string, then the new format is ignored.
setFormat
Since the order of format elements in a pattern string often changes during localization, it is generally better to use the setFormatByArgumentIndex method, which accesses format elements based on the argument index they specify.
getFormatsByArgumentIndex
If an argument index is used for more than one format element in the pattern string, then the format used for the last such format element is returned in the array. If an argument index is not used for any format element in the pattern string, then null is returned in the array.
getFormats
Since the order of format elements in a pattern string often changes during localization, it’s generally better to use the getFormatsByArgumentIndex method, which assumes an order of formats corresponding to the order of elements in the arguments array passed to the format methods or the result array returned by the parse methods.
format
The text substituted for the individual format elements is derived from the current subformat of the format element and the arguments element at the format element’s argument index as indicated by the first matching line of the following table. An argument is unavailable if arguments is null or has fewer than argumentIndex+1 elements.
format
format
formatToCharacterIterator
The text of the returned AttributedCharacterIterator is the same that would be returned by
parse
parse
See the parse(String, ParsePosition) method for more information on message parsing.
parseObject
See the parse(String, ParsePosition) method for more information on message parsing.