AbstractDecoder.java 1.8 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 22

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

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

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

/**
 * @author Sebastien Deleuze
32
 * @author Arjen Poutsma
S
Sebastien Deleuze 已提交
33 34 35
 */
public abstract class AbstractDecoder<T> implements Decoder<T> {

36
	private List<MimeType> decodableMimeTypes = Collections.emptyList();
S
Sebastien Deleuze 已提交
37

38
	protected AbstractDecoder(MimeType... supportedMimeTypes) {
39
		this.decodableMimeTypes = Arrays.asList(supportedMimeTypes);
S
Sebastien Deleuze 已提交
40 41
	}

R
Polish  
Rossen Stoyanchev 已提交
42 43

	@Override
44 45
	public List<MimeType> getDecodableMimeTypes() {
		return this.decodableMimeTypes;
R
Polish  
Rossen Stoyanchev 已提交
46 47
	}

S
Sebastien Deleuze 已提交
48
	@Override
R
Rossen Stoyanchev 已提交
49
	public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object... hints) {
50 51 52
		if (mimeType == null) {
			return true;
		}
53 54
		return this.decodableMimeTypes.stream().
				anyMatch(mt -> mt.isCompatibleWith(mimeType));
S
Sebastien Deleuze 已提交
55 56
	}

S
Sebastien Deleuze 已提交
57 58 59 60
	@Override
	public Mono<T> decodeOne(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Object... hints) {
		throw new UnsupportedOperationException();
	}
S
Sebastien Deleuze 已提交
61
}