1 package org.apache.archiva.repository.content;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.nio.channels.ReadableByteChannel;
26 import java.nio.channels.WritableByteChannel;
27 import java.nio.file.Path;
28 import java.time.Instant;
29 import java.util.List;
30 import java.util.function.Consumer;
33 * A instance of this interface represents information about an specific asset in a repository.
34 * The asset may be an real artifact, a directory, or a virtual asset.
36 * Each asset has a unique path relative to the repository.
38 * The implementation may read the data directly from the filesystem or underlying storage implementation.
40 * @author Martin Stockhammer <martin_s@apache.org>
42 public interface StorageAsset
46 * Returns the storage this asset belongs to.
49 RepositoryStorage getStorage();
52 * Returns the complete path relative to the repository to the given asset.
54 * @return A path starting with '/' that uniquely identifies the asset in the repository.
59 * Returns the name of the asset. It may be just the filename.
65 * Returns the time of the last modification.
69 Instant getModificationTime();
72 * Returns true, if this asset is a container type and contains further child assets.
75 boolean isContainer();
78 * List the child assets.
80 * @return The list of children. If there are no children and if the asset is not a container, a empty list will be returned.
82 List<StorageAsset> list();
85 * The size in bytes of the asset. If the asset does not have a size, -1 should be returned.
87 * @return The size if the asset has a size, otherwise -1
92 * Returns the input stream of the artifact content.
93 * It will throw a IOException, if the stream could not be created.
94 * Implementations should create a new stream instance for each invocation and make sure that the
95 * stream is proper closed after usage.
97 * @return The InputStream representing the content of the artifact.
100 InputStream getReadStream() throws IOException;
103 * Returns a NIO representation of the data.
105 * @return A channel to the asset data.
106 * @throws IOException
108 ReadableByteChannel getReadChannel() throws IOException;
112 * Returns an output stream where you can write data to the asset. The operation is not locked or synchronized.
113 * User of this method have to make sure, that the stream is proper closed after usage.
115 * @param replace If true, the original data will be replaced, otherwise the data will be appended.
116 * @return The OutputStream where the data can be written.
117 * @throws IOException
119 OutputStream getWriteStream( boolean replace) throws IOException;
122 * Returns a NIO representation of the asset where you can write the data.
124 * @param replace True, if the content should be replaced by the data written to the stream.
125 * @return The Channel for writing the data.
126 * @throws IOException
128 WritableByteChannel getWriteChannel( boolean replace) throws IOException;
131 * Replaces the content. The implementation may do an atomic move operation, or keep a backup. If
132 * the operation fails, the implementation should try to restore the old data, if possible.
134 * The original file may be deleted, if the storage was successful.
136 * @param newData Replaces the data by the content of the given file.
138 boolean replaceDataFromFile( Path newData) throws IOException;
141 * Returns true, if the asset exists.
143 * @return True, if the asset exists, otherwise false.
148 * Creates the asset in the underlying storage, if it does not exist.
150 void create() throws IOException;
153 * Returns the real path to the asset, if it exist. Not all implementations may implement this method.
154 * The method throws {@link UnsupportedOperationException}, if and only if {@link #isFileBased()} returns false.
156 * @return The filesystem path to the asset.
157 * @throws UnsupportedOperationException If the underlying storage is not file based.
159 Path getFilePath() throws UnsupportedOperationException;
162 * Returns true, if the asset can return a file path for the given asset. If this is true, the {@link #getFilePath()}
163 * will not throw a {@link UnsupportedOperationException}
167 boolean isFileBased();
170 * Returns true, if there is a parent to this asset.
176 * Returns the parent of this asset.
177 * @return The asset, or <code>null</code>, if it does not exist.
179 StorageAsset getParent();