Encoder.java 2.5 KB
Newer Older
S
Sebastien Deleuze 已提交
1
/*
2
 * Copyright 2002-2016 the original author or authors.
S
Sebastien Deleuze 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
package org.springframework.core.codec;
S
Sebastien Deleuze 已提交
18 19 20 21

import java.util.List;

import org.reactivestreams.Publisher;
22
import reactor.core.publisher.Flux;
S
Sebastien Deleuze 已提交
23 24

import org.springframework.core.ResolvableType;
25
import org.springframework.core.io.buffer.DataBuffer;
26
import org.springframework.core.io.buffer.DataBufferFactory;
S
Sebastien Deleuze 已提交
27 28 29
import org.springframework.util.MimeType;

/**
R
Rossen Stoyanchev 已提交
30 31
 * Strategy to encode a stream of Objects of type {@code <T>} into an output
 * stream of bytes.
S
Sebastien Deleuze 已提交
32 33
 *
 * @author Sebastien Deleuze
R
Rossen Stoyanchev 已提交
34
 * @author Rossen Stoyanchev
35
 * @since 5.0
36
 * @param <T> the type of elements in the input stream
S
Sebastien Deleuze 已提交
37 38 39 40
 */
public interface Encoder<T> {

	/**
R
Rossen Stoyanchev 已提交
41 42 43 44 45 46
	 * Whether the encoder supports the given source element type and the MIME
	 * type for the output stream.
	 * @param elementType the type of elements in the source stream
	 * @param mimeType the MIME type for the output stream
	 * @param hints additional information about how to do encode, optional
	 * @return {@code true} if supported, {@code false} otherwise
S
Sebastien Deleuze 已提交
47
	 */
R
Rossen Stoyanchev 已提交
48
	boolean canEncode(ResolvableType elementType, MimeType mimeType, Object... hints);
S
Sebastien Deleuze 已提交
49 50

	/**
R
Rossen Stoyanchev 已提交
51 52 53 54 55 56 57 58 59
	 * Encode a stream of Objects of type {@code T} into a {@link DataBuffer}
	 * output stream.
	 * @param inputStream the input stream of Objects to encode
	 * @param bufferFactory for creating output stream {@code DataBuffer}'s
	 * @param elementType the expected type of elements in the input stream;
	 * this type must have been previously passed to the {@link #canEncode}
	 * method and it must have returned {@code true}.
	 * @param mimeType the MIME type for the output stream
	 * @param hints additional information about how to do encode, optional
S
Sebastien Deleuze 已提交
60 61
	 * @return the output stream
	 */
R
Rossen Stoyanchev 已提交
62 63
	Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory,
			ResolvableType elementType, MimeType mimeType, Object... hints);
S
Sebastien Deleuze 已提交
64 65

	/**
R
Polish  
Rossen Stoyanchev 已提交
66
	 * Return the list of mime types this encoder supports.
S
Sebastien Deleuze 已提交
67
	 */
68
	List<MimeType> getEncodableMimeTypes();
S
Sebastien Deleuze 已提交
69 70

}