View Javadoc
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.OutputStream;
25  
26  /**
27   * Maven 2 Index writable {@link ResourceHandler}, is capable of saving resources too. Needed only if incremental index
28   * updates are wanted, to store the index state locally, and be able to calculate incremental diffs on next {@link
29   * IndexReader} invocation. Is used by single thread only.
30   *
31   * @see ResourceHandler
32   * @since 5.1.2
33   */
34  public interface WritableResourceHandler
35      extends ResourceHandler
36  {
37      /**
38       * Resource that is writable.
39       */
40      interface WritableResource
41          extends Resource, Closeable
42      {
43          /**
44           * Returns the {@link OutputStream} stream of the resource, if exists, it will replace the existing content, or
45           * if not exists, the resource will be created. The stream should be closed by caller, otherwise resource leaks
46           * might be introduced. How and when content is written is left to implementation, but it is guaranteed that
47           * this method is called only once, and will be followed by {@link #close()} on the resource itself.
48           * Implementation does not have to be "read consistent", in a way to worry what subsequent {@link #read()}
49           * method will return, as mixed calls will not happen on same instance of resource.
50           */
51          OutputStream write()
52              throws IOException;
53      }
54  
55      /**
56       * Returns the {@link WritableResource} with {@code name}. Returned locator should be handled as
57       * resource, is {@link Closeable}.
58       *
59       * @param name Resource name, guaranteed to be non-{@code null} and is FS and URL safe string.
60       */
61      WritableResource locate( String name )
62          throws IOException;
63  }