Creates or updates audio format using payload number and text format description.

@param payload the payload number of the format.
@param description text description of the format
@return format object
976353
private RTPFormat createAudioFormat(int payload, Text description) {
        Iterator<Text> it = description.split('/').iterator();

        //encoding name
        Text token = it.next();
        token.trim();
        EncodingName name = new EncodingName(token);

        //clock rate
        //TODO : convert to sample rate
        token = it.next();
        token.trim();
        int clockRate = token.toInteger();

        //channels
        int channels = 1;
        if (it.hasNext()) {
            token = it.next();
            token.trim();
            channels = token.toInteger();
        }

        RTPFormat rtpFormat = getFormat(payload);
        if (rtpFormat == null) {
            formats.add(new RTPFormat(payload, FormatFactory.createAudioFormat(name, clockRate, -1, channels)));
        } else {
            //TODO: recreate format anyway. it is illegal to use clock rate as sample rate
            ((AudioFormat)rtpFormat.getFormat()).setName(name);
            ((AudioFormat)rtpFormat.getFormat()).setSampleRate(clockRate);
            ((AudioFormat)rtpFormat.getFormat()).setChannels(channels);
        }

        return rtpFormat;
    }
1328957
private RTPFormat createApplicationFormat(int payload, Text description) {
        Iterator<Text> it = description.split('/').iterator();

        //encoding name
        Text token = it.next();
        token.trim();
        EncodingName name = new EncodingName(token);

        //clock rate
        token = it.next();
        token.trim();

        RTPFormat rtpFormat = getFormat(payload);
        if (rtpFormat == null) {
            formats.add(new RTPFormat(payload, FormatFactory.createApplicationFormat(name)));
        } else {
            ((ApplicationFormat)rtpFormat.getFormat()).setName(name);
        }
        return rtpFormat;
    }
568179
public void setCreativeFormat(com.google.api.ads.admanager.axis.v201902.RichMediaStudioCreativeFormat creativeFormat) {
        this.creativeFormat = creativeFormat;
    }
292472
private static ByteBuffer convertAudioBytes(AudioFormat format, byte[] audio_bytes, boolean two_bytes_data) {
		ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
		dest.order(ByteOrder.nativeOrder());
		ByteBuffer src = ByteBuffer.wrap(audio_bytes);
		src.order(ByteOrder.BIG_ENDIAN);
		if (two_bytes_data) {
			ShortBuffer dest_short = dest.asShortBuffer();
			ShortBuffer src_short = src.asShortBuffer();
			while (src_short.hasRemaining())
				dest_short.put(src_short.get());
		} else {
			while (src.hasRemaining()) {
				byte b = src.get();
				if (format.getEncoding() == Encoding.PCM_SIGNED) {
					b = (byte) (b + 127);
				}
				dest.put(b);
			}
		}
		dest.rewind();
		return dest;
	}
344005
public FormatStringBuffer format(String str) {

        if (str == null) str = "<NULL>";

        Format fmt = getFormat();

        if (fmt.type != STRING) throw new IllegalArgumentException("Expected a String format");

        int len = str.length();
        if (fmt.precision != -1 && len > fmt.precision) len = fmt.precision;

        if ((fmt.flags & LEFT) != LEFT) while (len < fmt.fieldWidth--)
            buffer.append(' ');

        for (int i = 0; i < len; ++i)
            buffer.append(str.charAt(i));

        while (len < fmt.fieldWidth--)
            buffer.append(' ');

        return this;
    }
538828
public void setDescription(final String DESCRIPTION) {
        if (null == description) {
            _description = DESCRIPTION;
            fireTileEvent(VISIBILITY_EVENT);
            fireTileEvent(REDRAW_EVENT);
        } else {
            description.set(DESCRIPTION);
        }
    }
809603
@Override
    public StringBuffer format(java.math.BigDecimal number, StringBuffer result,
                               FieldPosition fieldPosition) {
        return format(number, result, fieldPosition, false);
    }
280125
public static <Payload> Message<Payload> create(Payload payload) {
    return new Message<>(payload, HashTreePMap.empty());
  }
628509
protected void setDescriptor(Text line) throws ParseException {
        line.trim();
        try {
            //split using equal sign
            Iterator<Text> it = line.split('=').iterator();

            //skip first token (m)
            Text t = it.next();

            //select second token (media_type port profile formats)
            t = it.next();

            //split using white spaces
            it = t.split(' ').iterator();

            //media type
            mediaType = it.next();
            mediaType.trim();

            //port
            t = it.next();
            t.trim();
            port = t.toInteger();

            //profile
            profile = it.next();
            profile.trim();

            //formats
            while (it.hasNext()) {
                t = it.next();
                t.trim();

                RTPFormat fmt = AVProfile.getFormat(t.toInteger(),mediaType);
                if (fmt != null && !formats.contains(fmt.getFormat())) {
                    formats.add(fmt.clone());
                }
            }
        } catch (Exception e) {
            throw new ParseException("Could not parse media descriptor", 0);
        }
    }
431885
public void setDescription(java.util.Collection<StringFilter> description) {
        if (description == null) {
            this.description = null;
            return;
        }

        this.description = new java.util.ArrayList<StringFilter>(description);
    }
1206998
private void addRtpMapAttribute(Text attribute) throws IllegalArgumentException {
    	if (!attribute.startsWith(SessionDescription.RTPMAP)) {
    		throw new IllegalArgumentException("Not a valid RTP MAP attribute"+attribute);
    	}

    	Iterator<Text> it = attribute.split(':').iterator();
    	Text token = it.next();
    	
        token = it.next();
        token.trim();

        //payload and format descriptor
        it = token.split(' ').iterator();

        //payload
        token = it.next();
        token.trim();

        int payload = token.toInteger();

        //format descriptor
        token = it.next();
        token.trim();

        createFormat(payload, token);
    }
136771
public void addDescription(String description, boolean unicode) {
        put(PdfName.DESC, new PdfString(description, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING));
    }
1218698
public String getFormattedOption(int offset, int descriptionStart, int width) {
        StringBuilder sb = new StringBuilder();
        if(required && ansiMode)
            sb.append(ANSI.BOLD);
        if(offset > 0)
            sb.append(String.format("%" + offset+ "s", ""));
        if(shortName != null)
            sb.append("-").append(shortName);
        if(name != null && name.length() > 0) {
            if(shortName != null)
                sb.append(", ");
            sb.append("--").append(name);
        }
        if(argument != null && argument.length() > 0) {
            sb.append("=<").append(argument).append(">");
        }
        if(required && ansiMode)
            sb.append(ANSI.BOLD_OFF);
        if(description != null && description.length() > 0) {
            //int descOffset = descriptionStart - sb.length();
            int descOffset = descriptionStart - getFormattedLength() - offset;
            if(descOffset > 0)
                sb.append(String.format("%"+descOffset+"s", ""));
            else
                sb.append(" ");

            sb.append(description);
        }

        return sb.toString();
    }
965050
public List<PayloadType> getAudioPayloadTypesList() {
        ArrayList<PayloadType> result = new ArrayList<>();
        Iterator<PayloadType> jinglePtsIter = getPayloadTypes();

        while (jinglePtsIter.hasNext()) {
            PayloadType jpt = jinglePtsIter.next();
            if (jpt instanceof PayloadType.Audio) {
                PayloadType.Audio jpta = (PayloadType.Audio) jpt;
                result.add(jpta);
            }
        }

        return result;
    }
769651
public static String parseMessagePayload(Element payloadElement) {
        if (payloadElement == null) {
            return "";
        }
        
        try {
            Document payload = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            payload.appendChild(payload.importNode(payloadElement, true));

            String payloadData = XMLUtils.serialize(payload);
            // temporary quickfix for unwanted testcase namespace in target payload
            payloadData = payloadData.replaceAll(" xmlns=\\\"http://www.citrusframework.org/schema/testcase\\\"", "");
            return payloadData.trim();
        } catch (DOMException e) {
            throw new CitrusRuntimeException("Error while constructing message payload", e);
        } catch (ParserConfigurationException e) {
            throw new CitrusRuntimeException("Error while constructing message payload", e);
        }
    }
781419
@Programmatic
    public ApplicationSetting newString(
            final String key,
            final String description,
            final String value) {
        return newSetting(key, description, SettingType.STRING, value);
    }
1142795
public static InputStreamResource buildInputStreamResourceFrom(final String value, final String description) {
        val reader = new StringReader(value);
        val is = new ReaderInputStream(reader, StandardCharsets.UTF_8);
        return new InputStreamResource(is, description);
    }