001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.jhc;
018
019 import java.io.IOException;
020 import java.io.InputStream;
021 import java.io.UnsupportedEncodingException;
022
023 import org.apache.camel.Converter;
024 import org.apache.http.HttpEntity;
025 import org.apache.http.entity.InputStreamEntity;
026 import org.apache.http.entity.StringEntity;
027 import org.apache.http.util.EntityUtils;
028
029 /**
030 * Created by IntelliJ IDEA.
031 * User: gnodet
032 * Date: Sep 10, 2007
033 * Time: 8:26:44 AM
034 * To change this template use File | Settings | File Templates.
035 */
036 @Converter
037 public final class JhcConverter {
038
039 private JhcConverter() {
040 }
041
042 @Converter
043 public static InputStream toInputStream(HttpEntity entity) throws IOException {
044 return entity.getContent();
045 }
046
047 @Converter
048 public static byte[] toByteArray(HttpEntity entity) throws IOException {
049 return EntityUtils.toByteArray(entity);
050 }
051
052 @Converter
053 public static String toString(HttpEntity entity) throws IOException {
054 return EntityUtils.toString(entity);
055 }
056
057 @Converter
058 public static HttpEntity toEntity(InputStream is) {
059 return new InputStreamEntity(is, -1);
060 }
061
062 @Converter
063 public static HttpEntity toEntity(String str) throws UnsupportedEncodingException {
064 return new StringEntity(str);
065 }
066 }