001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.http.codec.protobuf;
018
019import java.util.Arrays;
020import java.util.Collections;
021import java.util.List;
022
023import org.springframework.lang.Nullable;
024import org.springframework.util.MimeType;
025
026/**
027 * Base class providing support methods for Protobuf encoding and decoding.
028 *
029 * @author Sebastien Deleuze
030 * @since 5.1
031 */
032public abstract class ProtobufCodecSupport {
033
034        static final List<MimeType> MIME_TYPES = Collections.unmodifiableList(
035                        Arrays.asList(
036                                        new MimeType("application", "x-protobuf"),
037                                        new MimeType("application", "octet-stream")));
038
039        static final String DELIMITED_KEY = "delimited";
040
041        static final String DELIMITED_VALUE = "true";
042
043
044        protected boolean supportsMimeType(@Nullable MimeType mimeType) {
045                return (mimeType == null || MIME_TYPES.stream().anyMatch(m -> m.isCompatibleWith(mimeType)));
046        }
047
048        protected List<MimeType> getMimeTypes() {
049                return MIME_TYPES;
050        }
051
052}