001/****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one   *
003 * or more contributor license agreements.  See the NOTICE file *
004 * distributed with this work for additional information        *
005 * regarding copyright ownership.  The ASF licenses this file   *
006 * to you under the Apache License, Version 2.0 (the            *
007 * "License"); you may not use this file except in compliance   *
008 * with the License.  You may obtain a copy of the License at   *
009 *                                                              *
010 *   http://www.apache.org/licenses/LICENSE-2.0                 *
011 *                                                              *
012 * Unless required by applicable law or agreed to in writing,   *
013 * software distributed under the License is distributed on an  *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015 * KIND, either express or implied.  See the License for the    *
016 * specific language governing permissions and limitations      *
017 * under the License.                                           *
018 ****************************************************************/
019
020package org.apache.james.mime4j.stream;
021
022import java.util.ArrayList;
023import java.util.List;
024
025/**
026 * This class represents a field's body consisting of a textual value and a number of optional
027 * name / value parameters separated with semicolon.
028 * <pre>
029 * value; param1 = value1; param2 = "value2";
030 * </pre>
031 */
032public final class RawBody {
033
034    private final String value;
035    private final List<NameValuePair> params;
036
037    RawBody(final String value, final List<NameValuePair> params) {
038        if (value == null) {
039            throw new IllegalArgumentException("Field value not be null");
040        }
041        this.value = value;
042        this.params = params != null ? params : new ArrayList<NameValuePair>();
043    }
044
045    public String getValue() {
046        return this.value;
047    }
048
049    public List<NameValuePair> getParams() {
050        return new ArrayList<NameValuePair>(this.params);
051    }
052
053    @Override
054    public String toString() {
055        StringBuilder buf = new StringBuilder();
056        buf.append(this.value);
057        buf.append("; ");
058        for (NameValuePair param: this.params) {
059            buf.append("; ");
060            buf.append(param);
061        }
062        return buf.toString();
063    }
064
065}