Home | History | Annotate | Download | only in shared
      1 // Copyright 2016 Google Inc. All rights reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package com.google.archivepatcher.shared;
     16 
     17 import java.io.File;
     18 import java.io.IOException;
     19 
     20 /**
     21  * An implementation of {@link MultiViewInputStreamFactory} that produces instances of
     22  * {@link RandomAccessFileInputStream}.
     23  */
     24 public class RandomAccessFileInputStreamFactory
     25     implements MultiViewInputStreamFactory<RandomAccessFileInputStream> {
     26 
     27   /**
     28    * Argument for {@link RandomAccessFileInputStream#RandomAccessFileInputStream(File, long, long)}.
     29    */
     30   private final File file;
     31 
     32   /**
     33    * Argument for {@link RandomAccessFileInputStream#RandomAccessFileInputStream(File, long, long)}.
     34    */
     35   private final long rangeOffset;
     36 
     37   /**
     38    * Argument for {@link RandomAccessFileInputStream#RandomAccessFileInputStream(File, long, long)}.
     39    */
     40   private final long rangeLength;
     41 
     42   /**
     43    * Constructs a new factory that will create instances of {@link RandomAccessFileInputStream} with
     44    * the specified parameters.
     45    * @param file the file to use in {@link #newStream()}
     46    * @param rangeOffset the range offset to use in {@link #newStream()}
     47    * @param rangeLength the range length to use in {@link #newStream()}
     48    */
     49   public RandomAccessFileInputStreamFactory(File file, long rangeOffset, long rangeLength) {
     50     this.file = file;
     51     this.rangeOffset = rangeOffset;
     52     this.rangeLength = rangeLength;
     53   }
     54 
     55   @Override
     56   public RandomAccessFileInputStream newStream() throws IOException {
     57     return new RandomAccessFileInputStream(file, rangeOffset, rangeLength);
     58   }
     59 }
     60