001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package core.tut.pori.http.parameters;
017
018import java.io.InputStream;
019import java.util.List;
020
021/**
022 * Input stream parameter for reading data as a stream.
023 * 
024 * This only supports data received as an InputStream (e.g. http body)
025 *
026 */
027public class InputStreamParameter extends HTTPParameter{
028  /** Default parameter name to use for a body parameter. If the parameter is defined as being a body parameter, the name has no effect. */
029  public static final String PARAMETER_DEFAULT_NAME = "body";
030  private InputStream _stream = null;
031
032  @Override
033  public void initialize(List<String> parameterValues) throws UnsupportedOperationException {
034    throw new UnsupportedOperationException("Parameter value list not accepted for this class.");
035  }
036
037  @Override
038  public void initialize(String parameterValue) throws UnsupportedOperationException {
039    throw new UnsupportedOperationException("Parameter value not accepted for this class.");
040  }
041
042  @Override
043  public boolean hasValues() {
044    return (_stream != null);
045  }
046
047  @Override
048  public void initialize(InputStream stream) {
049    _stream = stream;
050  }
051  
052  /**
053   *  Note: if this class is used with default \@HttpServiceMethod annotation designated as a body parameter,
054   *  you do not need to close the stream manually, it will be automatically closed when the connection disconnects.
055   * 
056   * @return the input stream
057   */
058  @Override
059  public InputStream getValue(){
060    return _stream;
061  }
062}