2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.ext.jaxrs.internal.provider;
36
import java.io.BufferedReader;
37
import java.io.IOException;
38
import java.io.InputStream;
39
import java.lang.annotation.Annotation;
40
import java.lang.reflect.Type;
42
import javax.ws.rs.core.MediaType;
43
import javax.ws.rs.core.MultivaluedMap;
44
import javax.ws.rs.ext.MessageBodyReader;
45
import javax.ws.rs.ext.Provider;
47
import org.restlet.engine.io.IoUtils;
50
* This {@link MessageBodyReader} is used to read data from the network to a
51
* {@link BufferedReader}.
53
* @author Stephan Koops
57
public class BufferedReaderProvider implements
58
MessageBodyReader<BufferedReader> {
60
public boolean isReadable(Class<?> type, Type genericType,
61
Annotation[] annotations, MediaType mediaType) {
62
return BufferedReader.class.isAssignableFrom(type);
66
* @see MessageBodyReader#readFrom(Class, Type, MediaType, Annotation[],
67
* MultivaluedMap, InputStream)
69
public BufferedReader readFrom(Class<BufferedReader> type,
70
Type genericType, Annotation[] annotations, MediaType mediaType,
71
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
73
return new BufferedReader(ReaderProvider.getReader(entityStream),
74
IoUtils.getBufferSize());