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.generator;
16 
17 /**
18  * Trivial struct containing the critical data about the central directory: the number of entries
19  * it contains, the position within the file at which it starts, and its length.
20  */
21 class MinimalCentralDirectoryMetadata {
22   /**
23    * The number of entries in the central directory.
24    */
25   private final int numEntriesInCentralDirectory;
26 
27   /**
28    * The file offset of the first byte of the central directory.
29    */
30   private final long offsetOfCentralDirectory;
31 
32   /**
33    * The length of the central directory, in bytes.
34    */
35   private final long lengthOfCentralDirectory;
36 
37   /**
38    * Constructs a new metadata object with the specified values
39    * @param numEntriesInCentralDirectory the number of entries in the central directory
40    * @param offsetOfCentralDirectory the file offset of the first byte of the central directory
41    * @param lengthOfCentralDirectory the length of the central directory, in bytes
42    */
MinimalCentralDirectoryMetadata( int numEntriesInCentralDirectory, long offsetOfCentralDirectory, long lengthOfCentralDirectory)43   MinimalCentralDirectoryMetadata(
44       int numEntriesInCentralDirectory,
45       long offsetOfCentralDirectory,
46       long lengthOfCentralDirectory) {
47     this.numEntriesInCentralDirectory = numEntriesInCentralDirectory;
48     this.offsetOfCentralDirectory = offsetOfCentralDirectory;
49     this.lengthOfCentralDirectory = lengthOfCentralDirectory;
50   }
51 
52   /**
53    * Returns the number of entries in the central directory.
54    * @return as described
55    */
getNumEntriesInCentralDirectory()56   public final int getNumEntriesInCentralDirectory() {
57     return numEntriesInCentralDirectory;
58   }
59 
60   /**
61    * Returns the file offset of the first byte of the central directory.
62    * @return as described
63    */
getOffsetOfCentralDirectory()64   public final long getOffsetOfCentralDirectory() {
65     return offsetOfCentralDirectory;
66   }
67 
68   /**
69    * Returns the length of the central directory, in bytes.
70    * @return as described
71    */
getLengthOfCentralDirectory()72   public final long getLengthOfCentralDirectory() {
73     return lengthOfCentralDirectory;
74   }
75 }
76