1 package org.apache.archiva.repository.storage.mock;
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 org.apache.archiva.repository.storage.RepositoryStorage;
23 import org.apache.archiva.repository.storage.StorageAsset;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.OutputStream;
28 import java.nio.channels.ReadableByteChannel;
29 import java.nio.channels.WritableByteChannel;
30 import java.nio.file.Path;
31 import java.time.Instant;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.LinkedHashMap;
35 import java.util.List;
38 public class MockAsset implements StorageAsset
40 private StorageAsset parent;
43 private LinkedHashMap<String, StorageAsset> children = new LinkedHashMap<>( );
44 private boolean container = false;
46 public MockAsset( String name ) {
51 public MockAsset( MockAsset parent, String name ) {
53 this.path = parent.getPath( ) + "/" + name;
55 parent.registerChild( this );
58 public void registerChild(StorageAsset child) {
59 children.putIfAbsent( child.getName(), child );
60 this.container = true;
64 public RepositoryStorage getStorage( )
70 public String getPath( )
76 public String getName( )
82 public Instant getModificationTime( )
88 public boolean isContainer( )
90 return this.container;
94 public boolean isLeaf( )
96 return !this.container;
100 public List<StorageAsset> list( )
102 return new ArrayList( children.values( ) );
106 public long getSize( )
112 public InputStream getReadStream( ) throws IOException
118 public ReadableByteChannel getReadChannel( ) throws IOException
124 public OutputStream getWriteStream( boolean replace ) throws IOException
130 public WritableByteChannel getWriteChannel( boolean replace ) throws IOException
136 public boolean replaceDataFromFile( Path newData ) throws IOException
142 public boolean exists( )
148 public void create( ) throws IOException
154 public Path getFilePath( ) throws UnsupportedOperationException
160 public boolean isFileBased( )
166 public boolean hasParent( )
168 return this.parent != null;
172 public StorageAsset getParent( )
178 public StorageAsset resolve( String toPath )
180 if (children.containsKey( toPath )) {
181 return children.get( toPath );
188 public String toString( )