/lib/src/org/apache/http/message/BasicHeader.java

http://github.com/onedanshow/Screen-Courter · Java · 85 lines · 35 code · 11 blank · 39 comment · 5 complexity · 44072d38e043397440cc870c36f865da MD5 · raw file

  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. * ====================================================================
  20. *
  21. * This software consists of voluntary contributions made by many
  22. * individuals on behalf of the Apache Software Foundation. For more
  23. * information on the Apache Software Foundation, please see
  24. * <http://www.apache.org/>.
  25. *
  26. */
  27. package org.apache.http.message;
  28. import org.apache.http.Header;
  29. import org.apache.http.HeaderElement;
  30. import org.apache.http.ParseException;
  31. /**
  32. * Basic implementation of {@link Header}.
  33. *
  34. * @since 4.0
  35. */
  36. public class BasicHeader implements Header, Cloneable {
  37. private final String name;
  38. private final String value;
  39. /**
  40. * Constructor with name and value
  41. *
  42. * @param name the header name
  43. * @param value the header value
  44. */
  45. public BasicHeader(final String name, final String value) {
  46. super();
  47. if (name == null) {
  48. throw new IllegalArgumentException("Name may not be null");
  49. }
  50. this.name = name;
  51. this.value = value;
  52. }
  53. public String getName() {
  54. return this.name;
  55. }
  56. public String getValue() {
  57. return this.value;
  58. }
  59. public String toString() {
  60. // no need for non-default formatting in toString()
  61. return BasicLineFormatter.DEFAULT.formatHeader(null, this).toString();
  62. }
  63. public HeaderElement[] getElements() throws ParseException {
  64. if (this.value != null) {
  65. // result intentionally not cached, it's probably not used again
  66. return BasicHeaderValueParser.parseElements(this.value, null);
  67. } else {
  68. return new HeaderElement[] {};
  69. }
  70. }
  71. public Object clone() throws CloneNotSupportedException {
  72. return super.clone();
  73. }
  74. }