1   package eu.fbk.knowledgestore.filestore;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.io.OutputStream;
6   
7   import com.google.common.collect.ForwardingObject;
8   
9   import eu.fbk.knowledgestore.data.Stream;
10  
11  /**
12   * A {@code FileStore} that forwards all its method calls to another {@code FileStore}.
13   * <p>
14   * This class provides a starting point for implementing the decorator pattern on top of the
15   * {@code FileStore} interface. Subclasses must implement method {@link #delegate()} and override
16   * the methods of {@code FileStore} they want to decorate.
17   * </p>
18   */
19  public abstract class ForwardingFileStore extends ForwardingObject implements FileStore {
20  
21  	@Override
22  	protected abstract FileStore delegate();
23  
24  	@Override
25  	public void init() throws IOException {
26  		delegate().init();
27  	}
28  
29  	@Override
30  	public InputStream read(final String filename) throws FileMissingException, IOException {
31  		return delegate().read(filename);
32  	}
33  
34  	@Override
35  	public OutputStream write(final String filename) throws FileExistsException, IOException {
36  		return delegate().write(filename);
37  	}
38  
39  	@Override
40  	public void delete(final String filename) throws FileMissingException, IOException {
41  		delegate().delete(filename);
42  	}
43  
44  	@Override
45  	public Stream<String> list() throws IOException {
46  		return delegate().list();
47  	}
48  
49  	@Override
50  	public void close() {
51  		delegate().close();
52  	}
53  
54  }