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 /** 18 * Constants used in reading and writing patches. 19 */ 20 public class PatchConstants { 21 /** 22 * The identifier that begins all patches of this type. 23 */ 24 public static final String IDENTIFIER = "GFbFv1_0"; // Google File-by-File v1.0 25 26 /** 27 * All available compatibility windows. The {@link #patchValue} field specifies the value for 28 * each constant as represented in a patch file. 29 */ 30 public static enum CompatibilityWindowId { 31 /** 32 * The {@link com.google.archivepatcher.shared.DefaultDeflateCompatibilityWindow}. 33 */ 34 DEFAULT_DEFLATE((byte) 0); 35 36 /** 37 * The representation of this enumerated constant in patch files. 38 */ 39 public final byte patchValue; 40 41 /** 42 * Construct a new enumerated constant with the specified value in patch files. 43 */ CompatibilityWindowId(byte patchValue)44 private CompatibilityWindowId(byte patchValue) { 45 this.patchValue = patchValue; 46 } 47 48 /** 49 * Parse a patch value and return the corresponding enumerated constant. 50 * @param patchValue the patch value to parse 51 * @return the corresponding enumerated constant, null if unmatched 52 */ fromPatchValue(byte patchValue)53 public static CompatibilityWindowId fromPatchValue(byte patchValue) { 54 switch (patchValue) { 55 case 0: 56 return DEFAULT_DEFLATE; 57 default: 58 return null; 59 } 60 } 61 } 62 63 /** 64 * All available delta formats. The {@link #patchValue} field specifies the value for each 65 * constant as represented in a patch file. 66 */ 67 public static enum DeltaFormat { 68 /** 69 * The bsdiff delta format. 70 */ 71 BSDIFF((byte) 0); 72 73 /** 74 * The representation of this enumerated constant in patch files. 75 */ 76 public final byte patchValue; 77 78 /** 79 * Construct a new enumerated constant with the specified value in patch files. 80 */ DeltaFormat(byte patchValue)81 private DeltaFormat(byte patchValue) { 82 this.patchValue = patchValue; 83 } 84 85 /** 86 * Parse a patch value and return the corresponding enumerated constant. 87 * @param patchValue the patch value to parse 88 * @return the corresponding enumerated constant, null if unmatched 89 */ fromPatchValue(byte patchValue)90 public static DeltaFormat fromPatchValue(byte patchValue) { 91 switch (patchValue) { 92 case 0: 93 return BSDIFF; 94 default: 95 return null; 96 } 97 } 98 } 99 } 100