• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload.file;
17 
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.util.List;
22 
23 /**
24  * Interface for adding behavior to how a file is opened that's independent from the Opener and
25  * Transforms. For example, this is used to support file locking and syncing. Instances are passed
26  * the whole chain of streams (which includes backends, transforms and monitors). The chain is
27  * ordered so that the first stream is the one that the client sees, and the last stream the
28  * backend. While the interface only sees Input/OutputStreams, most implementations will rely on
29  * <code>instanceof</code> to see if there are other features available on the stream.
30  */
31 public interface Behavior {
32 
33   /**
34    * Inform this Behavior about this input chain.
35    *
36    * @param chain The transforms, monitors, and backend (in that order).
37    */
forInputChain(List<InputStream> chain)38   default void forInputChain(List<InputStream> chain) throws IOException {}
39 
40   /**
41    * Inform this Behavior about this output chain.
42    *
43    * @param chain The transforms, monitors, and backend (in that order).
44    */
forOutputChain(List<OutputStream> chain)45   default void forOutputChain(List<OutputStream> chain) throws IOException {}
46 
47   /**
48    * Perform any aspects of the behavior that are required to be executed immediately prior to
49    * closing the stream.
50    */
commit()51   default void commit() throws IOException {}
52 }
53