1 package org.apache.maven.index.reader;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.Closeable;
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 /**
27 * Maven 2 Index resource abstraction, that should be handled as a resource (is {@link Closeable}. That means, that
28 * implementations could perform any extra activity as FS locking or so (if uses FS as backing store). Is used by single
29 * thread only.
30 *
31 * @since 5.1.2
32 */
33 public interface ResourceHandler
34 extends Closeable
35 {
36 /**
37 * Handle of content.
38 */
39 interface Resource
40 {
41 /**
42 * Returns the {@link InputStream} stream of the resource, if exists, {@code null} otherwise. The stream should
43 * be closed by caller, otherwise resource leaks might be introduced.
44 */
45 InputStream read()
46 throws IOException;
47 }
48
49 /**
50 * Returns the {@link Resource} with {@code name}, non {@code null}.
51 *
52 * @param name Resource name, guaranteed to be non-{@code null} and is FS and URL safe string.
53 */
54 Resource locate( String name )
55 throws IOException;
56 }