1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.client.api; 20 21 import java.nio.ByteBuffer; 22 23 /** 24 * {@link ContentProvider} provides a source of request content. 25 * <p/> 26 * Implementations should return an {@link Iterator} over the request content. 27 * If the request content comes from a source that needs to be closed (for 28 * example, an {@link InputStream}), then the iterator implementation class 29 * must implement {@link Closeable} and will be closed when the request is 30 * completed (either successfully or failed). 31 * <p/> 32 * Applications should rely on utility classes such as {@link ByteBufferContentProvider} 33 * or {@link PathContentProvider}. 34 */ 35 public interface ContentProvider extends Iterable<ByteBuffer> 36 { 37 /** 38 * @return the content length, if known, or -1 if the content length is unknown 39 */ 40 long getLength(); 41 42 /** 43 * An extension of {@link ContentProvider} that provides a content type string 44 * to be used as a {@code Content-Type} HTTP header in requests. 45 */ 46 public interface Typed extends ContentProvider 47 { 48 /** 49 * @return the content type string such as "application/octet-stream" or 50 * "application/json;charset=UTF8", or null if no content type must be set 51 */ 52 public String getContentType(); 53 } 54 }