001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * 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, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.spring.converter;
019
020 import org.apache.camel.Converter;
021 import org.springframework.core.io.ByteArrayResource;
022 import org.springframework.core.io.FileSystemResource;
023 import org.springframework.core.io.Resource;
024 import org.springframework.core.io.UrlResource;
025
026 import java.io.File;
027 import java.io.IOException;
028 import java.io.InputStream;
029 import java.net.URL;
030
031 /**
032 * Some Spring based
033 * <a href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>
034 *
035 * @version $Revision: 524222 $
036 */
037 @Converter
038 public class ResourceConverter {
039 @Converter
040 public static InputStream toInputStream(Resource resource) throws IOException {
041 return resource.getInputStream();
042 }
043
044 @Converter
045 public static File toFile(Resource resource) throws IOException {
046 return resource.getFile();
047 }
048
049 @Converter
050 public static URL toUrl(Resource resource) throws IOException {
051 return resource.getURL();
052 }
053
054 @Converter
055 public static UrlResource toResource(String uri) throws IOException {
056 return new UrlResource(uri);
057 }
058
059 @Converter
060 public static UrlResource toResource(URL uri) throws IOException {
061 return new UrlResource(uri);
062 }
063
064 @Converter
065 public static FileSystemResource toResource(File file) throws IOException {
066 return new FileSystemResource(file);
067 }
068
069 @Converter
070 public static ByteArrayResource toResource(byte[] data) throws IOException {
071 return new ByteArrayResource(data);
072 }
073 }