1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.index.reader; 20 21 import java.io.IOException; 22 import java.io.OutputStream; 23 24 /** 25 * Maven Index writable {@link ResourceHandler}, is capable of saving resources too. Needed only if incremental index 26 * updates are wanted, to store the index state locally, and be able to calculate incremental diffs on next {@link 27 * IndexReader} invocation. Is used by single thread only. 28 * 29 * @see ResourceHandler 30 * @since 5.1.2 31 */ 32 public interface WritableResourceHandler extends ResourceHandler { 33 /** 34 * Resource that is writable. 35 */ 36 interface WritableResource extends Resource { 37 /** 38 * Returns the {@link OutputStream} stream of the resource, if exists, it will replace the existing content, or 39 * if not exists, the resource will be created. The stream should be closed by caller, otherwise resource leaks 40 * might be introduced. How and when content is written is left to implementation, but it is guaranteed that 41 * this method is called only once, and will be followed by {@link #close()} on the resource itself. 42 * Implementation does not have to be "read consistent", in a way to worry what subsequent {@link #read()} 43 * method will return, as mixed calls will not happen on same instance of resource. 44 */ 45 OutputStream write() throws IOException; 46 } 47 48 /** 49 * Returns the {@link WritableResource} with {@code name}. Returned locator should be handled as 50 * resource. 51 * 52 * @param name Resource name, guaranteed to be non-{@code null} and is FS and URL safe string. 53 */ 54 WritableResource locate(String name) throws IOException; 55 }