1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.tika.detect; 18 19 import java.io.IOException; 20 import java.io.InputStream; 21 22 import org.apache.tika.metadata.Metadata; 23 import org.apache.tika.mime.MediaType; 24 25 /** 26 * Content type detector. Implementations of this interface use various 27 * heuristics to detect the content type of a document based on given 28 * input metadata or the first few bytes of the document stream. 29 * 30 * @since Apache Tika 0.3 31 */ 32 public interface Detector { 33 34 /** 35 * Detects the content type of the given input document. Returns 36 * <code>application/octet-stream</code> if the type of the document 37 * can not be detected. 38 * <p> 39 * If the document input stream is not available, then the first 40 * argument may be <code>null</code>. Otherwise the detector may 41 * read bytes from the start of the stream to help in type detection. 42 * The given stream is guaranteed to support the 43 * {@link InputStream#markSupported() mark feature} and the detector 44 * is expected to {@link InputStream#mark(int) mark} the stream before 45 * reading any bytes from it, and to {@link InputStream#reset() reset} 46 * the stream before returning. The stream must not be closed by the 47 * detector. 48 * <p> 49 * The given input metadata is only read, not modified, by the detector. 50 * 51 * @param input document input stream, or <code>null</code> 52 * @param metadata input metadata for the document 53 * @return detected media type, or <code>application/octet-stream</code> 54 * @throws IOException if the document input stream could not be read 55 */ 56 MediaType detect(InputStream input, Metadata metadata) throws IOException; 57 58 }